Пример #1
0
            public void TestBlankLAList()
            {
                ShoppingList testList3 = new ShoppingList() { Name = "Test List 3" };
                ShoppingListItem testInsertItem = new ShoppingListItem() { Description = "Test Insert", Checked = false };

                Assert.IsNotNull(testInsertItem, "Test insert item is null.");

                testList3.ShoppingListItems.Add(testInsertItem);
                Assert.AreEqual<int>(1, testList3.ShoppingListItems.Count, "List item not added.");
                testList3.ShoppingListItems.Remove(testInsertItem);
                Assert.AreEqual<int>(0, testList3.ShoppingListItems.Count, "List item not removed.");
            }
Пример #2
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;
        }