public int Add(DownTimeReasonDto dto) { DownTimeReason entity = Mapper.Map <DownTimeReasonDto, DownTimeReason>(dto); try { _repository.Repository <DownTimeReason>().Insert(entity); _repository.Save(); } catch (DbEntityValidationException valEx) { var sb = new StringBuilder(); foreach (var failure in valEx.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new DbEntityValidationException( "Entity Validation Failed - errors follow:\n" + sb.ToString(), valEx ); // Add the original exception as the innerException } catch (Exception ex) { LogException(ex); throw; } return(entity.ID); }
public JsonResult UpdateReasonResult(DownTimeReason model) { ResponseMessage responseMessage; try { var dto = Mapper.Map <DownTimeReason, DownTimeReasonDto>(model); dto.ModifiedBy = CurrentUser; dto.LastModified = DateTime.Now; using (DownTimeReasonService svc = new DownTimeReasonService()) { if (dto.ID > 0) { svc.Update(dto); } else { dto.EnteredBy = CurrentUser; dto.DateEntered = DateTime.Now; dto.PlantID = CurrentPlantId; dto.ID = svc.Add(dto); } } model = Mapper.Map <DownTimeReasonDto, DownTimeReason>(dto); responseMessage = SetResponseMesssage(ActionTypeMessage.SuccessfulSave); } catch (Exception exc) { responseMessage = SetResponseMesssage(ActionTypeMessage.FailedSave, exc.Message); } model.ResponseMessage = responseMessage; return(Json(model, JsonRequestBehavior.AllowGet)); }