B
B
bigProblem2015-10-29 13:00:57
JSON
bigProblem, 2015-10-29 13:00:57

Problems with Deserialization to a ready object. How to convert bool type to '1' or '0'?

The form has a CheckBox .

<ext:Checkbox ID="DELIVERY" runat="server" 
 Width="210" 
 FieldLabel="Рассылка" 
 LabelWidth="100" 
 MarginSpec="0 0 0 15">
</ext:Checkbox>

I send form parameters and then I deserialize into a ready-made object that was provided to me by Entity (DataBase First)
public partial class PERSON
    {
        public decimal ID { get; set; }
        public string NAME { get; set; }
        public string SURNAME { get; set; }
        public string PASSPORT { get; set; }
        public decimal SEX { get; set; }
        public System.DateTime BORN { get; set; }
        public decimal DELIVERY { get; set; }
        public decimal CITY_ID { get; set; }
    
        public virtual CITY CITY { get; set; }
    }

Submit on the form.
<ext:Button ID="IDBUTTON" runat="server" 
Text="Добавить" 
Icon="Add" 
Flat="true" 
ToolTip="Добавить нового пользователя"
Cls="btnBackground"
Disabled="True">
<DirectEvents>
  <Click OnEvent="AddNewUser"
    After="Ext.Msg.alert('Сообщение','Пользователь добавлен');">
    <ExtraParams>
      <ext:Parameter 
        Name="values"
        Value="#{FormPanel1}.getValues(false, false, true, true)"
        Mode="Raw"
        Encode="True"/>
    </ExtraParams>
  </Click>                           
</DirectEvents>  
</ext:Button>

We get the form parameters on the server.
[0] = {[NAME, Андрей]}
[1] = {[SURNAME, Андреанов]}
[2] = {[PASSPORT, 1221 212112]}
[3] = {[SEX, 1]}
[4] = {[COUNTRY, 1]}
[5] = {[CITY_ID, 2]}
[6] = {[BORN, 2015-10-29T00:00:00]}
[7] = {[DELIVERY, True]}

So. The code that adds me a new user.
protected void AddNewUser(object Sender, DirectEventArgs e)
        {
            var objectParam = JsonConvert.DeserializeObject<PERSON>(e.ExtraParams["values"]);
            var DB = new Entities();
            DB.PERSON.Add(objectParam);
            DB.SaveChanges();            
        }

But the problem is that TRUE or FALSE comes from the combobox, and I need '0' or '1'. So how do I change the value in the key? And how to make it so that there would be no hard binding to the element ID.
Just started learning JSON.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oxoron, 2015-10-29
@Oxoron

Make a BoolIntHybrid class, it has implicit casts to Int32 and string.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question