// GET: Reservation/Details/5 public ActionResult Details(short?id) { if (Session["USER_LOGIN"] != null) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RESERVATIONS rESERVATIONS = db.RESERVATIONS.Find(id); if (rESERVATIONS == null) { return(HttpNotFound()); } var RDetails = db.RESERVATIONS_DETAILS.Where(r => r.ID_RESERVATION == id).ToList(); Dictionary <string, TICKETS> seat_ticket = new Dictionary <string, TICKETS>(); foreach (var item in RDetails) { seat_ticket.Add(item.ID_SEAT, item.TICKETS); } ViewBag.RDetails = seat_ticket; return(View(rESERVATIONS)); } else { return(RedirectToAction("", "Home")); } }
public void Save(Reservation entity) { var reservation = _dbContext.Reservations.Find(entity.Id.Value); if (reservation == null) { reservation = new RESERVATIONS(); _dbContext.Reservations.Add(reservation); } reservation.id = entity.Id.Value; reservation.accounts_id = entity.AccountId.Value; reservation.equipments_id = entity.EquipmentId.Value; reservation.start_date_time = entity.ReservationDateTime.Start; reservation.end_date_time = entity.ReservationDateTime.End; reservation.purpose_of_use = entity.PurposeOfUse.Value; var reservationStatus = _dbContext.ReservationsStatus.Find(reservation.id); if (reservationStatus == null) { reservationStatus = new RESERVATIONS_STATUS(); _dbContext.ReservationsStatus.Add(reservationStatus); } reservationStatus.reservations_id = reservation.id; reservationStatus.status = (int)entity.ReservationStatus; _dbContext.SaveChanges(); }
// GET: Reservation/Delete/5 public ActionResult Delete(short?id) { if (Session["USER_LOGIN"] != null) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } RESERVATIONS rESERVATIONS = db.RESERVATIONS.Find(id); if (rESERVATIONS == null) { return(HttpNotFound()); } var RDetails = db.RESERVATIONS_DETAILS.Where(r => r.ID_RESERVATION == id).ToList(); Dictionary <string, string> seatTicket = new Dictionary <string, string>(); foreach (var item in RDetails) { seatTicket.Add(item.ID_SEAT, db.TICKETS.Where(x => x.ID_TICKET == item.ID_TICKET).Select(x => x.TYPE).FirstOrDefault()); } Session["seatTicket"] = seatTicket; return(View(rESERVATIONS)); } else { return(RedirectToAction("", "Home")); } }
public ActionResult DeleteConfirmed(short id) { if (Session["USER_LOGIN"] != null) { RESERVATIONS rESERVATIONS = db.RESERVATIONS.Find(id); db.RESERVATIONS.Remove(rESERVATIONS); db.SaveChanges(); } Session["seatTicket"] = null; return(RedirectToAction("Index")); }
private Reservation Create(RESERVATIONS reservation) { if (reservation == null) { return(null); } return(new Reservation( new ReservationId(reservation.id), new AccountId(reservation.accounts_id), new EquipmentId(reservation.equipments_id), new ReservationDateTime(reservation.start_date_time, reservation.end_date_time), new PurposeOfUse(reservation.purpose_of_use), (ReservationStatus)reservation.reservations_status.status)); }
private ReservationData CreateReservationData(RESERVATIONS reservation) { if (reservation == null) { return(null); } return(new ReservationData() { Id = reservation.id, AccountId = reservation.accounts.id, EquipmentId = reservation.equipments_id, StartDateTime = reservation.start_date_time, EndDateTime = reservation.end_date_time, PurposeOfUse = reservation.purpose_of_use, }); }
public IHttpActionResult Postreservations(List <ReservationBindingModel> Reservations) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } string UID = User.Identity.GetUserId(); for (int i = 0; i < Reservations.Count; i++) { RESERVATIONS res = new RESERVATIONS { ID_SCREENING = Reservations[i].ID_SCREENING, ID_SEAT = Reservations[i].ID_SEAT, RESERVATION_DATE = Reservations[i].RESERVATION_DATE, IS_REDUCED = Reservations[i].IS_REDUCED, ID_USER = UID }; _unitOfWork.ReservationsRepository.Insert(res); } if (TheyTookYourPlace(Reservations, Reservations[0].ID_SCREENING)) { return(BadRequest("Seats are already reserved, refresh the page and try again")); } try { _unitOfWork.Save(); } catch (DbUpdateException) { return(BadRequest("Cannot reserve the reservation, reserve later")); } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator."); } return(Ok()); }
public ActionResult SummaryReservation(short?id) { if (Session["USER_LOGIN"] != null) { if (id == -1) //uzytkownik dokonuje nowej rezerwacji { RESERVATIONS rESERVATIONS = new RESERVATIONS(); string dateTimeHall = Session["DateTimeHall"].ToString(); string[] date_time_hall_Array = dateTimeHall.Split(' ');//3 -hall string[] date = date_time_hall_Array[0].Split('-'); //year, month, day DateTime YearMonthDay = new DateTime(Int32.Parse(date[0]), Int32.Parse(date[1]), Int32.Parse(date[2])); //hour, minutes, seconds string[] time = date_time_hall_Array[1].Split(':'); TimeSpan HourMinutesSeconds = new TimeSpan(Int32.Parse(time[0]), Int32.Parse(time[1]), Int32.Parse(time[2])); string Hallid = date_time_hall_Array[3]; //ID_Program var idProgram = db.PROGRAM.Where (x => x.DATE == YearMonthDay && x.TIME == HourMinutesSeconds && x.ID_HALL == Hallid).Select(x => x.ID_PROGRAM).FirstOrDefault(); //rESERVATIONS.ID_RESERVATION= string userLogin = Session["USER_LOGIN"].ToString(); rESERVATIONS.ID_PROGRAM = idProgram; rESERVATIONS.USER_LOGIN = userLogin; db.RESERVATIONS.Add(rESERVATIONS); db.SaveChanges(); //id_reser | id_seat |id_ticket RESERVATIONS_DETAILS rESERVATIONS_DETAILS; var idReservation = rESERVATIONS.ID_RESERVATION; Dictionary <string, string> seatTicket = (Dictionary <string, string>)Session["seatTicket"]; //pair.Value - rodzaj biletu //pair.Key - miejsce foreach (KeyValuePair <string, string> pair in seatTicket) { rESERVATIONS_DETAILS = new RESERVATIONS_DETAILS(); rESERVATIONS_DETAILS.ID_RESERVATION = idReservation; if (pair.Key.Contains("VIP")) { rESERVATIONS_DETAILS.ID_SEAT = pair.Key.Remove(pair.Key.Length - 4); } else { rESERVATIONS_DETAILS.ID_SEAT = pair.Key; } rESERVATIONS_DETAILS.ID_TICKET = db.TICKETS.Where(x => x.TYPE == pair.Value).Select(x => x.ID_TICKET).FirstOrDefault(); db.RESERVATIONS_DETAILS.Add(rESERVATIONS_DETAILS); } } else //uzytkownik ma rezerwacje { List <RESERVATIONS_DETAILS> rESERVATIONS_DETAILS_List = db.RESERVATIONS_DETAILS.Where(x => x.ID_RESERVATION == id).ToList(); //zwraca wszystkie rezerwacje o ID==id uzytkownika Dictionary <string, string> seatTicket = (Dictionary <string, string>)Session["seatTicket"]; //siedzenia i bilety, ktore wybrał uzytkownik //1. Skasowanie pozycji z RESERVATIONS_DETAILS o id przeslanym w argumencie metody foreach (var item in rESERVATIONS_DETAILS_List) { db.RESERVATIONS_DETAILS.Remove(item); } db.SaveChanges(); RESERVATIONS_DETAILS rESERVATIONS_DETAILS; //2. Dodanie do bazy poprawnych pozycji z listy foreach (KeyValuePair <string, string> pair in seatTicket) { rESERVATIONS_DETAILS = new RESERVATIONS_DETAILS(); rESERVATIONS_DETAILS.ID_RESERVATION = id.Value; if (pair.Key.Contains("VIP")) { rESERVATIONS_DETAILS.ID_SEAT = pair.Key.Remove(pair.Key.Length - 4); } else { rESERVATIONS_DETAILS.ID_SEAT = pair.Key; } rESERVATIONS_DETAILS.ID_TICKET = db.TICKETS.Where(x => x.TYPE == pair.Value).Select(x => x.ID_TICKET).FirstOrDefault(); db.RESERVATIONS_DETAILS.Add(rESERVATIONS_DETAILS); } } Session["mTitle"] = null; Session["DateTimeHall"] = null; Session["seatTicket"] = null; db.SaveChanges(); } return(RedirectToAction("Index")); }
public void Initialize(MyDbContext dbContext) { if (dbContext.Accounts.Count() > 0) { return; } var accounts = new List <ACCOUNTS>(); accounts.Add(new ACCOUNTS() { id = new EquipmentReservation.Domain.Accounts.AccountId().Value, account_name = "アカウント1" }); accounts.Add(new ACCOUNTS() { id = new EquipmentReservation.Domain.Accounts.AccountId().Value, account_name = "アカウント2" }); accounts.Add(new ACCOUNTS() { id = new EquipmentReservation.Domain.Accounts.AccountId().Value, account_name = "アカウント3" }); dbContext.AddRange(accounts); var equipments = new List <EQUIPMENTS>(); equipments.Add(new EQUIPMENTS() { id = new EquipmentReservation.Domain.Equipments.EquipmentId().Value, equipment_type = (int)EquipmentReservation.Domain.Equipments.EquipmentTypes.USB, equipment_name = "USB1" }); equipments.Add(new EQUIPMENTS() { id = new EquipmentReservation.Domain.Equipments.EquipmentId().Value, equipment_type = (int)EquipmentReservation.Domain.Equipments.EquipmentTypes.PocketWifi, equipment_name = "ポケットWifi1" }); equipments.Add(new EQUIPMENTS() { id = new EquipmentReservation.Domain.Equipments.EquipmentId().Value, equipment_type = (int)EquipmentReservation.Domain.Equipments.EquipmentTypes.CellPhone, equipment_name = "携帯電話1" }); dbContext.AddRange(equipments); var additionalDay = 1; var startDateTime = DateTime.Now; foreach (var account in accounts) { foreach (var equipment in equipments) { var reservation = new RESERVATIONS() { id = new EquipmentReservation.Domain.Reservations.ReservationId().Value, accounts_id = account.id, equipments_id = equipment.id, start_date_time = startDateTime.AddDays(additionalDay), end_date_time = startDateTime.AddDays(additionalDay + 1), purpose_of_use = "テスト" }; dbContext.Add(reservation); var reservationsStatus = new RESERVATIONS_STATUS() { reservations_id = reservation.id, status = 0 }; dbContext.Add(reservationsStatus); additionalDay++; } } dbContext.SaveChanges(); }