public async Task CancelReservation(CancelReservationModel model)
        {
            var userId = _httpContextAccessor.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            Reservation reservation = await _dbContext.Reservations
                                      .Where(rs => rs.UserId == userId && rs.TicketId == model.TicketId)
                                      .FirstOrDefaultAsync();

            Ticket ticket = await _dbContext.Tickets
                            .Where(t => t.Id == model.TicketId)
                            .FirstOrDefaultAsync();

            AvailableSeat availableSeat = new AvailableSeat
            {
                ProjectionId = model.ProjectionId,
                SeatId       = model.SeatId
            };

            CinemaCreditCard card = await _dbContext.CinemaCreditCards
                                    .Where(u => u.UserId == userId)
                                    .FirstOrDefaultAsync();

            card.Balance = card.Balance + 7;

            _dbContext.Reservations.Remove(reservation);
            _dbContext.Tickets.Remove(ticket);
            _dbContext.AvailableSeats.Add(availableSeat);
            await _dbContext.SaveChangesAsync();
        }
        public ActionResult CancelBooking(int Id)
        {
            var booking = _reservationService.GetReservation(Id);
            CancelReservationModel reservation = new CancelReservationModel()
            {
                Email     = booking.Email,
                Message   = "Hej " + booking.Name + "!\n\rDin bokning för " + booking.PersonCount + " personer på " + booking.Restaurant.Name + " den " + booking.TimeSlot.ToShortDateString() + " kl " + booking.TimeSlot.ToLocalTime().ToShortTimeString() + " har blivit inställd\n\n\rMed vänlig hälsning " + booking.Restaurant.Name,
                SendMail  = false,
                BookingId = Id
            };

            return(View(reservation));
        }
        public ActionResult CancelBooking(CancelReservationModel model, string submitButton)
        {
            if (submitButton == "Avbryt")
            {
                return(View("Index"));
            }
            var booking = _reservationService.GetReservation(model.BookingId);

            _reservationService.DeleteReservation(booking);
            if (model.SendMail)
            {
                dynamic email = new Email("CancelBookingEmail");
                email.To      = model.Email;
                email.Message = model.Message;
                email.Send();
            }
            return(View("BookingCanceled"));
        }
Esempio n. 4
0
        public IActionResult CancelReservation(CancelReservationModel model)
        {
            if (model == null || !ModelState.IsValid)
            {
                TempData["Message"] = "Dados de reserva de turno inválidos.";
                return(RedirectToScheduleList());
            }

            var slot = db.ScheduleSlots
                       .Include(sl => sl.Students)
                       .Include(sl => sl.Schedule)
                       .FirstOrDefault(sl => sl.Id == model.SlotId.Value);

            if (slot == null)
            {
                TempData["Message"] = "O turno especificado não existe.";
                return(RedirectToScheduleDetails(model.ScheduleId.Value));
            }

            if (slot.Schedule.When < DateTime.Now.Date)
            {
                TempData["Message"] = "Este horário está fechado.";
                return(RedirectToScheduleDetails(model.ScheduleId.Value));
            }

            var studentNumber = User.GetStudentNumber();

            if (slot.ReservedBy_Id != studentNumber)
            {
                TempData["Message"] = "Só pode cancelar turnos reservados por si.";
                return(RedirectToScheduleDetails(model.ScheduleId.Value));
            }

            slot.ReservedBy_Id = null;
            slot.ReservedAt    = null;
            slot.Students.Clear();

            db.ScheduleSlots.Update(slot);

            db.SaveChanges();

            return(RedirectToScheduleDetails(model.ScheduleId.Value));
        }
Esempio n. 5
0
        public async Task <IActionResult> CancelReservation(CancelReservationModel model)
        {
            await _reservationsRepository.CancelReservation(model);

            return(View("CancelReservation"));
        }