public async static Task <ServiceType> LoadByDescription(string description) { try { ServiceType serviceType = new ServiceType(); await Task.Run(() => { using (LawnProEntities dc = new LawnProEntities()) { tblServiceType tblServicetype = dc.tblServiceTypes.FirstOrDefault(s => s.Description == description); if (tblServicetype != null) { serviceType.Id = tblServicetype.Id; serviceType.Description = tblServicetype.Description; serviceType.CostPerSQFT = tblServicetype.CostPerSqFt; } else { throw new Exception("Service type not found"); } } }); return(serviceType); } catch (Exception) { throw; } }
public void DeleteTest() { InsertTest(); int expected = 1; int actual = 0; tblServiceType deleteRow = dc.tblServiceTypes.Where(a => a.Id == servicetypeId).FirstOrDefault(); if (deleteRow != null) { dc.tblServiceTypes.Remove(deleteRow); actual = dc.SaveChanges(); } Assert.AreEqual(expected, actual); }
public void UpdateTest() { InsertTest(); int expected = 1; int actual = 0; tblServiceType updateRow = dc.tblServiceTypes.Where(a => a.Id == servicetypeId).FirstOrDefault(); if (updateRow != null) { updateRow.CostPerSqFt = 0.0055M; actual = dc.SaveChanges(); } 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()) { 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 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 <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; } }