public ActionResult Edit(IMProduct model) { //Static value used because CurrentPlantId is throwing exception model.PlantId = CurrentPlantId; if (ModelState.IsValid) { IMProductDto dto = Mapper.Map <IMProduct, IMProductDto>(model); //TODO: move to service using (var service = new IMProductService()) { if (model.Id > 0) { service.Update(dto); } else { service.Add(dto); } } SetResponseMesssage(ActionTypeMessage.SuccessfulSave); } else { ModelState.AddModelError(string.Empty, "Please enter required fields."); SetResponseMesssage(ActionTypeMessage.FailedSave); return(View(model)); } return(RedirectToAction("Edit")); }
public ActionResult Edit(int id = 0) { if (id == 0) { return(View(new IMProduct())); } using (var service = new IMProductService()) { IMProduct model = Mapper.Map <IMProductDto, IMProduct>(service.Get(id)); return(View(model)); } }
public int Add(IMProductDto dto) { dto.LastModified = DateTime.Now; IMProduct entity = Mapper.Map <IMProductDto, IMProduct>(dto); try { _repository.Repository <IMProduct>().Insert(entity); _repository.Save(); } catch (DbEntityValidationException valEx) { HandleValidationException(valEx); } catch (Exception ex) { LogException(ex); throw; } return(entity.ID); }