/// <inheritdoc />
        public async Task <ServiceResponse <int> > CreateGuide(AddGuideDto newGuide)
        {
            var serviceResponse = new ServiceResponse <int>();
            var userId          = GetUserId;

            var hasAccess = await _usersRepository.UserIsEditor(userId);

            if (!hasAccess)
            {
                serviceResponse.StatusCode = 401;
                serviceResponse.Message    = "User access should be editor or admin.";
                serviceResponse.MessageRu  = "Пользователь должен быть Редактором или Администратором.";
                return(serviceResponse);
            }

            if (newGuide.Image.ContentType != "image/png")
            {
                serviceResponse.StatusCode = 400;
                serviceResponse.Message    = "File must be PNG image.";
                serviceResponse.MessageRu  = "Файл должен являться PNG изображением.";
                return(serviceResponse);
            }

            var guide = _mapper.Map <Guide>(newGuide);

            guide.OwnerId = userId;
            guide.Hidden  = "true";

            var guideId = await _guidesRepository.CreateGuide(guide);

            await _fileManager.SaveFile(guideId, "preview.png", newGuide.Image);

            serviceResponse.StatusCode = 201;
            serviceResponse.Data       = guideId;
            serviceResponse.Message    = "Guide is successfully created.";
            serviceResponse.MessageRu  = "Гайд успешно создан.";
            return(serviceResponse);
        }
Beispiel #2
0
        public async Task <IActionResult> CreateNewGuide([FromForm] AddGuideDto guide)
        {
            var serviceResponse = await _guidesService.CreateGuide(guide);

            return(StatusCode(serviceResponse.StatusCode, serviceResponse.ToControllerResponse()));
        }