public BugTrackingResponse <BusinessObjects.Priority> Save(BusinessObjects.Priority prio) { Logger.TraceMethodStart(ClassName, "Save"); var response = new BugTrackingResponse <BusinessObjects.Priority>(); using (var db = new EntityModel.BugTrackingEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { var validator = new PrioritySpecification(); var result = validator.Validate(prio); var failures = result.Errors; response.ValidationResult = result; if (result.IsValid) { prio.LastModified = DateTime.Now; prio.Active = true; var newprio = MapperAllLevels.Map <BusinessObjects.Priority, EntityModel.Priority>(prio); db.Priorities.Add(newprio); db.SaveChanges(); transaction.Commit(); } else { transaction.Rollback(); Logger.TraceErrorFormat("Error while Saving {0}", response.ValidationResult.Errors); } return(response); } catch (Exception ex) { Logger.TraceError("Exception: ", ex); transaction.Rollback(); throw; } finally { Logger.TraceMethodEnd(ClassName, "Save"); } } } }
public ActionResult EditPriority([Bind(Include = "Id,Name,Description,Active,LastModified,TimeIncrementInMinutes")] BusinessObjects.Priority prio) { var response = prioritymanager.SaveEdit(prio); if (!response.IsError) { return(RedirectToAction("/PrioritiesList")); } else { foreach (var failer in response.ValidationResult.Errors) { ModelState.AddModelError(failer.PropertyName, failer.ErrorMessage); } return(View()); } }