using System; using System.Collections.Generic; using System.Drawing; using System.Web.Mvc; using custom.Web.Models; using custom.BLL.Model; namespace custom.Web.Controllers { public class HomeController : Controller { private IPayrollService _payRollService; private EmployeeService _employeeService; protected new CustomPrincipal User { get { return HttpContext.User as CustomPrincipal; } } public HomeController() : this(new PayrollService(), new EmployeeServiceClient()) { } public HomeController(IPayrollService payrollService, EmployeeService employeeService) { _payRollService = payrollService; _employeeService = employeeService; } [HttpPost] //[ValidateAntiForgeryToken] public ActionResult Calculate(TimeSheetViewModel model, FormCollection form) { model.TimeSheet.Emp_Uno = User.EmployeeUno; var week = _payRollService.ExecutePayRollRules(User.EmployeeUno, model.SelectedPayRollWeek, model.tz); for (int itr = 0; itr < 7; itr++) { // days of week Sunday to Monday, so total 7 if (form["TimeSheet.DayList[" + itr + "].IsMealBreakWaived"] != null) { bool SelectedActualValue = Convert.ToBoolean(form["TimeSheet.DayList[" + itr + "].IsMealBreakWaived"].ToString().Split(',')[0]); string selectedTransDate = form["TimeSheet.DayList[" + itr + "].TRAN_DATE"]; if (SelectedActualValue == true) { week.DayList[itr].IsMealBreakWaived = true; week.DayList[itr].TRAN_DATE = DateTime.Parse(selectedTransDate); } } } _payRollService.AddTimeEntries(week); WeekClass timeSheet = _payRollService.GetTimeSheet(User.EmployeeUno, model.SelectedPayRollWeek, model.tz); model.TimeSheet = timeSheet; model.Format(); model.GetErrors(ModelState); model.GetWarnings(); if (!ModelState.IsValid) { // re-render the view when validation failed. return View("TimeSheet", model); } return View("TimeSheet", model); } // GET: /Home/TimeSheet/?p={value} [HttpGet] public ActionResult TimeSheet(string p, string tz) { WeekClass timeSheet = _payRollService.GetTimeSheet(User.EmployeeUno, p, tz); // FOR PRODUCTION var model = new TimeSheetViewModel { EmployeeName = User.EmployeeName, ApproverName = User.ManagerName, TimeSheet = timeSheet, SelectedPayRollWeek = p, tz = tz }; //Onload selected string[] pt = p.Split('-'); //seperating start of the week, end of the week var mealAndRestTimes = _payRollService.GetEntriesFromCustomDb(User.EmployeeUno, DateTime.Parse(pt[0]), DateTime.Parse(pt[1])); var curlength = mealAndRestTimes.Length; if (curlength != 0) { for (int ctr = 0; ctr < curlength; ctr++) { foreach (var day in timeSheet.DayList) { if ((mealAndRestTimes[ctr].MealHours > 0) && (day.TRAN_DATE == mealAndRestTimes[ctr].Date)) { day.IsMealBreakWaived = true; } } } } model.Format(); model.GetErrors(ModelState); model.GetWarnings(); return View(model); } } }