public async Task <IActionResult> UpdateAsync(Hall hallIn) { hallIn.Id.ValidateId(); var hall = await _hallsRepository.GetAsync(hallIn.Id); if (hall == null) { return(NotFound()); } try { await _hallsRepository.UpdateAsync(hallIn.Id, hallIn); } catch (Exception) { throw new Error(Errors.Update_error, $"Can not update record {hall}"); } return(NoContent()); }
public async Task <HallDTO> GetAsync(HttpRequest request, string id) { // Get language from header StringValues language = LanguageConstants.LanguageDefault; request?.Headers?.TryGetValue("Accept-Language", out language); var hall = await _hallsRepository.GetAsync(id); MapperConfiguration mapperConfiguration = null; HallDTO hallDTO = null; if (hall != null) { // Create mapping depending on language switch (language) { case LanguageConstants.LanguageRu: mapperConfiguration = HallsMappingConfigurations.GetRuConfiguration; break; case LanguageConstants.LanguageEn: mapperConfiguration = HallsMappingConfigurations.GetEnConfiguration; break; case LanguageConstants.LanguageBy: mapperConfiguration = HallsMappingConfigurations.GetByConfiguration; break; default: mapperConfiguration = HallsMappingConfigurations.GetEnConfiguration; break; } var mapper = new Mapper(mapperConfiguration); hallDTO = mapper.Map <HallDTO>(hall); var stands = await _standsService.GetAllAsync(request, id); hallDTO.Stands = stands; } return(hallDTO); }
public async Task <Schedule> GenerateScheduleAsync(EntityId id, CinemaId cinemaId, MovieId movieId, DateTime from, DateTime to, int ageRestriction) { var schema = await _scheduleSchemasRepository.GetAsync(cinemaId); if (schema is null) { throw new ScheduleSchemaNotFoundException(cinemaId); } var times = schema.Times .Where(h => h.ageRestriction <= ageRestriction) .Select(h => h.times) .FirstOrDefault(); if (times is null) { throw new MissingScheduleTimesException(cinemaId, ageRestriction); } var schedules = await _schedulesRepository.GetAsync(); var schedule = Schedule.Create(id, cinemaId, movieId); var shows = schedules.SelectMany(s => s.Shows); var dates = Enumerable.Range(0, 1 + to.Subtract(from).Days) .Select(offset => from.AddDays(offset)) .ToList(); var halls = await _hallsRepository.GetAsync(cinemaId); var generatedShows = dates.SelectMany(d => GenerateShowsForDay(d, movieId, shows.ToList(), times.ToList(), halls.ToList())); schedule.AddShows(generatedShows); return(schedule); }
public async Task <PartialViewResult> Index(string id) { return(PartialView("~/Views/Shared/Halls/_Index.cshtml", await _hallsRepository.GetAsync(id))); }