public PaymentPerDay getPaymentOfUserById(int ID) { PaymentPerDay payment = base.db.PaymentPerDays.Where(u => u.UserID == ID).FirstOrDefault(); if (payment == null) { return(base.db.PaymentPerDays.Where(u => u.UserID == null).FirstOrDefault()); } else { return(payment); } }
public ActionResult Index() { int ID = SessionContext.CurrentUser().ID; Monthly_Schedule userMonth = _provider.getDataMonth(ID); Salary userSalary = _provider.getSalaryOfUserByID(ID); PaymentPerDay paymen = _provider.getPaymentOfUserById(ID); ViewBag.Salary = userSalary.Payment; ViewBag.TotalSalary = Convert.ToDateTime(userMonth.EndDay.ToString()).Day *paymen.Money; ViewBag.TotalDay = Convert.ToDateTime(userMonth.EndDay.ToString()).Day; ViewBag.TotalRollCountday = userMonth.TotalCount; ViewBag.Fullname = SessionContext.CurrentUser().Firstname + " " + SessionContext.CurrentUser().Lastname; ViewBag.TotalUser = _provider.getAllUser().Count(); return(View()); }
public Salary getSalaryOfUserByID(int ID) { try { Monthly_Schedule select = base.db.Monthly_Schedule.Where(u => u.UserID == ID).FirstOrDefault(); PaymentPerDay paymentOfDay = base.db.PaymentPerDays.Where(u => u.UserID == ID).FirstOrDefault(); Double salary = 0; if (select != null) { if (paymentOfDay == null) { paymentOfDay = base.db.PaymentPerDays.Where(u => u.UserID == null).FirstOrDefault(); } salary = Convert.ToInt32(select.TotalCount) * Convert.ToDouble(paymentOfDay.Money); Salary UserSalary = base.db.Salaries.Where(u => u.UserID == ID).FirstOrDefault(); if (UserSalary != null) { UserSalary.Payment = Convert.ToDecimal(salary); base.db.SaveChanges(); return(UserSalary); } else { UserSalary = new Salary(); UserSalary.MonthID = select.ID; UserSalary.UserID = ID; UserSalary.Payment = Convert.ToDecimal(salary); UserSalary.PayMentOfUserID = paymentOfDay.ID; base.db.Salaries.Add(UserSalary); base.db.SaveChanges(); return(UserSalary); } } else { return(null); } } catch (Exception ex) { return(null); } }