public IHttpActionResult AllReservations() { try { BLReservations reservations = new BLReservations(); var reservation_list = reservations.All(); ReservationsVM obj = new ReservationsVM(); return(Ok(obj.CreateList(reservation_list))); } catch (Exception ex) { return(InternalServerError(ex)); } }
public IHttpActionResult ReservationDetail(string start_date, string end_date, string username) { try { BLReservations reservations = new BLReservations(); var reservation_list = reservations.GetDetail(start_date, end_date, username); ReservationsVM obj = new ReservationsVM(); return(Ok(obj.CreateList(reservation_list))); } catch (Exception ex) { return(InternalServerError(ex)); } }
private async Task <ReservationsVM> PopulateReservationsVM(int?guestId = -1, int?roomReservationId = -1) { var guest = await _db.Guests.SingleOrDefaultAsync(g => g.Id == guestId); var reservationDetails = await _db.ReservationDetails.Where(rd => rd.RoomReservationId == roomReservationId) .OrderBy(r => r.CheckInDate).ToListAsync(); var roomReservations = await _db.RoomReservations.SingleOrDefaultAsync(r => r.Id == roomReservationId); var vacantRooms = await GetVacantRooms(); var reservationsVM = new ReservationsVM { Rooms = vacantRooms != null ? vacantRooms : new List <Room>(), Guest = guest != null ? guest : new Guest(), ReservationDetails = reservationDetails != null ? reservationDetails : new List <ReservationDetail>(), RoomReservations = roomReservations != null ? roomReservations : new RoomReservation() }; return(reservationsVM); }
public async Task <IActionResult> ReservationsTicketPhilharmonics(int Id, string date) { var dateEvent = DateTime.Parse(date); var user = await db.Users.FirstOrDefaultAsync(u => u.Id == UserId); var SeansEvent = await db.seanses.FirstOrDefaultAsync(c => c.ConcertId == Id && c.Date == dateEvent); var concert = await db.concerts.FirstOrDefaultAsync(n => n.Id == Id); var location = await db.locations.FirstOrDefaultAsync(t => t.Id == concert.LocationId); var SeansesReservations = db.reservations.Where(n => n.SeanseId == SeansEvent.Id); List <int> seatsReservation = new List <int>() { }; foreach (var item in SeansesReservations) { seatsReservation.Add(item.SeatReservation); } var viewModel = new ReservationsVM { Id = concert.Id, Title = concert.TitleConcert, BeginPriceTicket = concert.PriceTicket, Seatreservations = seatsReservation, Date = dateEvent, TotalSeats = location.TotalSeats, UserName = user.UserName }; return(View(viewModel)); }
public async Task <IActionResult> ReservationsTicketPhilharmonics(ReservationsVM reservations, List <int> orderNumbers, string date, string title) { var dateEvent = DateTime.Parse(date); var seans = await db.seanses.FirstOrDefaultAsync(x => x.ConcertId == reservations.Id && x.Date == dateEvent); var reservationss = await db.reservations.FirstOrDefaultAsync(g => g.SeanseId == seans.Id && g.UserId == UserId); var concert = db.concerts.FirstOrDefault(p => p.Id == reservations.Id); string guid = Guid.NewGuid().ToString(); if (reservationss != null) { guid = reservationss.Guid; } if (orderNumbers.Count != 0) { using (var transaction = await db.Database.BeginTransactionAsync()) { for (int i = 0; i < orderNumbers.Count; i++) { int price = 0; if (orderNumbers[i] <= 19) { price = concert.PriceTicket + 400; } if (orderNumbers[i] >= 20 && orderNumbers[i] <= 39) { price = concert.PriceTicket + 300; } if (orderNumbers[i] >= 40 && orderNumbers[i] <= 59) { price = concert.PriceTicket + 200; } if (orderNumbers[i] >= 60 && orderNumbers[i] <= 79) { price = concert.PriceTicket + 100; } if (orderNumbers[i] >= 80 && orderNumbers[i] <= 99) { price = concert.PriceTicket; } await db.reservations.AddAsync(new Reservation { SeanseId = seans.Id, UserId = UserId, SeatReservation = orderNumbers[i], Guid = guid.ToString(), Price = price, Status = 0 }); } await db.SaveChangesAsync(); await transaction.CommitAsync(); var user = await db.Users.FirstOrDefaultAsync(u => u.Id == UserId); MimeMessage message = new MimeMessage(); message.From.Add(new MailboxAddress("Afisha", "")); message.To.Add(new MailboxAddress($"{user.UserName}")); message.Subject = "Уведомление от Afisha!"; message.Body = new BodyBuilder() { HtmlBody = $"<h1 style=\"color: green;\">Good day {user.Name} {user.Surname}! On {date} a concert will take place {title}, do not forget! Your hashcode {guid}." }.ToMessageBody(); using (MailKit.Net.Smtp.SmtpClient client = new MailKit.Net.Smtp.SmtpClient()) { client.Connect("smtp.gmail.com", 465, true); client.Authenticate("*****@*****.**", "Afisha01"); client.Send(message); client.Disconnect(true); } TempData["SuccessNotification"] = $" The letter has been sent to your mail. You have booked successfully!"; return(RedirectToAction("ReservationsTicketPhilharmonics", new { date = date })); } } TempData["ErrorMessage"] = $"You have not selected a seat for booking"; return(RedirectToAction("ReservationsTicketPhilharmonics", new { date = date })); }