public Model.AiringDaysOfCinema Insert(Model.Requests.InserAiringDayOfCinemaRequest ad) { bool validCinemaId = false; foreach (var cinema in _context.Cinemas.ToList()) { if (ad.CinemaId == cinema.CinemaId) { validCinemaId = true; break; } } if (!validCinemaId) { throw new UserException("Could not find sepcified cinemaId!"); } var baseAd = _mapper.Map <Database.AiringDaysOfCinema>(ad); var day = baseAd.Date.DayOfWeek; var days = _context.AiringDays.ToList(); foreach (var airingDay in days) { if (airingDay.Name == day.ToString()) { baseAd.AiringDayId = airingDay.AiringDayId; break; } } _context.AiringDaysOfCinema.Add(baseAd); _context.SaveChanges(); return(_mapper.Map <Model.AiringDaysOfCinema>(baseAd)); }
private async void saveBtn_Click(object sender, EventArgs e) { var daysApi = new APIService("AiringDaysOfCinema"); var messageBox = new CustomMessageBox(); var allDays = await daysApi.Get <List <Model.AiringDaysOfCinema> >(null); foreach (var day in allDays) { if (day.Date.Date == datePicker.Value.Date && day.CinemaId == _schedule.Cinema.CinemaId) { messageBox.Show("Day already generated!", "error"); return; } } var Object = new Model.Requests.InserAiringDayOfCinemaRequest() { Date = datePicker.Value, CinemaId = _schedule.Cinema.CinemaId }; if (_airingDayId.HasValue) { await _apiService.Update <Model.AiringDaysOfCinema>(_airingDayId, Object); messageBox.Show("Airing day updated successfully", "success"); } else { await _apiService.Insert <Model.AiringDaysOfCinema>(Object); messageBox.Show("Airing day added successfully", "success"); } this.Close(); _scheduleForm.Close(); ScheduleForm form = new ScheduleForm(_schedule.Cinema.CinemaId, _menuForm) { MdiParent = _menuForm, Dock = DockStyle.Fill }; form.Show(); }
public ActionResult <Model.AiringDaysOfCinema> UpdateAiringDay(int airingDayId, Model.Requests.InserAiringDayOfCinemaRequest ad) { return(_service.Update(airingDayId, ad)); }
public ActionResult <Model.AiringDaysOfCinema> AddAiringDayToCinema(Model.Requests.InserAiringDayOfCinemaRequest ad) { return(_service.Insert(ad)); }
public Model.AiringDaysOfCinema Update(int airingDayId, Model.Requests.InserAiringDayOfCinemaRequest ad) { bool validAiringDayId = false; foreach (var inDay in _context.AiringDaysOfCinema.ToList()) { if (airingDayId == inDay.AiringDaysOfCinemaId) { validAiringDayId = true; break; } } if (!validAiringDayId) { throw new UserException("Cannot find specified day with that airingDaysOfCinemaId!"); } bool validCinemaId = false; foreach (var cinema in _context.Cinemas.ToList()) { if (ad.CinemaId == cinema.CinemaId) { validCinemaId = true; break; } } if (!validCinemaId) { throw new UserException("Invalid cinemaId inside of airing day of cinema!"); } var baseAd = _context.AiringDaysOfCinema.Find(airingDayId); var oldDate = baseAd.Date.Date; baseAd.Date = ad.Date; var day = ad.Date.DayOfWeek; var days = _context.AiringDays.ToList(); foreach (var airingDay in days) { if (airingDay.Name == day.ToString()) { baseAd.AiringDayId = airingDay.AiringDayId; break; } } _context.SaveChanges(); var cdms = _context.CinemaDayMovie.Where(c => c.AiringDaysOfCinemaId == baseAd.AiringDaysOfCinemaId).ToList(); var list = new List <Database.Appointments>(); foreach (var cdm in cdms) { foreach (var app in _context.Appointments.ToList()) { if (app.CinemaDayMovieId == cdm.CinemaDayMovieId) { list.Add(app); } } } Helper helper = new Helper(_context); helper.NonDeleteNotification(list, $"Orders from the {oldDate} have been changed to the {baseAd.Date.Date}", "Warning"); return(_mapper.Map <Model.AiringDaysOfCinema>(baseAd)); }