public BugTrackingResponse <BusinessObjects.Category> SaveEdit(BusinessObjects.Category category) { Logger.TraceMethodStart(ClassName, "SaveEdit"); var response = new BugTrackingResponse <BusinessObjects.Category>(); using (var db = new EntityModel.BugTrackingEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { var validator = new CategoryUpdateSpecification(); var result = validator.Validate(category); var failures = result.Errors; response.ValidationResult = result; if (result.IsValid) { category.LastModified = DateTime.Now; var newcat = MapperAllLevels.Map <BusinessObjects.Category, EntityModel.Category>(category); db.Entry(newcat).State = EntityState.Modified; 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, "SaveEdit"); } } } }
public ActionResult CreateCategory([Bind(Include = "Id,Name,Description,Active, LastModified, Section")] BusinessObjects.Category category) { var response = categorymanager.Save(category); if (!response.IsError) { return(RedirectToAction("/CategoryList")); } else { foreach (var failer in response.ValidationResult.Errors) { ModelState.AddModelError(failer.PropertyName, failer.ErrorMessage); } return(View()); } }
public BugTrackingResponse <BusinessObjects.Category> Save(BusinessObjects.Category category) { Logger.TraceMethodStart(ClassName, "Save"); var response = new BugTrackingResponse <BusinessObjects.Category>(); try { var validator = new CategorySpecification(); var result = validator.Validate(category); var failures = result.Errors; response.ValidationResult = result; if (result.IsValid) { category.LastModified = DateTime.Now; category.Active = true; var newcategory = MapperAllLevels.Map <BusinessObjects.Category, EntityModel.Category>(category); UoW.Categories.Add(newcategory); UoW.Complete(); } else { Logger.TraceErrorFormat("Error while Saving {0}", response.ValidationResult.Errors); } return(response); } catch (Exception ex) { Logger.TraceError("Exception: ", ex); throw; } finally { Logger.TraceMethodEnd(ClassName, "Save"); } }