public MyResponse Add([FromBody] MessageViewModel model)
        {
            MyResponse oR = new MyResponse();

            try
            {
                Models.Message oMessage = new Models.Message();
                oMessage.Name = model.Name;
                oMessage.Text = model.Text;
                db.Message.Add(oMessage);
                db.SaveChanges();
                oR.Success = 1;
            }
            catch (Exception ex)
            {
                oR.Success = 0;
                oR.Message = ex.Message.ToString();
            }
            return(oR);
        }
示例#2
0
 public void UpdateItem(string updateCartID, int updateProductID, int quantity)
 {
     using (var db = new Models.MyDbContext())
     {
         try
         {
             var myItem = (from c in db.ShoppingCartItems
                           where c.CartId == updateCartID && c.Product.ProductID == updateProductID
                           select c).FirstOrDefault();
             if (myItem != null)
             {
                 myItem.Quantity = quantity;
                 db.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             throw new Exception("ERROR: Unable to Update Cart Item - " + ex.Message.ToString(), ex);
         }
     }
 }
示例#3
0
 public void RemoveItem(string removeCartID, int removeProductID)
 {
     using (var db = new Models.MyDbContext())
     {
         try
         {
             var myItem = (from c in db.ShoppingCartItems
                           where c.CartId == removeCartID && c.Product.ProductID == removeProductID
                           select c).FirstOrDefault();
             if (myItem != null)
             {
                 db.ShoppingCartItems.Remove(myItem);
                 db.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             throw new Exception("ERROR: Unable to Remove Cart Item - " + ex.Message.ToString(), ex);
         }
     }
 }
 public IActionResult CreateDepartamentos(Departamentos depto)
 {
     db.Departamentos.Add(depto);
     db.SaveChanges();
     return(RedirectToAction("Index", "Departamentos"));
 }