public Group(String name, String description, timeperiod time, DateTime date, Instructor instructor, GymRoom room) { this.Name = name; this.Description = description; this.Time = time; this.Date = date; this.Instructor = instructor; this.Room = room; this.Clients = new List<Client>(); }
// GET: Timeperiod/Edit/5 public ActionResult Edit(DateTime id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } timeperiod timeperiod = db.timeperiods.Find(id); if (timeperiod == null) { return(HttpNotFound()); } return(View(timeperiod)); }
private string TimePeriodToString(timeperiod time)//Little method to get proper string values of our timeperiod enum { string result = "time period invalid"; switch (time) { case timeperiod.MORNING: { result = "8:00-11:00"; break; } case timeperiod.MIDDAY: { result = "11:00-14:00"; break; } case timeperiod.AFTERNOON: { result = "14:00-17:00"; break; } case timeperiod.EVENING: { result = "17:00-20:00"; break; } } return result; }
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)); }