public ResponseVM Create(EmployeeTypeVM employeetypeVM) { using (context) { //check if record already exists if (context.EmployeeTypes.Where(b => b.EmployeeTypeName.ToLower() == employeetypeVM.EmployeeTypeName.ToLower()).Any()) { return(new ResponseVM("created", false, "Employee Type", ResponseVM.ALREADY_EXIST)); } using (var dbTransaction = context.Database.BeginTransaction()) { try { employeetypeVM.EmployeeTypeid = Guid.NewGuid(); //converts to book type then save to context context.EmployeeTypes.Add(toModel.EmployeeType(employeetypeVM)); context.SaveChanges(); //commits changes to db dbTransaction.Commit(); return(new ResponseVM("created", true, "Employee Type")); } catch (Exception ex) { dbTransaction.Rollback(); return(new ResponseVM("created", false, "Employee Type", ResponseVM.SOMETHING_WENT_WRONG, "", ex)); } } } }
public ResponseVM Create(CategoryListVM categoryListVM) { using (context) { if (context.CategoryLists.Where(x => x.CategoryListName == categoryListVM.CategoryListName).Any()) { return(new ResponseVM("created", false, "CategoryList", ResponseVM.ALREADY_EXIST)); } using (var dbTransaction = context.Database.BeginTransaction()) { try { categoryListVM.CategoryListid = Guid.NewGuid(); context.CategoryLists.Add(toModel.CategoryList(categoryListVM)); context.SaveChanges(); dbTransaction.Commit(); return(new ResponseVM("created", true, "CategoryList")); } catch (Exception ex) { dbTransaction.Rollback(); return(new ResponseVM("created", false, "CategoryList", ResponseVM.SOMETHING_WENT_WRONG, "", ex)); } } } }
public ResponseVM Create(SeverityVM severityVM) { using (context) { if (context.Severities.Where(x => x.SeverityCode == severityVM.SeverityCode || x.SeverityName == severityVM.SeverityName || x.SeverityDesc == severityVM.SeverityDesc).Any()) { return(new ResponseVM("created", false, "Severity", ResponseVM.ALREADY_EXIST)); } using (var dbTransaction = context.Database.BeginTransaction()) { try { severityVM.Severityid = Guid.NewGuid(); context.Severities.Add(toModel.Severity(severityVM)); context.SaveChanges(); dbTransaction.Commit(); return(new ResponseVM("created", true, "Severity")); } catch (Exception ex) { dbTransaction.Rollback(); return(new ResponseVM("created", false, "Severity", ResponseVM.SOMETHING_WENT_WRONG, "", ex)); } } } }
public ResponseVM Create(ITGroupVM itgroupVM) { using (context) { if (context.ITGroups.Where(x => x.ITGroupName == itgroupVM.ITGroupName).Any()) { return(new ResponseVM("created", false, "ITGroup", ResponseVM.ALREADY_EXIST)); } using (var dbTransaction = context.Database.BeginTransaction()) { try { context.ITGroups.Add(toModel.ITGroup(itgroupVM)); context.SaveChanges(); dbTransaction.Commit(); return(new ResponseVM("created", true, "ITGroup")); } catch (Exception ex) { dbTransaction.Rollback(); return(new ResponseVM("created", false, "ITGroup", ResponseVM.SOMETHING_WENT_WRONG, "", ex)); } } } }
public ResponseVM Create(TicketVM ticketVM) { using (context) { using (var dbTransaction = context.Database.BeginTransaction()) { try { ticketVM.Ticketid = Guid.NewGuid(); ticketVM.TrackingStatus = "Request for approval"; ticketVM.IsOpen = "True"; ticketVM.RequestedBy = "ridz"; //converts to book type then save to context context.Tickets.Add(toModel.Ticket(ticketVM)); context.SaveChanges(); //commits changes to db dbTransaction.Commit(); return new ResponseVM("created", true, "Ticket"); } catch (Exception ex) { dbTransaction.Rollback(); return new ResponseVM("created", false, "Ticket", ResponseVM.SOMETHING_WENT_WRONG, "", ex); } } } }
public ResponseVM Create(TicketMinorVM ticketMinorVM) { using (context) { using (var dbTransaction = context.Database.BeginTransaction()) { try { ticketMinorVM.TicketMinorid = Guid.NewGuid(); ticketMinorVM.DateAccomplished = DateTime.Now; context.TicketMinors.Add(toModel.TicketMinor(ticketMinorVM)); context.SaveChanges(); dbTransaction.Commit(); return(new ResponseVM("created", true, "TicketMinor")); } catch (Exception ex) { dbTransaction.Rollback(); return(new ResponseVM("created", false, "TicketMinor", ResponseVM.SOMETHING_WENT_WRONG, "", ex)); } } } }
public ResponseVM Create(EmployeeEmployeeTypeVM employeeEmployeeTypeVM) { using (context) { using (var dbTransaction = context.Database.BeginTransaction()) { try { employeeEmployeeTypeVM.EmployeeEmployeeTypeid = Guid.NewGuid().ToString(); var employeeEmployeeTypeSaved = context.EmployeeEmployeeTypes.Add(toModel.EmployeeEmployeeType(employeeEmployeeTypeVM)).Entity; context.SaveChanges(); foreach (var empID in employeeEmployeeTypeVM.EmployeeIdList) { var employee = context.Employees.Find(empID); if (employee == null) { return(new ResponseVM("create", false, "EmployeeEmployeeType", "Employee does not exists")); } var typeEmployee = new TypeEmployee { EmployeeID = empID, EmployeeEmployeeTypeid = employeeEmployeeTypeSaved.EmployeeEmployeeTypeid, EmployeeFullName = toViewModel.ToFullName(employee.FirstName, employee.LastName) }; context.TypeEmployees.Add(typeEmployee); context.SaveChanges(); } dbTransaction.Commit(); return(new ResponseVM ("create", true, "EmployeeEmployeeType")); } catch (Exception ex) { dbTransaction.Rollback(); return(new ResponseVM("create", false, "EmployeeEmployeeType", ResponseVM.SOMETHING_WENT_WRONG, "", ex)); } } } }