public ActionResult DeleteConfirmed(string id) { employeetimeperiod employeetimeperiod = db.employeetimeperiods.Find(id); db.employeetimeperiods.Remove(employeetimeperiod); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "Employee_employeeID,TimePeriod_periodEndDate,isApproved")] employeetimeperiod employeetimeperiod) { if (ModelState.IsValid) { db.Entry(employeetimeperiod).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Employee_employeeID = new SelectList(db.employees, "employeeID", "employeeFirstName", employeetimeperiod.Employee_employeeID); ViewBag.TimePeriod_periodEndDate = new SelectList(db.timeperiods, "periodEndDate", "periodEndDate", employeetimeperiod.TimePeriod_periodEndDate); return(View(employeetimeperiod)); }
// GET: TimePeriodByEmployee/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } employeetimeperiod employeetimeperiod = db.employeetimeperiods.Find(id); if (employeetimeperiod == null) { return(HttpNotFound()); } return(View(employeetimeperiod)); }
// GET: TimePeriodByEmployee/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } employeetimeperiod employeetimeperiod = db.employeetimeperiods.Find(id); if (employeetimeperiod == null) { return(HttpNotFound()); } ViewBag.Employee_employeeID = new SelectList(db.employees, "employeeID", "employeeFirstName", employeetimeperiod.Employee_employeeID); ViewBag.TimePeriod_periodEndDate = new SelectList(db.timeperiods, "periodEndDate", "periodEndDate", employeetimeperiod.TimePeriod_periodEndDate); return(View(employeetimeperiod)); }
public ActionResult SubmitHours(HomeViewModel submittedHours, string submitButton) { var emp = UserManager.User.employeeID; DateTime AddToWeek = submittedHours.currentWeekEndDate.Date; // Check if timeperiod already exists // If not create it DateTime timePeriod = submittedHours.currentWeekEndDate.Date; if (db.timeperiods.Find(timePeriod) == null) { timeperiod newTimePeriod = new timeperiod(); newTimePeriod.periodEndDate = timePeriod; new TimeperiodController().Create(newTimePeriod); } // Check if employee already has this timeperiod // If not create it var employeeTPexists = from tp in db.employeetimeperiods where tp.Employee_employeeID == emp && tp.TimePeriod_periodEndDate == timePeriod select tp; if (!employeeTPexists.Any()) { employeetimeperiod etp = new employeetimeperiod(); etp.Employee_employeeID = emp; etp.TimePeriod_periodEndDate = timePeriod; etp.isApproved = false; new EmployeeTimeperiodsController().Create(etp); } foreach (var entry in submittedHours.HoursWorked) { if (entry.isDeleted) { hoursworked deleteEntry = db.hoursworkeds.Find(entry.entryID); if (deleteEntry != null) { new HoursWorkedController().DeleteConfirmed(deleteEntry.entryID); } } else if (entry.hours > 0 && entry.Activity_activityID != 0 && entry.Project_projectID != 0) { if (entry.entryID == 0) { // Check if the activity was already logged on the current date // If it was, just add hours to the entry // Otherwise, create a new entry hoursworked newEntry = new hoursworked(); DateTime periodEndDate = AddToWeek; newEntry.hours = entry.hours; newEntry.Project_projectID = entry.Project_projectID; newEntry.Activity_activityID = entry.Activity_activityID; newEntry.date = ExtensionMethods.GetDateInWeek(periodEndDate, entry.currentDay); newEntry.comments = entry.comments; newEntry.TimePeriod_employeeID = emp; newEntry.TimePeriod_periodEndDate = periodEndDate.Date; if (ExtensionMethods.EntryExists(newEntry) == null) { new HoursWorkedController().Create(newEntry); } else { hoursworked existingEntry = ExtensionMethods.EntryExists(newEntry); existingEntry.hours += newEntry.hours; existingEntry.comments += ", " + newEntry.comments; new HoursWorkedController().AddHours(existingEntry); } } // Updating already existing entry else { // If we get to this point, entry is already saved to DB, and we're editing it hoursworked existingEntry = db.hoursworkeds.First(hw => hw.entryID == entry.entryID); existingEntry.Activity_activityID = entry.Activity_activityID; existingEntry.activity = entry.activity; existingEntry.Project_projectID = entry.Project_projectID; existingEntry.project = entry.project; existingEntry.hours = entry.hours; existingEntry.comments = entry.comments; existingEntry.date = entry.date; new HoursWorkedController().AddHours(existingEntry); } } } if (submitButton == "Previous") { submittedHours.currentWeekEndDate = submittedHours.currentWeekEndDate.AddDays(-7); } else if (submitButton == "Next") { submittedHours.currentWeekEndDate = submittedHours.currentWeekEndDate.AddDays(7); } ModelState.Clear(); HomeViewModel myModel = new HomeViewModel(); myModel.currentWeekEndDate = submittedHours.currentWeekEndDate; var query = from hw in db.hoursworkeds where hw.TimePeriod_employeeID == UserManager.User.employeeID && DbFunctions.TruncateTime(hw.TimePeriod_periodEndDate) == myModel.currentWeekEndDate.Date select hw; myModel.HoursWorked = query.ToList(); foreach (var hw in myModel.HoursWorked) { hw.currentDay = hw.date.DayOfWeek; } // If Timeperiod was already approved, set Viewbag isApproved to true var isApprovedQuery = from a in db.employeetimeperiods where a.Employee_employeeID == UserManager.User.employeeID && DbFunctions.TruncateTime(a.TimePeriod_periodEndDate) == myModel.currentWeekEndDate.Date select a; if (isApprovedQuery.Any()) { myModel.isApproved = isApprovedQuery.First().isApproved; } // Get list of active projects that group is working on List <project> groupProjects = GetGroupProjects(emp.ToString()); foreach (var hrworked in myModel.HoursWorked) { hrworked.ProjectList = groupProjects; } myModel.ProjectList = groupProjects; return(View("Index", myModel)); }