public JsonResult Edit(Merchandize merch)
 {
     if (ModelState.IsValid)
     {
         if (merch != null)
         {
             using (EntityContext ctx = new EntityContext())
             {
                 Merchandize merchDb = ctx.Merchandize.FirstOrDefault(c => c.Id == merch.Id);
                 if (merchDb != null)
                 {
                     merchDb.Price = merch.Price;
                     merchDb.Name  = merch.Name;
                 }
                 else
                 {
                     ctx.Merchandize.Add(merch);
                 }
                 ctx.SaveChanges();
                 return(Json(merch));
             }
         }
     }
     return(Json(new { error = "true" }));
 }
 public ActionResult Remove(Merchandize merch)
 {
     if (merch != null)
     {
         using (EntityContext ctx = new EntityContext())
         {
             ctx.Merchandize.Remove(merch);
             ctx.SaveChanges();
         }
     }
     return(Json(merch, JsonRequestBehavior.AllowGet));
 }
 public ActionResult Details(long?id, long?userId)
 {
     using (EntityContext ctx = new EntityContext())
     {
         Merchandize c = ctx.Merchandize.FirstOrDefault(com => com.Id == id) ?? new Merchandize();
         if (c.ClientId <= 0 && userId.HasValue)
         {
             c.ClientId = userId.Value;
         }
         return(PartialView(c));
     }
 }
 public ActionResult Add(Merchandize merch)
 {
     if (merch != null)
     {
         using (EntityContext ctx = new EntityContext())
         {
             ctx.Merchandize.Add(merch);
             ctx.SaveChanges();
             return(Json(merch));
         }
     }
     return(Json(new { error = "true" }));
 }