public Model.Hall Insert(Model.Requests.InsertHallRequest h) { bool validCinemaId = false; foreach (var cinema in _context.Cinemas.ToList()) { if (h.CinemaId == cinema.CinemaId) { validCinemaId = true; break; } } if (!validCinemaId) { throw new UserException("Could not find sepcified cinemaId!"); } var hall = _mapper.Map <Database.Hall>(h); var inBaseHalls = _context.Hall.Where(ha => ha.CinemaId == h.CinemaId).ToList(); foreach (var inHall in inBaseHalls) { if (inHall.HallName.ToLower() == hall.HallName.ToLower() && inHall.HallNumber == hall.HallNumber && hall.NumberOfseats == inHall.NumberOfseats && hall.CinemaId == inHall.CinemaId) { return(_mapper.Map <Model.Hall>(hall)); } } _context.Hall.Add(hall); _context.SaveChanges(); return(_mapper.Map <Model.Hall>(hall)); }
public Model.Hall Update(int hallId, Model.Requests.InsertHallRequest hall) { bool validHallId = false; foreach (var inHall in _context.Hall.ToList()) { if (hallId == inHall.HallId) { validHallId = true; break; } } if (!validHallId) { throw new UserException("Cannot find specified Hall with that hallId!"); } var baseHall = _context.Hall.Find(hallId); bool validCinemaId = false; foreach (var cinema in _context.Cinemas.ToList()) { if (hall.CinemaId == cinema.CinemaId) { validCinemaId = true; break; } } if (!validCinemaId) { throw new UserException("Invalid cinemaId inside of hall!"); } var oldName = baseHall.HallName; baseHall.HallName = hall.HallName; baseHall.HallNumber = hall.HallNumber; baseHall.NumberOfseats = hall.NumberOfseats; _context.SaveChanges(); var list = _context.Appointments.Where(a => a.HallId == baseHall.HallId).ToList(); var helper = new Helper(_context); helper.NonDeleteNotification(list, $"The hall '{oldName}' was renamed to '{baseHall.HallName}'!", "Information"); return(_mapper.Map <Model.Hall>(baseHall)); }
public ActionResult <Model.Hall> Update(int hallId, Model.Requests.InsertHallRequest hall) { return(_service.Update(hallId, hall)); }
private async void saveBtn_Click(object sender, EventArgs e) { var messageBox = new CustomMessageBox(); if (string.IsNullOrWhiteSpace(HallName.Text) || HallName.Text.Length < 4) { messageBox.Show("The hall name field requires 4 letters!", "error"); return; } if (HallNumber.Value < 1 || HallNumber.Value > 100) { messageBox.Show("Enter a valid hall number (1-100)!", "error"); return; } if (HallSeats.Value < 1 || HallSeats.Value > 100) { messageBox.Show("Enter valid seats (1-100)!", "error"); return; } Model.Requests.InsertHallRequest hall = new Model.Requests.InsertHallRequest() { HallName = HallName.Text, HallNumber = (int)HallNumber.Value, NumberOfseats = (int)HallSeats.Value, CinemaId = _cinemaId }; if (_hallId.HasValue) { await _apiService.Update <Model.Hall>(_hallId, hall); messageBox.Show("Hall updated succesfully", "Success"); } else { await _apiService.Insert <Model.Hall>(hall); messageBox.Show("Hall added succesfully", "Success"); } CinemasHallsForm form = new CinemasHallsForm(_menuForm, _cinemaId, _cinemaName, _cinemaLocation); _cinemasHallsForm.Close(); while (this.Opacity > 0.0) { await Task.Delay(15); this.Opacity -= 0.05; } this.Opacity = 0; this.Close(); form.Show(); form.Opacity = 0; while (form.Opacity < 1.0) { await Task.Delay(15); form.Opacity += 0.05; } form.Opacity = 1; }
public ActionResult <Model.Hall> Inesrt(Model.Requests.InsertHallRequest hall) { return(_service.Insert(hall)); }