コード例 #1
0
    protected void btnApplyAllChanges_Click(object sender, EventArgs e)
    {
        //Create product list from json posted from client
        List <colour> colours         = new List <colour>();
        var           coloursJson     = Colour_Data_To_Post_To_Server.Text;
        dynamic       coloursResponse = JsonConvert.DeserializeObject(coloursJson);

        if (coloursResponse.Count > 0)
        {
            List <object> colourObjects = coloursResponse.ToObject <List <object> >();
            foreach (var obj in colourObjects)
            {
                colour item = new colour();

                int colour_id = -1;
                Int32.TryParse(Helper.GetPropValue(obj + "", "colour_id") + "", out colour_id);
                item.colour_id = colour_id;

                item.colour_name        = Helper.GetPropValue(obj + "", "colour_name") + "";
                item.colour_description = Helper.GetPropValue(obj + "", "colour_description") + "";

                item.create_date = Helper.ConverToDateTime(Helper.GetPropValue(obj + "", "create_date") + "");


                colours.Add(item);
            }
        }

        //Delete records from product
        //Get product ids from json posted from client
        var     deletedIdsJson     = txtDeletedIds.Text;
        dynamic deletedIdsResponse = JsonConvert.DeserializeObject(deletedIdsJson);

        if (deletedIdsResponse.Count > 0)
        {
            List <int> deletedIds = deletedIdsResponse.ToObject <List <int> >();

            if (deletedIds.Count > 0)
            {
                foreach (var id in deletedIds)
                {
                    var found = colours.Find(x => x.colour_id == id);
                    if (found != null)
                    {
                        colours.Remove(found);
                    }
                }
                ColourHelper.DeleteColourByIds(deletedIds);
            }
        }

        ColourHelper.Updatecolours(colours);
        PushDataToClient();
    }