/// <summary> /// Creates a Driver Log entry for a return trip /// </summary> /// <param name="regularId">regularId</param> /// <returns>DriverLogViewModel object</returns> public DriverLogViewModel CreateRTVM(int regularId) { Regular regular = db.Regulars.Find(regularId); foreach (var rt in regular.ReturnTrips.Where(x=>x.Id != null)) { //Create a new driver log vm = new DriverLogViewModel() { //Set PickupTime = meth.convertTimeToDate(rt.PickupTime.Value), Date = regular.Date, PickupLocation = meth.ReturnPickupLocation(regular.Id), Destination = meth.ReturnDestinationLocation(regularId), TripType = regular.TripType.Name, Member = regular.Member.Name, Count = meth.CountGuests(regular.Id), emailaddress = regular.Email, Phone = regular.Phone, Notes = regular.Notes }; } return vm; }
public ActionResult DailyReport(DateTime Date) { //Create a list of DriverLogViewModel objects List<DriverLogViewModel> dlList = new List<DriverLogViewModel>(); //Create a new ViewBag with date variable in the longstringformat ViewBag.Date = Date.ToLongDateString(); //Create a regular list with the date, if the trip is not cancelled // and order it by Pickup times var regular = db.Regulars.Where(x => x.Date == Date) .Where(x => x.IsCancelled == false) .OrderBy(x => x.PickupTime) .ToList(); //foreach item in regular object list foreach (var item in regular) { //Create a new VM vm = new DriverLogViewModel(item.Id); //add it to the list dlList.Add(vm); if (item.ReturnTrips.Count != 0) { //Create a new return trip VM vm = dl.CreateRTVM(item.Id); //add it to the list dlList.Add(vm); } } //Try to send the list of trips to the view try { return PartialView(dlList); } //Catch an Exception catch (Exception e) { //Log the Exception message and the custom method // log.FatalError(e.Message); // log.FatalError(Hermes.ViewModels.ReportViewModel.Resources.InvalidDailyReportLog, 23); //Return HttpNotFound View return new HttpNotFoundResult(); } }