public void InsertTest() { int expected = 1; int actual = 0; Guid customerId = dc.tblCustomers.First().Id; string serviceName = dc.tblServiceTypes.First().Description; decimal serviceRate = dc.tblServiceTypes.First().CostPerSqFt; string employeeName = dc.tblEmployees.First().FirstName + " " + dc.tblEmployees.First().LastName; tblInvoice newInvoice = new tblInvoice { Id = Guid.NewGuid(), CustomerId = customerId, EmployeeName = employeeName, ServiceName = serviceName, ServiceRate = serviceRate, ServiceDate = DateTime.Now, Status = "Completed" }; dc.tblInvoices.Add(newInvoice); actual = dc.SaveChanges(); invoiceId = newInvoice.Id; Assert.AreEqual(expected, actual); }
public void InsertTest() { int expected = 1; int actual = 0; Guid userId = dc.tblUsers.First().Id; tblEmployee newEmployee = new tblEmployee { Id = Guid.NewGuid(), City = "Appleton", StreetAddress = "123 Easy Street", Email = "*****@*****.**", FirstName = "Bill", LastName = "Jenkins", Phone = "123-456-7890", State = "WI", UserId = userId, ZipCode = "54901", }; dc.tblEmployees.Add(newEmployee); actual = dc.SaveChanges(); employeeId = newEmployee.Id; Assert.AreEqual(expected, actual); }
public void InsertTest() { int expected = 1; int actual = 0; Guid customerId = dc.tblCustomers.First().Id; Guid employeeId = dc.tblEmployees.First().Id; Guid serviceId = dc.tblServiceTypes.First().Id; tblAppointment newAppointment = new tblAppointment { Id = Guid.NewGuid(), CustomerId = customerId, EmployeeId = employeeId, ServiceId = serviceId, StartDateTime = DateTime.Now, EndDateTime = DateTime.Now.AddHours(4), Status = "Pending" }; dc.tblAppointments.Add(newAppointment); actual = dc.SaveChanges(); appointmentId = newAppointment.Id; Assert.AreEqual(expected, actual); }
public void InsertTest() { int expected = 1; int actual = 0; Guid userId = dc.tblUsers.First().Id; tblCustomer newCustomer = new tblCustomer { Id = Guid.NewGuid(), City = "Appleton", StreetAddress = "123 Easy Street", Email = "*****@*****.**", FirstName = "Bill", LastName = "Jenkins", Phone = "123-456-7890", State = "WI", UserId = userId, ZipCode = "54901", PropertySqFt = 50000 }; dc.tblCustomers.Add(newCustomer); actual = dc.SaveChanges(); customerId = newCustomer.Id; Assert.AreEqual(expected, actual); }
public async static Task <bool> Insert(User user, bool rollback = false) { try { int result = 0; if (user.Id.Equals(user.Id.ToString())) { user.Id = (Guid)user.Id; } await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { // Check if username already exists - do not allow .... bool inuse = dc.tblUsers.Any(u => u.UserName.Trim().ToUpper() == user.UserName.Trim().ToUpper()); if (inuse) { throw new Exception("This User Name already exists."); } else { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblUser newUser = new tblUser(); newUser.Id = Guid.NewGuid(); newUser.FirstName = user.FirstName.Trim(); newUser.LastName = user.LastName.Trim(); newUser.UserName = user.UserName.Trim(); newUser.UserPass = GetHash(user.UserPass.Trim()); user.Id = newUser.Id; dc.tblUsers.Add(newUser); result = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } } }); return(result == 1); } catch (Exception) { throw; } }
public async static Task <int> Delete(Guid id, bool rollback = false) { try { int results = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { // Check if user is associated with an exisiting customers or employees = do not allow delete .... bool inuse = dc.tblEmployees.Any(e => e.UserId == id); if (!inuse) { inuse = dc.tblCustomers.Any(c => c.UserId == id); } if (inuse) { throw new Exception("This user is associated with an existing Customers or Employee and therefore cannot be deleted."); } else { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblUser deleteRow = dc.tblUsers.FirstOrDefault(r => r.Id == id); if (deleteRow != null) { dc.tblUsers.Remove(deleteRow); // Commit the changes and get the number of rows affected results = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } else { throw new Exception("User was not found."); } } } }); return(results); } catch (Exception) { throw; } }
public async static Task <int> Delete(Guid id, bool rollback = false) { try { int results = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { // Check if user is associated with an exisiting appointment or invoice = do not allow delete .... bool inuse = dc.tblAppointments.Any(e => e.CustomerId == id); if (!inuse) { inuse = dc.tblInvoices.Any(c => c.CustomerId == id); } if (inuse && rollback == false) { throw new Exception("This customer is associated with an existing appointment or invoice and therefore cannot be deleted."); } else { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblCustomer deleteRow = dc.tblCustomers.FirstOrDefault(r => r.Id == id); if (deleteRow != null) { dc.tblCustomers.Remove(deleteRow); results = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } else { throw new Exception("Customer was not found."); } } } }); return(results); } catch (Exception) { throw; } }
public async static Task <int> Update(Appointment appointment, bool rollback = false) { try { int results = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblAppointment updateRow = dc.tblAppointments.FirstOrDefault(r => r.Id == appointment.Id); if (updateRow != null) { updateRow.CustomerId = appointment.CustomerId; updateRow.EmployeeId = appointment.EmployeeId; updateRow.StartDateTime = appointment.StartDateTime; updateRow.EndDateTime = appointment.EndDateTime; updateRow.ServiceId = appointment.ServiceId; updateRow.Status = appointment.Status; dc.tblAppointments.Update(updateRow); // Commit the changes and get the number of rows affected results = dc.SaveChanges(); if (appointment.Status == AppointmentStatus.Completed.ToString()) { GenerateInvoice(appointment); } if (rollback) { transaction.Rollback(); } } else { throw new Exception("Appointment was not found."); } } }); return(results); } catch (Exception) { throw; } }
public void InsertTest() { int expected = 1; int actual = 0; tblServiceType newServiceType = new tblServiceType { Id = Guid.NewGuid(), Description = "Rake Leaves", CostPerSqFt = 0.0045M }; dc.tblServiceTypes.Add(newServiceType); actual = dc.SaveChanges(); servicetypeId = newServiceType.Id; Assert.AreEqual(expected, actual); }
public async static Task <int> Update(Customer customer, bool rollback = false) { try { int results = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblCustomer upDateRow = dc.tblCustomers.FirstOrDefault(r => r.Id == customer.Id); if (upDateRow != null) { upDateRow.FirstName = customer.FirstName; upDateRow.LastName = customer.LastName; upDateRow.StreetAddress = customer.StreetAddress; upDateRow.City = customer.City; upDateRow.State = customer.State; upDateRow.ZipCode = customer.ZipCode; upDateRow.Email = customer.Email; upDateRow.Phone = customer.Phone; upDateRow.PropertySqFt = customer.PropertySqFeet; upDateRow.UserId = customer.UserId; dc.tblCustomers.Update(upDateRow); // Commit the changes and get the number of rows affected results = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } else { throw new Exception("Customer was not found."); } } }); return(results); } catch (Exception) { throw; } }
public async static Task <bool> Insert(Customer customer, bool rollback = false) { try { int result = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblCustomer newRow = new tblCustomer(); // Teranary operator newRow.Id = Guid.NewGuid(); newRow.FirstName = customer.FirstName; newRow.LastName = customer.LastName; newRow.StreetAddress = customer.StreetAddress; newRow.City = customer.City; newRow.State = customer.State; newRow.ZipCode = customer.ZipCode; newRow.Email = customer.Email; newRow.Phone = customer.Phone; newRow.PropertySqFt = customer.PropertySqFeet; newRow.UserId = customer.UserId; // Backfill the id on the input parameter customer customer.Id = newRow.Id; // Insert the row dc.tblCustomers.Add(newRow); // Commit the changes and get the number of rows affected result = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } }); return(result == 1); } catch (Exception) { throw; } }
public void InsertTest() { int expected = 1; int actual = 0; tblUser newUser = new tblUser { Id = Guid.NewGuid(), UserName = "******", UserPass = "******", FirstName = "TestFirstName", LastName = "TestLastName" }; dc.tblUsers.Add(newUser); actual = dc.SaveChanges(); userId = newUser.Id; Assert.AreEqual(expected, actual); }
public async static Task <int> Delete(Guid id, bool rollback = false) { try { int results = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { // Check if appointment is in progress or completed .... bool inuse = dc.tblAppointments.Any(a => a.Id == id && a.Status == "InProgress" || a.Status == "Complete"); if (inuse && rollback == false) { throw new Exception("This appointment is currently in progress or completed and therefore cannot be deleted."); } else { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblAppointment deleteRow = dc.tblAppointments.FirstOrDefault(r => r.Id == id); if (deleteRow != null) { dc.tblAppointments.Remove(deleteRow); results = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } else { throw new Exception("Appointment was not found."); } } } }); return(results); } catch (Exception) { throw; } }
public async static Task <bool> Insert(Appointment appointment, bool rollback = false) { try { int result = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblAppointment newRow = new tblAppointment(); newRow.Id = Guid.NewGuid(); newRow.CustomerId = appointment.CustomerId; newRow.EmployeeId = appointment.EmployeeId; newRow.StartDateTime = appointment.StartDateTime; newRow.EndDateTime = appointment.EndDateTime; newRow.ServiceId = appointment.ServiceId; newRow.Status = appointment.Status; // Backfill the id on the input parameter appointment appointment.Id = newRow.Id; // Insert the row dc.tblAppointments.Add(newRow); // Commit the changes and get the number of rows affected result = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } }); return(result == 1); } catch (Exception) { throw; } }
public async static Task <int> Update(Invoice invoice, bool rollback = false) { try { int results = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblInvoice updateRow = dc.tblInvoices.FirstOrDefault(s => s.Id == invoice.Id); if (updateRow != null) { updateRow.EmployeeName = invoice.EmployeeFullName; updateRow.ServiceDate = invoice.ServiceDate; updateRow.ServiceName = invoice.ServiceType; updateRow.ServiceRate = invoice.ServiceRate; updateRow.Status = invoice.Status; dc.tblInvoices.Update(updateRow); results = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } else { throw new Exception("Invoice not found"); } } }); return(results); } catch (Exception) { throw; } }
public async static Task <int> Delete(Guid id, bool rollback = false) { try { int results = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { bool inuse = dc.tblInvoices.Any(e => e.Id == id && e.Status != "Paid"); if (inuse && rollback == false) { throw new Exception("This Invoice has not been paid and cannot be deleted"); } else { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblInvoice deleteRow = dc.tblInvoices.FirstOrDefault(s => s.Id == id); if (deleteRow != null) { dc.tblInvoices.Remove(deleteRow); results = dc.SaveChanges(); } else { throw new Exception("Invoice not found"); } } } }); return(results); } catch (Exception) { throw; } }
public async static Task <int> Delete(Guid id, bool rollback = false) { try { int results = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { bool inuse = dc.tblAppointments.Any(e => e.ServiceId == id); if (inuse && rollback == false) { throw new Exception("This service type is associated with an existing appointment and cannot be deleted"); } else { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblServiceType deleteRow = dc.tblServiceTypes.FirstOrDefault(s => s.Id == id); if (deleteRow != null) { dc.tblServiceTypes.Remove(deleteRow); results = dc.SaveChanges(); } else { throw new Exception("Service type not found"); } } } }); return(results); } catch (Exception) { throw; } }
public async static Task <int> Update(ServiceType serviceType, bool rollback = false) { try { int results = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblServiceType updateRow = dc.tblServiceTypes.FirstOrDefault(s => s.Id == serviceType.Id); if (updateRow != null) { updateRow.Description = serviceType.Description; updateRow.CostPerSqFt = serviceType.CostPerSQFT; dc.tblServiceTypes.Update(updateRow); results = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } else { throw new Exception("Service type not found"); } } }); return(results); } catch (Exception) { throw; } }
public async static Task <bool> Insert(Invoice invoice, bool rollback = false) { try { int result = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblInvoice newrow = new tblInvoice(); newrow.Id = Guid.NewGuid(); newrow.CustomerId = invoice.CustomerId; newrow.EmployeeName = invoice.EmployeeFullName; newrow.ServiceDate = invoice.ServiceDate; newrow.ServiceName = invoice.ServiceType; newrow.ServiceRate = invoice.ServiceRate; newrow.Status = invoice.Status; invoice.Id = newrow.Id; dc.tblInvoices.Add(newrow); result = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } }); return(result == 1); } catch (Exception) { throw; } }
public async static Task <bool> Insert(ServiceType serviceType, bool rollback = false) { try { int result = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblServiceType newrow = new tblServiceType(); newrow.Id = Guid.NewGuid(); newrow.Description = serviceType.Description; newrow.CostPerSqFt = serviceType.CostPerSQFT; serviceType.Id = newrow.Id; dc.tblServiceTypes.Add(newrow); result = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } }); return(result == 1); } catch (Exception) { throw; } }
public static async Task <bool> Seed() { List <User> users = new List <User>(); await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { dc.tblUsers .ToList() .ForEach(u => users .Add(new User { Id = u.Id, FirstName = u.FirstName, LastName = u.LastName, UserName = u.UserName, UserPass = u.UserPass })); foreach (User user in users) { if (user.UserPass.Length != 28) { tblUser upDateRow = dc.tblUsers.FirstOrDefault(r => r.Id == user.Id); if (upDateRow != null) { upDateRow.UserPass = GetHash(user.UserPass.Trim()); } dc.tblUsers.Update(upDateRow); // Commit the changes and get the number of rows affected dc.SaveChanges(); } } } }); return(true); }
public async static Task <int> Update(User user, bool nameonly = false, bool rollback = false) { try { int results = 0; await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { // Check if username already exists - do not allow .... bool inuse = dc.tblUsers.Any(u => u.UserName.Trim().ToUpper() == user.UserName.Trim().ToUpper() && u.Id != user.Id); if (inuse) { throw new Exception("This User Name already exists."); } else { IDbContextTransaction transaction = null; if (rollback) { transaction = dc.Database.BeginTransaction(); } tblUser upDateRow = dc.tblUsers.FirstOrDefault(r => r.Id == user.Id); if (upDateRow != null) { upDateRow.FirstName = user.FirstName.Trim(); upDateRow.LastName = user.LastName.Trim(); if (!nameonly) { upDateRow.UserName = user.UserName.Trim(); upDateRow.UserPass = GetHash(user.UserPass.Trim()); } dc.tblUsers.Update(upDateRow); // Commit the changes and get the number of rows affected results = dc.SaveChanges(); if (rollback) { transaction.Rollback(); } } else { throw new Exception("User was not found."); } } } }); return(results); } catch (Exception) { throw; } }