public BugTrackingResponse <Ticket> Save(Ticket ticket) { Logger.TraceMethodStart(ClassName, "SaveTicket"); var response = new BugTrackingResponse <BusinessObjects.Ticket>(); using (var db = new DAL.EntityModel.BugTrackingEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { var UserID = System.Web.HttpContext.Current.User.Identity.GetUserId(); ticket.UserID = UserID; var validator = new TicketSaveSpecificaion(); var result = validator.Validate(ticket); var failures = result.Errors; response.ValidationResult = result; if (result.IsValid) { ticket.Active = true; ticket.DateCreated = DateTime.Now; ticket.LastModified = DateTime.Now; var _ticket = MapperAllLevels.Map <BusinessObjects.Ticket, DAL.EntityModel.Ticket>(ticket); db.Tickets.Add(_ticket); 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, "SaveTicket"); } } } }
public BugTrackingResponse <BusinessObjects.Ticket> DeleteTicketConfirmed(long Id) { Logger.TraceMethodStart(ClassName, "DeleteTicket"); var response = new BugTrackingResponse <BusinessObjects.Ticket>(); using (var db = new DAL.EntityModel.BugTrackingEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { var query = db.Tickets.Where(c => c.ID == Id && c.Active == true).FirstOrDefault(); var ticket = MapperAllLevels.Map <DAL.EntityModel.Ticket, BusinessObjects.Ticket>(query); var validator = new TicketDeleteSpecification(); var result = validator.Validate(ticket); var failures = result.Errors; response.ValidationResult = result; if (result.IsValid) { query.Active = false; query.LastModified = DateTime.Now; 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, "DeleteTicketConfirmed"); } } } }