// // GET: /Home/ public ActionResult Index() { try { DateTime date = DateTime.Today.AddDays(7); DateTime date2 = DateTime.Now.AddMonths(-1); IEnumerable<appointment> appointments = db.appointments.Where(i => i.employeeid == User.Identity.Name && i.starttime >= DateTime.Today && i.starttime <= date); IEnumerable<issue> issues = db.issues.Where(i => i.date <= date2 && i.status != "Complete"); List<Events> Events = new List<Events>(); foreach (appointment appointment in appointments) { Events Event = new Events(); Event.id = appointment.appointmentid; Event.title = appointment.subject; Event.allDay = appointment.allday; Event.start = ConvertToUnixTimestamp(appointment.starttime).ToString(); Event.end = ConvertToUnixTimestamp(appointment.endtime).ToString(); Event.url = Url.Action("Details/" + appointment.appointmentid.ToString()); switch (appointment.appointmenttype.Trim()) { case "Personal": Event.color = "#009B00"; break; case "Advisement": Event.color = "#36C"; break; case "Office": Event.color = "#800080"; break; } Events.Add(Event); } List<IssuesPOCO> _issues = new List<IssuesPOCO>(); foreach (issue i in issues.OrderByDescending(e => e.date)) { IssuesPOCO temp = new IssuesPOCO(); temp.IssueID = i.issueid; temp.Name = i.issuename; temp.Date = ConvertToUnixTimestamp(i.date).ToString(); temp.Status = i.status; temp.Urgency = i.urgency; _issues.Add(temp); } IndexHomeModel model = new IndexHomeModel() { _Events = Events, _Issues = _issues }; return View(model); } catch (Exception ex) { return View(); } }
public ActionResult Index(IndexCalendarModel model) { IEnumerable<appointment> appoint; List<appointment> appointments; if (model.cName.Equals("All")) { if (User.IsInRole("Receptionist")) { appoint = db.appointments; } else { appoint = db.appointments.Where(i => i.employeeid == User.Identity.Name); } } else { if (User.IsInRole("Receptionist")) { appoint = db.appointments.Where(i => i.cname == model.cName); } else { appoint = db.appointments.Where(i => i.employeeid == User.Identity.Name && i.cname == model.cName); } } if (model.advisorID != null) { model.advisorID = model.advisorID.Remove(0, model.advisorID.Length - 10); model.advisorID = model.advisorID.Remove(model.advisorID.Length - 1); appoint = appoint.Where(a => a.employeeid == model.advisorID); appointments = appoint.ToList(); IEnumerable<Attendee> Attendee = db.Attendees.Where(i => i.attendee1 == model.advisorID && (i.confirmed == true || i.confirmed == null)); foreach (Attendee Attend in Attendee) { if (model.cName.Equals("All")) { appointments.Add(db.appointments.Single(i => i.appointmentid == Attend.appointmentid)); } else { appointment app = db.appointments.Single(i => i.appointmentid == Attend.appointmentid); if (app.cname == model.cName) appointments.Add(app); } } } else { appointments = appoint.ToList(); } if (!User.IsInRole("Receptionist")) { IEnumerable<Attendee> Attendee = db.Attendees.Where(i => i.attendee1 == User.Identity.Name && (i.confirmed == true || i.confirmed == null)); foreach (Attendee Attend in Attendee) { if (model.cName.Equals("All")) { appointments.Add(db.appointments.Single(i => i.appointmentid == Attend.appointmentid)); } else { appointment app = db.appointments.Single(i => i.appointmentid == Attend.appointmentid); if (app.cname == model.cName) appointments.Add(app); } } } List<Events> events = new List<Events>(); foreach (appointment appointment in appointments) { Events Events = new Events(); Events.id = appointment.appointmentid; Events.title = appointment.subject; Events.allDay = appointment.allday; Events.start = ConvertToUnixTimestamp(appointment.starttime).ToString(); Events.end = ConvertToUnixTimestamp(appointment.endtime).ToString(); Events.url = Url.Action("Details/" + appointment.appointmentid.ToString()); switch (appointment.appointmenttype.Trim()) { case "Personal": Events.color = "#009B00"; break; case "Advisement": Events.color = "#36C"; break; case "Office": Events.color = "#800080"; break; } events.Add(Events); } IEnumerable<campu> campus = db.campus; List<String> list = new List<String>(); list.Add("All"); foreach (campu camp in campus) { list.Add(camp.cname); } IEnumerable<employee> employees = db.employees; List<AutoCompletePOCO> EmployeeID = new List<AutoCompletePOCO>(); foreach (employee emp in employees) { AutoCompletePOCO poco = new AutoCompletePOCO() { value = emp.fname + " " + emp.lname + " (" + emp.employeeid + ")", Label = emp.fname + " " + emp.lname + " (" + emp.employeeid + ")", Email = emp.email, Role = emp.role }; EmployeeID.Add(poco); } model.cNames = list; model.Events = events; model.AutoCom = EmployeeID; return View(model); }