public ActionResult EditResponsible([Bind(Include = "ID, ID_Product,ID_User,Active,LastModified")] BusinessObjects.Responsible responsible) { var response = productmanager.SaveEditResponsible(responsible); if (!response.IsError) { return(RedirectToAction("/ProductResponsibleList")); } else { ViewBag.ID_User = new SelectList(usermanager.DropDownUser(), "ID", "Email", responsible.ID_User); ViewBag.ID_Product = new SelectList(productmanager.DropDownProduct(), "Id", "Name_Prod", responsible.ID_Product); foreach (var failer in response.ValidationResult.Errors) { ModelState.AddModelError(failer.PropertyName, failer.ErrorMessage); } return(View()); } }
public BugTrackingResponse <BusinessObjects.Responsible> SaveProductResponsible(BusinessObjects.Responsible productresponsible) { Logger.TraceMethodStart(ClassName, "SaveProductResponsible"); var response = new BugTrackingResponse <BusinessObjects.Responsible>(); using (var db = new EntityModel.BugTrackingEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { var validator = new ResponsibleSpecification(); var result = validator.Validate(productresponsible); var failures = result.Errors; response.ValidationResult = result; if (result.IsValid) { productresponsible.Active = true; productresponsible.LastModified = DateTime.Now; var responsible = MapperAllLevels.Map <BusinessObjects.Responsible, EntityModel.Responsible>(productresponsible); db.Responsibles.Add(responsible); 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, "SaveProductResponsible"); } } } }