public ActionResult Edit(int EmployeeId, DateTime? timeCardDate) { db = new EMSEntities12(); int CompanyId = EMSPSSUtilities.GetCompanyId(EmployeeId); if (timeCardDate != null) { DateTime weekOf = (DateTime)timeCardDate.Value; while (weekOf.DayOfWeek != DayOfWeek.Monday) { weekOf = weekOf.AddDays(-1); } TimeCard tc = new TimeCard(); List<TimeCard> allTCs = db.TimeCards.ToList(); foreach (TimeCard tmp in allTCs) { if ((tmp.EmployeeRef5Id == EmployeeId) && (tmp.EmployedWith5Id == CompanyId) && (tmp.WeekOf == weekOf)) { return View(tmp); } } // if it reaches here, the timecard was not found // create and add it before proceeding tc.EmployedWith5Id = CompanyId; tc.EmployeeRef5Id = EmployeeId; tc.Employee = db.Employees.Find(EmployeeId); tc.Company = db.Companies.Find(CompanyId); tc.WeekOf = weekOf; tc.Mon = null; tc.Tue = null; tc.Wed = null; tc.Thu = null; tc.Fri = null; tc.Sat = null; tc.Sun = null; db.TimeCards.Add(tc); db.SaveChanges(); return View(tc); } return RedirectToAction("Index", "TimeCard", new { EmployeeId = EmployeeId, CompanyId = CompanyId }); }
public ActionResult Edit(TimeCard timecard) { db = new EMSEntities12(); if (ModelState.IsValid) { db.Entry(timecard).State = EntityState.Modified; db.SaveChanges(); foreach (Employee emp in db.Employees) { if (emp.EmployeeId == timecard.EmployeeRef5Id) { ViewBag.Name = emp.FirstName + " " + emp.LastName; break; } } foreach (Company cmp in db.Companies) { if (cmp.CompanyId == timecard.EmployedWith5Id) { ViewBag.Company = cmp.CompanyName; break; } } ViewBag.EmployeeId = timecard.EmployeeRef5Id; ViewBag.CompanyId = timecard.EmployedWith5Id; return RedirectToAction("Index", "TimeCard", new { EmployeeId = timecard.EmployeeRef5Id, CompanyId = timecard.EmployedWith5Id }); } return View(timecard); }
private decimal? TotalHours(TimeCard Hours) { decimal? total; total = Hours.Mon.GetValueOrDefault(0) + Hours.Tue.GetValueOrDefault(0) + Hours.Wed.GetValueOrDefault(0) + Hours.Thu.GetValueOrDefault(0) + Hours.Fri.GetValueOrDefault(0) + Hours.Sat.GetValueOrDefault(0) + Hours.Sun.GetValueOrDefault(0); return total; }
private TimeCard GetTimeCardEntry(int employeeId) { TimeCard tc = new TimeCard(); DateTime weekOf = DateTime.Now.Date; while (weekOf.DayOfWeek != DayOfWeek.Monday) { weekOf = weekOf.AddDays(-1); } List<TimeCard> allTCs = db.TimeCards.ToList(); foreach (TimeCard tmp in allTCs) { if ((tmp.EmployeeRef5Id == employeeId) && (tmp.WeekOf == weekOf)) { tc = tmp; } } return tc; }
private float addHours(TimeCard tc) { float hours = 0; if (tc.Mon != null) { hours += (float)tc.Mon; } if (tc.Tue != null) { hours += (float)tc.Tue; } if (tc.Wed != null) { hours += (float)tc.Wed; } if (tc.Thu != null) { hours += (float)tc.Thu; } if (tc.Fri != null) { hours += (float)tc.Fri; } if (tc.Sat != null) { hours += (float)tc.Sat; } if (tc.Sun != null) { hours += (float)tc.Sun; } return hours; }
public ActionResult HoursIndex(Nullable<DateTime> DateTimeQuery, string CompList) { db = new EMSEntities12(); //if (DateTimeQuery != null) //{ // return View("HoursWorkedReport" ); //} DateTime timeofweek = DateTime.Now ; Company MyComp = new Company(); EmployeeType MyEmp = new EmployeeType(); TimeCard TimeCardEnt = new TimeCard(); Dictionary<EmployeeType, decimal?> emplist2 = new Dictionary<EmployeeType, decimal?>(); List<TimeCard> tmcard = new List<TimeCard>(); if (DateTimeQuery != null) { ViewBag.ThisCompany = CompList; timeofweek = (DateTime)DateTimeQuery; foreach (Company mycmp in db.Companies) { if (mycmp.CompanyName == CompList) { MyComp.CompanyId = mycmp.CompanyId; } } while (timeofweek.DayOfWeek != DayOfWeek.Sunday) { timeofweek = timeofweek.AddDays(+1); } ViewBag.DateWeek = timeofweek; } List<EmployeeType> emplist = new List<EmployeeType>(); foreach (EmployeeType EmpTime in db.EmployeeTypes) { if (EmpTime.CompanyId == MyComp.CompanyId) { if (EmpTime.Employee.Completed && EmpTime.Employee.Active) { if (EmpTime.EmployeeType1 != "Contract ") { emplist.Add(EmpTime); } } } } foreach (TimeCard TimecrdEnt in db.TimeCards) { if (TimecrdEnt.EmployedWith5Id == MyComp.CompanyId) { tmcard.Add(TimecrdEnt); } } foreach (EmployeeType EMP in emplist) { foreach (TimeCard tmcrd in tmcard) { if (EMP.EmployeeId == tmcrd.EmployeeRef5Id) { if (DateTimeQuery == tmcrd.WeekOf) { emplist2.Add(EMP, TotalHours(tmcrd)); } } } } return View("HoursWorkedReport", emplist2); }