public void PayrollSetup_021_UpdateSpiff() { // Arrange SQLHelper.RunSetupScript("UnitTest_PayrollSetup", "A9"); int franchiseID = 39; ReportingService rs = ReportingService.Create <ReportingService>(Guid.NewGuid()); SiteBlue.Business.Reporting.PayrollSetup[] arrPayrollSetup = rs.GetPayrollSetupData(franchiseID); Assert.AreEqual <int>(1, arrPayrollSetup.Length); int payrollSetupID = arrPayrollSetup[0].PayrollSetupID; int payrollSpiffID = arrPayrollSetup[0].PayrollSpiffs.ToArray()[0].PayrollSpiffID; int serviceProID = 172; int jobCodeID = 65834; int payType = 1; decimal rate = 3.5M; DateTime?dateExpires = DateTime.Parse("5/2/2014"); string comments = "Test comments Update Spiff"; bool addOn = true; bool active = true; // Act // Save Spiff to existing PayrollSetup PayrollSetupService payrollSetupService = PayrollSetupService.Create <PayrollSetupService>(Guid.NewGuid()); OperationResult <SiteBlue.Business.PayrollSetup.PayrollSpiff> result = payrollSetupService.PayrollSpiff_Update(payrollSpiffID, serviceProID, jobCodeID, payType, rate, dateExpires, comments, addOn, active); // Assert SiteBlue.Business.PayrollSetup.PayrollSpiff newSpiff = result.ResultData; Assert.AreEqual <int>(payrollSetupID, newSpiff.PayrollSetupID); Assert.AreEqual <int>(serviceProID, newSpiff.ServiceProID); Assert.AreEqual <int>(jobCodeID, newSpiff.JobCodeID); Assert.AreEqual <int>(payType, newSpiff.PayType); Assert.AreEqual <decimal>(rate, newSpiff.Rate); Assert.AreEqual <DateTime?>(dateExpires, newSpiff.DateExpires); Assert.AreEqual <string>(comments, newSpiff.Comments); Assert.AreEqual <bool>(addOn, newSpiff.AddOn); Assert.AreEqual <bool>(active, newSpiff.Active); // Can also check the saved entity SiteBlue.Business.Reporting.PayrollSetup[] arrRptPayrollSetup = rs.GetPayrollSetupData(franchiseID); Assert.AreEqual <int>(1, arrRptPayrollSetup.Length); Assert.AreEqual <int>(1, arrRptPayrollSetup[0].PayrollSpiffs.Count()); SiteBlue.Business.Reporting.PayrollSpiff reportSpiff = arrRptPayrollSetup[0].PayrollSpiffs.ToArray()[0]; Assert.AreEqual <int>(payrollSetupID, reportSpiff.PayrollSetupID); Assert.AreEqual <int>(serviceProID, reportSpiff.ServiceProID); Assert.AreEqual <int>(jobCodeID, reportSpiff.JobCodeID); Assert.AreEqual <int>(payType, reportSpiff.PayTypeID); Assert.AreEqual <decimal>(rate, reportSpiff.Rate); Assert.AreEqual <DateTime?>(dateExpires, reportSpiff.DateExpires); Assert.AreEqual <string>(comments, reportSpiff.Comments); Assert.AreEqual <bool>(addOn, reportSpiff.AddOn); Assert.AreEqual <bool>(active, reportSpiff.Active); }
public OperationResult <PayrollSpiff> PayrollSpiff_Add(int payrollSetupID, int serviceProID, int jobCodeID, int payType, decimal rate, DateTime?dateExpires, string comments, bool addOn, bool active) { // Step 0: Business Validation - make sure the payroll SETUP ID exists int existingCount = (from payrollSetup in db.tbl_HR_PayrollSetup where payrollSetup.PayrollSetupID == payrollSetupID select payrollSetup).Count(); if (existingCount == 0) { throw new PayrollSetupDoesNotExistException(payrollSetupID); } // Step 1: inflate a POCO object with our parameters and do any validation PayrollSpiff toReturn = new PayrollSpiff() { PayrollSetupID = payrollSetupID, ServiceProID = serviceProID, JobCodeID = jobCodeID, PayType = payType, Rate = rate, DateExpires = dateExpires, Comments = comments, AddOn = addOn, Active = active }; // Step 2: Save to DB tbl_HR_PayrollSpiffs newPayrollSpiff = new tbl_HR_PayrollSpiffs(); newPayrollSpiff.PayrollSetupID = payrollSetupID; newPayrollSpiff.ServiceProID = serviceProID; newPayrollSpiff.JobCodeID = jobCodeID; newPayrollSpiff.PayTypeID = payType; newPayrollSpiff.Rate = rate; newPayrollSpiff.DateExpires = dateExpires; newPayrollSpiff.Comments = comments; newPayrollSpiff.AddonYN = addOn; newPayrollSpiff.ActiveYN = active; db.tbl_HR_PayrollSpiffs.AddObject(newPayrollSpiff); db.SaveChanges(); return(new OperationResult <PayrollSpiff>() { Success = true, ResultData = toReturn }); }
public OperationResult <PayrollSpiff> PayrollSpiff_Update(int payrollSpiffID, int serviceProID, int jobCodeID, int payType, decimal rate, DateTime?dateExpires, string comments, bool addOn, bool active) { // Step 1: Get existing Spiff from DB tbl_HR_PayrollSpiffs existingPayrollSpiff = (from tbl_HR_PayrollSpiffs payrollSpiff in db.tbl_HR_PayrollSpiffs where payrollSpiff.PayrollSpiffID == payrollSpiffID select payrollSpiff).FirstOrDefault <tbl_HR_PayrollSpiffs>(); if (existingPayrollSpiff == null) { throw new Exception("Cannot update SPIFF. Record does not exist. ID: " + payrollSpiffID.ToString()); } // Step 2: inflate a POCO object with our parameters and do any validation PayrollSpiff toReturn = new PayrollSpiff() { PayrollSetupID = existingPayrollSpiff.PayrollSetupID, ServiceProID = serviceProID, JobCodeID = jobCodeID, PayType = payType, Rate = rate, DateExpires = dateExpires, Comments = comments, AddOn = addOn, Active = active }; // Step 3: Save to DB existingPayrollSpiff.ServiceProID = serviceProID; existingPayrollSpiff.JobCodeID = jobCodeID; existingPayrollSpiff.PayTypeID = payType; existingPayrollSpiff.Rate = rate; existingPayrollSpiff.DateExpires = dateExpires; existingPayrollSpiff.Comments = comments; existingPayrollSpiff.AddonYN = addOn; existingPayrollSpiff.ActiveYN = active; db.SaveChanges(); return(new OperationResult <PayrollSpiff>() { Success = true, ResultData = toReturn }); }