// GET: Timesheet public ActionResult Create(DateTime date) { string message; if (Request.Cookies["UserID"].Value == null) { //Redirect to login if it can't find user id TempData["message"] = "Please log in."; System.Diagnostics.Debug.WriteLine("User not logged in. Redirecting to login page.\n"); return(RedirectToAction("LandingPage", "Home")); } //ensure that the model exists if (ModelState.IsValid) { //Email already exists using (Entities dc = new Entities()) { GrizzTime.Models.payrollcycle pc = new GrizzTime.Models.payrollcycle(); //pc.PayrollCycleStart = System.DateTime.Now.StartOfWeek(DayOfWeek.Monday).Date; //pc.PayrollCycleEnd = System.DateTime.Now.StartOfWeek(DayOfWeek.Monday).AddDays(7).Date; //pc.PayrollCycleYear = (short)System.DateTime.Now.Year; pc.PayrollCycleStart = date.Date; pc.PayrollCycleEnd = date.AddDays(-7).Date; pc.PayrollCycleYear = (short)date.Year; dc.payrollcycles.Add(pc); dc.SaveChanges(); GrizzTime.Models.timesheet ts = new GrizzTime.Models.timesheet(); ts.PayrollCycleID = pc.PayrollCycleID; ts.EmpID = Int32.Parse(Request.Cookies["UserID"].Value); ts.TimeSheetStatus = "In Progress"; dc.timesheets.Add(ts); dc.SaveChanges(); int tsID = ts.TimeSheetID; message = "New timesheet and payroll cycle created."; TempData["message"] = message; return(RedirectToAction("Week", "Timesheet", new { id = tsID })); } } else { message = "Something messed up."; TempData["message"] = message; return(RedirectToAction("Week")); } }
public ActionResult ExpenseEntry() { //TODO: ADD edit/view expense entry logic in here using (Entities dc = new Entities()) { ViewBag.UserID = Int32.Parse(Request.Cookies["UserID"].Value); var d = System.DateTime.Now.StartOfWeek(DayOfWeek.Monday).Date; var v = dc.payrollcycles.Where(a => a.PayrollCycleStart == d).FirstOrDefault(); if (v == null) { GrizzTime.Models.payrollcycle pc = new GrizzTime.Models.payrollcycle(); pc.PayrollCycleStart = System.DateTime.Now.StartOfWeek(DayOfWeek.Monday).Date; pc.PayrollCycleEnd = System.DateTime.Now.StartOfWeek(DayOfWeek.Monday).AddDays(7).Date; pc.PayrollCycleYear = (short)System.DateTime.Now.Year; dc.payrollcycles.Add(pc); dc.SaveChanges(); } ViewBag.IsChangeable = true; return(View()); } }