Esempio n. 1
0
        public async Task <IActionResult> UpdateAsync(string hallId, string standId, Exhibit exhibitIn)
        {
            exhibitIn.Id.ValidateId();
            hallId.ValidateId();
            standId.ValidateId();

            var exhibit = await _exhibitsRepository.GetAsync(hallId, standId, exhibitIn.Id);

            if (exhibit == null)
            {
                return(NotFound());
            }

            try
            {
                await _exhibitsRepository.UpdateAsync(hallId, standId, exhibitIn.Id, exhibitIn);
            }
            catch (Exception)
            {
                throw new Error(Errors.Update_error, $"Can not update record {exhibit}");
            }
            return(NoContent());
        }
Esempio n. 2
0
        public async Task <ExhibitViewModel> EditArticleAsync(string hallId, string standId, ExhibitViewModel exhibit, IEnumerable <IFormFile> files, IEnumerable <string> ids)
        {
            var initialExhibit = await _exhibitsRepository.GetAsync(hallId, standId, exhibit.Id);

            if (initialExhibit.Photos != null)
            {
                exhibit.Photos = initialExhibit.Photos;
                foreach (var photo in exhibit.Photos)
                {
                    if (!ids.Contains(photo?.Id))
                    {
                        photo.Photo = null;
                    }
                }
            }

            if (files.Count() != 0)
            {
                await _formFileToByteConverterService.ConvertAsync(files, exhibit);
            }

            return(exhibit);
        }
Esempio n. 3
0
        public async Task <ExhibitDTO> GetAsync(HttpRequest request, string hallId, string standId, string id)
        {
            // Get language from header
            StringValues language = LanguageConstants.LanguageDefault;

            request?.Headers?.TryGetValue("Accept-Language", out language);

            var exhibit = await _exhibitsRepository.GetAsync(hallId, standId, id);

            MapperConfiguration mapperConfiguration      = null;
            MapperConfiguration mapperConfigurationPhoto = null;

            ExhibitDTO exhibitDTO = null;

            if (exhibit != null)
            {
                // Create mapping depending on language
                switch (language)
                {
                case LanguageConstants.LanguageRu:
                    mapperConfiguration      = ExhibitsMappingConfigurations.GetRuConfiguration;
                    mapperConfigurationPhoto = ExhibitsMappingConfigurations.GetRuPhotoConfiguration;
                    break;

                case LanguageConstants.LanguageEn:
                    mapperConfiguration      = ExhibitsMappingConfigurations.GetEnConfiguration;
                    mapperConfigurationPhoto = ExhibitsMappingConfigurations.GetEnPhotoConfiguration;
                    break;

                case LanguageConstants.LanguageBy:
                    mapperConfiguration      = ExhibitsMappingConfigurations.GetByConfiguration;
                    mapperConfigurationPhoto = ExhibitsMappingConfigurations.GetByPhotoConfiguration;
                    break;

                default:
                    mapperConfiguration      = ExhibitsMappingConfigurations.GetEnConfiguration;
                    mapperConfigurationPhoto = ExhibitsMappingConfigurations.GetEnPhotoConfiguration;
                    break;
                }
                var mapper = new Mapper(mapperConfiguration);
                exhibitDTO = mapper.Map <ExhibitDTO>(exhibit);

                mapper = new Mapper(mapperConfigurationPhoto);
                var photoInfoDTO = mapper.Map <List <PhotoInfoDTO> >(exhibit.Photos);
                exhibitDTO.Photos = photoInfoDTO;
            }
            return(exhibitDTO);
        }
Esempio n. 4
0
 public async Task <PartialViewResult> Index(string hallId, string standId, string id)
 {
     ViewBag.HallId  = hallId;
     ViewBag.StandId = standId;
     return(PartialView("~/Views/Shared/Exhibits/_Index.cshtml", await _exhibitsRepository.GetAsync(hallId, standId, id)));
 }