コード例 #1
0
        public ActionResult UpdateItem(int id, ItemUpdateDto itemUpdateDto)
        {
            var itemModelFromRepo = _repository.GetItemById(id);

            if (itemModelFromRepo == null)
            {
                return(NotFound());
            }
            _mapper.Map(itemUpdateDto, itemModelFromRepo);
            // don't ned to do that but it;s a good practice
            _repository.UpdateItem(itemModelFromRepo);
            _repository.SaveChanges();
            return(NoContent());
        }
コード例 #2
0
 public ActionResult AddOrEdit(Item item)
 {
     //try
     //{
     if (item.ItemId == 0)
     {
         _itemsRepo.SaveItem(item);
         return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         //return View(item);
     }
     else
     {
         _itemsRepo.UpdateItem(item);
         return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
     }
     //}
     //catch (Exception e)
     //{
     //    return Json(new { success = false, message = "Error in " + (item.ItemId == 0 ? "saving" : "updation") + "\n" + e.Message }, JsonRequestBehavior.AllowGet);
     //}
 }