public async Task <IActionResult> OnPostDelete(string id)
        {
            var guid = Guid.Parse(id);

            var result = await bookingDataService.DeleteBooking(guid);

            return(new RedirectToPageResult("BookingOverViewAdmin"));
        }
        public async Task <IActionResult> OnPostDelete(string id)
        {
            var result = await _bookingDataService.DeleteBooking(Guid.Parse(id));

            if (!result.IsSuccesfull)
            {
                return(new RedirectToPageResult("Error"));
            }
            return(new RedirectToPageResult("BookingOverviewAdmin"));
        }
示例#3
0
        public async Task <IActionResult> OnPostUpdate(List <NewIntervalViewModel> NewIntervals,
                                                       List <IntervalViewModel> intervals, List <string> day, string nameOfPlan, Shift shift,
                                                       DateTime NewScheduleDate, Guid CurrentScheduleId, Guid CreatedBy)
        {
            var currentSchedule = await _scheduleDataService.GetScheduleById(CurrentScheduleId);



            List <BookingViewModel> NotToBeDeleted = new List <BookingViewModel>();
            var createCommand = new CreateScheduleFromActiveSchedule();

            createCommand.Name                  = nameOfPlan;
            createCommand.Shifts                = shift;
            createCommand.IsStandard            = false;
            createCommand.ScheduleDay           = NewScheduleDate;
            createCommand.MischellaneousPallets = 0;
            createCommand.CreatedBy             = CreatedBy;

            var scheduleId = currentSchedule.ScheduleId;

            createCommand.ScheduleId = scheduleId;

            createCommand.ActiveDays = SetDayViewModel(day);

            var intervall = new List <IntervalViewModel>();

            foreach (var interval in intervals)
            {
                if (interval.EndTime.Value.TimeOfDay != TimeSpan.Zero ||
                    interval.StartTime.Value.TimeOfDay != TimeSpan.Zero)
                {
                    var sameInterval = currentSchedule.Intervals.FirstOrDefault(e =>
                                                                                e.EndTime.Value.TimeOfDay.CompareTo(interval.EndTime.Value.TimeOfDay) == 0 &&
                                                                                e.StartTime.Value.TimeOfDay.CompareTo(interval.StartTime.Value.TimeOfDay) == 0);

                    if (sameInterval != null)
                    {
                        intervall.Add(sameInterval);
                        NotToBeDeleted.AddRange(sameInterval.Bookings);
                    }
                    else
                    {
                        intervall.Add(new IntervalViewModel
                        {
                            Bookings         = new List <BookingViewModel>(),
                            BottomPallets    = interval.BottomPallets,
                            EndTime          = CreateDate(NewScheduleDate, interval.EndTime.Value.TimeOfDay),
                            StartTime        = CreateDate(NewScheduleDate, interval.StartTime.Value.TimeOfDay),
                            IntervalId       = Guid.NewGuid(),
                            IsBooked         = false,
                            RemainingPallets = interval.BottomPallets,
                            ScheduleId       = scheduleId
                        });
                    }
                }
            }

            foreach (var newInterval in NewIntervals)
            {
                if (newInterval.End != TimeSpan.Zero ||
                    newInterval.Start != TimeSpan.Zero)
                {
                    var sameInterval = currentSchedule.Intervals.FirstOrDefault(e =>
                                                                                e.EndTime.Value.TimeOfDay.CompareTo(newInterval.End) == 0 &&
                                                                                e.StartTime.Value.TimeOfDay.CompareTo(newInterval.Start) == 0);

                    if (sameInterval != null)
                    {
                        intervall.Add(sameInterval);
                        NotToBeDeleted.AddRange(sameInterval.Bookings);
                    }
                    else
                    {
                        intervall.Add(new IntervalViewModel
                        {
                            Bookings         = new List <BookingViewModel>(),
                            BottomPallets    = newInterval.Pallets,
                            EndTime          = CreateDate(NewScheduleDate, newInterval.End),
                            StartTime        = CreateDate(NewScheduleDate, newInterval.End),
                            IntervalId       = Guid.NewGuid(),
                            IsBooked         = false,
                            RemainingPallets = newInterval.Pallets,
                            ScheduleId       = scheduleId
                        });
                    }
                }
            }



            List <BookingViewModel> bookingToBeDeleted = new List <BookingViewModel>();

            foreach (var interval in currentSchedule.Intervals)
            {
                foreach (var booking in interval.Bookings)
                {
                    var notDeleted = NotToBeDeleted.FirstOrDefault(e => e.InternalId == booking.InternalId);
                    if (notDeleted == null)
                    {
                        bookingToBeDeleted.Add(booking);
                    }
                }
            }

            foreach (var booking in bookingToBeDeleted)
            {
                var bookingResult = await _bookingDataService.DeleteBooking(booking.InternalId);

                Console.WriteLine(bookingResult);
            }

            List <IntervalViewModel> sorted = intervall.OrderBy(e => e.StartTime).ToList();

            createCommand.IntervalViewModels = sorted;
            var result = await _scheduleDataService.CreateScheduleFromSchedule(createCommand);

            if (result.IsSuccesfull)
            {
                return(new RedirectToPageResult("CalendarOverview"));
            }

            return(new RedirectToPageResult("CalendarOverview"));
        }