public void CreatePayroll() { using (ApplicationDbContext db = new ApplicationDbContext(this.TestDatabase)) { Account lAccount = this.TestAccount; Company lCompany = this.TestCompany; Contact lCompanyContact = this.TestContact; Contact lEmployeeContact = this.TestContact; Employee lCompanyEmployee = this.TestEmployee; Payroll lCompanyPayroll = this.TestPayroll; PayrollDetails lCompanyPayrollDetails = this.TestPayrollDetails; lCompanyEmployee.Contact = lEmployeeContact; lCompany.Contact = lCompanyContact; lCompany.Employees.Add(lCompanyEmployee); lAccount.Company = lCompany; lAccount.Company.Payrolls.Add(lCompanyPayroll); db.Account.Add(lAccount); db.SaveChanges(); lCompanyPayrollDetails.EmployeeId = lCompanyEmployee.Id; lCompanyPayroll.Company.Payrolls.FirstOrDefault().Details.Add(lCompanyPayrollDetails); db.SaveChanges(); } }
private void PayrollGridView_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e) { try { if (e.Row is DataRowView row) { UnitOfWork unitOfWork = new UnitOfWork(); var employeeId = row["EmployeeId"]?.ToInt(); var employee = unitOfWork.EmployeesRepo.Find(m => m.Id == employeeId); if (employee == null) { if (sender is GridView gridView) { gridView.SetFocusedRowModified(); return; } } var item = new PayrollDetails() { Id = row["Id"].ToInt(), ItemNumber = row["ItemNumber"].ToInt(), Name = employee?.EmployeeName, Designation = employee?.Position, EmployeeId = employeeId, }; item.PayrollId = obId; item.Total = 0; foreach (var i in frm.txtColumnTitle.Text.Split(',')) { item.Total += row[i]?.ToDecimal() ?? 0; item.ColumnTitle += i + "=" + (row[i]?.ToDecimal() ?? 0) + ","; } row["Total"] = item.Total; if (item.Id == 0) { unitOfWork.PayrollDetailsRepo.Insert(item); } else { unitOfWork.PayrollDetailsRepo.Update(item); } unitOfWork.Save(); InitializeGridView(unitOfWork.PayrollsRepo.Find(x => x.Id == obId)); } } catch (Exception exception) { MessageBox.Show(exception.Message, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void UpdatePayroll() { Int32 lUpdatePayrollId = 0; using (ApplicationDbContext db = new ApplicationDbContext(this.TestDatabase)) { Account lAccount = this.TestAccount; Company lCompany = this.TestCompany; Contact lCompanyContact = this.TestContact; Contact lEmployeeContact = this.TestContact; Employee lCompanyEmployee = this.TestEmployee; Payroll lCompanyPayroll = this.TestPayroll; PayrollDetails lCompanyPayrollDetails = this.TestPayrollDetails; lCompanyEmployee.Contact = lEmployeeContact; lCompany.Contact = lCompanyContact; lCompany.Employees.Add(lCompanyEmployee); lAccount.Company = lCompany; lAccount.Company.Payrolls.Add(lCompanyPayroll); db.Account.Add(lAccount); db.SaveChanges(); lCompanyPayrollDetails.EmployeeId = lCompanyEmployee.Id; lCompanyPayroll.Company.Payrolls.FirstOrDefault().Details.Add(lCompanyPayrollDetails); db.SaveChanges(); lUpdatePayrollId = lCompanyPayroll.Id; } using (ApplicationDbContext db = new ApplicationDbContext(this.TestDatabase)) { Payroll lUpdatePayroll = db.Payroll.Find(lUpdatePayrollId); lUpdatePayroll.WeekEnding = DateTime.UtcNow.AddDays(7); lUpdatePayroll.Details.FirstOrDefault().HoursOvertimeWorked = 20; db.SaveChanges(); } }
public void TestAddIntoDatabaseOfHandleDatabseClassPassEmployeeDetailsObejctsAndGetTheNumberOfRowsAffected() { EmployeeDetails employeeDetails = new EmployeeDetails() { EmployeeID = 12, Name = "New Name", StartDate = Convert.ToDateTime("05/04/2020"), Gender = "F", Phone = "7889564512", SalaryID = 115, Address = "New Address", IsActive = 1 }; CompanyData companyData = new CompanyData() { DepartmentID = 510, DepartmentName = "New Department 5" }; Department department = new Department() { DepartmentID = 510, EmployeeID = 12 }; PayrollDetails payrollDetails = new PayrollDetails() { SalaryID = 115, BasicPay = 7889, Deduction = 78, IncomeTax = 56, NetPay = 7715, Taxable = 156 }; int actual = HandleDatabase.AddAnEmployee(employeeDetails, companyData, department, payrollDetails); Assert.AreEqual(4, actual); }
public IActionResult OnPost(int yyyy, int mm, string jsonStr) { if (string.IsNullOrEmpty(jsonStr)) { return(Page()); } var Payrolls = Newtonsoft.Json.JsonConvert.DeserializeObject <IList <PayrollDetailsDTO> >(jsonStr); if (Payrolls == null) { return(Page()); } var Rcid = _pinhuaContext.GetNewRcId(); var rtId = _pinhuaContext.GetRtId("工资单"); var repCase = new EsRepCase { RcId = Rcid, RtId = rtId, LstFiller = 2, LstFillerName = User.Identity.Name, LstFillDate = DateTime.Now, }; var payrollMain = new PayrollMain { ExcelServerRcid = Rcid, ExcelServerRtid = rtId, Y = yyyy, M = mm }; var payrollDetails = new List <PayrollDetails>(); foreach (var payroll in Payrolls) { var pd = new PayrollDetails { ExcelServerRcid = Rcid, ExcelServerRtid = rtId, Y = yyyy, M = mm, }; _mapper.Map <PayrollDetailsDTO, PayrollDetails>(payroll, pd); payrollDetails.Add(pd); } _pinhuaContext.EsRepCase.Add(repCase); _pinhuaContext.PayrollMain.Add(payrollMain); _pinhuaContext.PayrollDetails.AddRange(payrollDetails); try { _pinhuaContext.SaveChanges(); } catch (DbUpdateException e) { ModelState.AddModelError("", e.InnerException.Message); return(Page()); } return(RedirectToPage("Index")); }