public void AddEmployeeDeductions(AssignedEmployeeDeduction toDB) { using (var db = new PayrollEntities()) { db.AssignedEmployeeDeductions.Add(toDB); db.SaveChanges(); } }
public ActionResult EditDeduction(AddDeductionViewModel fromModel) { AssignedEmployeeDeductionBL assingedEmployeeBL = new AssignedEmployeeDeductionBL(); DeductionBL bL = new DeductionBL(); AddDeductionViewModel toModel = new AddDeductionViewModel(); Deduction deduction = new Deduction(); toModel.Deductions = new SelectList(bL.GetActiveDeductions(), "DeductionId", "DeductionName", 1); toModel.UserPersonalInformationId = fromModel.UserPersonalInformationId; toModel.DeductionId = fromModel.DeductionId; toModel.Name = fromModel.Name; //toModel.SelectedCustomAmount = fromModel.SelectedCustomAmount; deduction = bL.GetDeductionById(fromModel.DeductionId); if (deduction != null) { toModel.SelectedDeductionAmount = 0.0M; toModel.SelectedDeductionName = deduction.DeductionName; } else { toModel.SelectedDeductionAmount = fromModel.SelectedDeductionAmount; toModel.SelectedDeductionName = fromModel.SelectedDeductionName; } AssignedEmployeeDeduction toDB = new AssignedEmployeeDeduction(); if (ModelState.IsValid) { if (fromModel.DeductionId > 0) { toDB.UserPersonalInformationID = toModel.UserPersonalInformationId; //toDB.CustomAmount = toModel.SelectedCustomAmount; toDB.DeductionAmount = toModel.SelectedDeductionAmount; toDB.DeductionId = toModel.DeductionId; assingedEmployeeBL.UpdateEmployeeDeduction(toDB); } else { ModelState.AddModelError("", "Please select a Deduction."); return(View(toModel)); } } else { ModelState.AddModelError("", "Error."); return(View(toModel)); } return(RedirectToAction("AssignDeduction", "Home", new { id = fromModel.UserPersonalInformationId })); }
public void UpdateEmployeeDeduction(AssignedEmployeeDeduction toDB) { using (var db = new PayrollEntities()) { var result = db.AssignedEmployeeDeductions.SingleOrDefault(b => b.UserPersonalInformationID == toDB.UserPersonalInformationID && b.DeductionId == toDB.DeductionId); if (result != null) { //result.CustomAmount = toDB.CustomAmount; db.SaveChanges(); } } }