Exemplo n.º 1
0
        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
            });
        }
Exemplo n.º 2
0
        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
            });
        }