예제 #1
0
        public ActionResult Create(string truckurlslug)
        {
            ScheduledStopEditViewModel vm = new ScheduledStopEditViewModel();
            var locations = schedService.GetLocations();
            vm.Locations = mapper.Map <IEnumerable<LocationDetailViewModel>>(locations);
            vm.ListLocations = mapper.Map<IEnumerable<SelectListItem>>(locations);

            var timeSlots = CreateTimeSlots();
            vm.From = timeSlots;
            vm.To = timeSlots;

            return View(vm);
        }
예제 #2
0
        public ActionResult Create(ScheduledStopEditViewModel vm, string truckurlslug)
        {
            var stop = mapper.Map<ScheduledStop>(vm);
            DateTime from;
            DateTime to;
            DateTime.TryParseExact(vm.SelectedFrom, @"h\:mm tt", CultureInfo.CurrentCulture, DateTimeStyles.None, out from);
            DateTime.TryParseExact(vm.SelectedTo, @"h\:mm tt", CultureInfo.CurrentCulture, DateTimeStyles.None, out to);

            stop.From = new DateTime(vm.Day.Value.Year,vm.Day.Value.Month, vm.Day.Value.Day, from.Hour, from.Minute, from.Second);
            stop.To = new DateTime(vm.Day.Value.Year, vm.Day.Value.Month, vm.Day.Value.Day, to.Hour, to.Minute, to.Second);
            stop.LastModifiedOn = DateTime.Now;

            var truck = truckService.GetTruckByUrl(truckurlslug);
            stop.FoodTruckId = truck.Id;
            schedService.CreateStop(stop);

            return RedirectToAction("Index", "Schedule", new { @name = truckurlslug });
        }
예제 #3
0
        public ActionResult Edit(ScheduledStopEditViewModel vm, int id)
        {
            var stop = schedService.GetStop(id);

            DateTime from;
            DateTime to;
            DateTime.TryParseExact(vm.SelectedFrom, @"h\:mm tt", CultureInfo.CurrentCulture, DateTimeStyles.None, out from);
            DateTime.TryParseExact(vm.SelectedTo, @"h\:mm tt", CultureInfo.CurrentCulture, DateTimeStyles.None, out to);
            if (!vm.Recurring && stop.Recurring)
            {

                var newStop = new ScheduledStop();
                newStop = mapper.Map<ScheduledStop>(vm);
                newStop.FoodTruckId = stop.FoodTruckId;
                newStop.From = new DateTime(vm.Day.Value.Year, vm.Day.Value.Month, vm.Day.Value.Day, from.Hour, from.Minute, from.Second);
                newStop.To = new DateTime(vm.Day.Value.Year, vm.Day.Value.Month, vm.Day.Value.Day, to.Hour, to.Minute, to.Second);
                newStop.LastModifiedOn = DateTime.Now;
                newStop.Recurring = false;
                //create the 'new' stop
                schedService.CreateStop(newStop);
                //update the existing recurring stop with the exception
                schedService.CreateStopException(newStop.From, stop.Id);
            }
            else
            {
                stop.LocationId = vm.LocationId;
                stop.Recurring = vm.Recurring;
                stop.RecurringStart = vm.RecurringStart;
                stop.HasRecurringEnd = vm.HasRecurringEnd;
                stop.RecurringEnd = vm.RecurringEnd;
                stop.From = new DateTime(vm.Day.Value.Year, vm.Day.Value.Month, vm.Day.Value.Day, from.Hour, from.Minute, from.Second);
                stop.To = new DateTime(vm.Day.Value.Year, vm.Day.Value.Month, vm.Day.Value.Day, to.Hour, to.Minute, to.Second);
                stop.LastModifiedOn = DateTime.Now;
                schedService.EditStop(stop);
            }

            return RedirectToAction("Index", "Schedule", new { @name = stop.FoodTruck.UrlSlug });
        }