예제 #1
0
 public ActionResult Edit(Product item)
 {
     try
     {
         if (ModelState.IsValid)
         {
             ProductMethods.ChangeItem(item);
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException)
     {
         //Log the error (add a variable name after DataException)
         ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
     }
     return(View(item));
 }
예제 #2
0
        string ProductCommand(string message, string[] json)
        {
            Product data = null;;

            if (json != null)
            {
                data = JsonConvert.DeserializeObject <Product>(json[0]);
            }
            string outMessage = null;

            switch (message)
            {
            case "AddItem":
                ProductMethods.AddItem(data);
                outMessage = "Добавленно";
                break;

            case "AddItems":
                List <Product> list = new List <Product>();
                int            i    = 0;
                foreach (var x in json)
                {
                    Product u = JsonConvert.DeserializeObject <Product>(json[i]);
                    list.Add(u);
                }
                ProductMethods.AddItems(list);
                outMessage = "Добавленно";
                break;

            case "ChangeItem":
                if (ProductMethods.ChangeItem(data) == true)
                {
                    outMessage = "Найден";
                }
                else
                {
                    outMessage = "Не найден";
                }
                break;

            case "DeleteItem":
                ProductMethods.DeleteItem(Convert.ToInt32(json[0]));
                outMessage = "Удален";
                break;

            case "GetItem":
                string s = JsonConvert.SerializeObject(ProductMethods.GetItem(Convert.ToInt32(json[0])));
                outMessage = s;
                break;

            case "Outpoot":
                string         outs        = null;
                List <Product> unitWeights = ProductMethods.Outpoot().ToList();
                foreach (var x in unitWeights)
                {
                    outs = $"{outs}!{JsonConvert.SerializeObject(x)}";
                }
                outMessage = outs;
                break;

            default:
                outMessage = "Product connect";
                break;
            }
            return(outMessage);
        }
예제 #3
0
 public void ChangeItem()
 {
     Assert.IsTrue(ProductMethods.ChangeItem(productTemp));
 }