コード例 #1
0
        public HttpStatusCode UpdateList()
        {
            JObject          jsonObj = null;
            ShoppingList     newList = null;
            ShoppingListItem newItem = null;

            jsonObj      = JObject.Parse(Request.Content.ReadAsStringAsync().Result);
            newList      = new ShoppingList();
            newList.Id   = (int)jsonObj["ID"];
            newList.Name = jsonObj["Name"].ToString();

            foreach (var jsonItem in jsonObj["LAListItems"].Children())
            {
                newItem             = new ShoppingListItem();
                newItem.Id          = (int)jsonItem["ID"];
                newItem.ListId      = (int)jsonItem["ListID"];
                newItem.Description = jsonItem["Description"].ToString();
                newItem.Checked     = (bool)jsonItem["Done"];

                newList.ShoppingListItems.Add(newItem);
            }

            var result = listQueries.UpdateList(newList.Id, newList.Name);

            if (result)
            {
                foreach (var item in newList.ShoppingListItems)
                {
                    if (!listQueries.UpdateItemFromList(item))
                    {
                        return(HttpStatusCode.InternalServerError);
                    }
                }

                return(HttpStatusCode.OK);
            }

            return(HttpStatusCode.InternalServerError);
        }