public IActionResult Post([FromForm] ChannelForAddDto channelForAddDto)
        {
            var     resultId    = User.Claims.GetUserId();
            IResult checkResult = _channelService.CheckIfChannelNameExists(channelForAddDto.Name);

            if (!checkResult.IsSuccessful)
            {
                return(BadRequest(checkResult.Message));
            }

            if (channelForAddDto.File.Length > 0)
            {
                ImageUploadResult imageUploadResult = _photoUpload.ImageUpload(channelForAddDto.File);
                if ((int)imageUploadResult.StatusCode < 300)
                {
                    var channel = _mapper.Map <Channel>(channelForAddDto);
                    channel.ChannelPhotoUrl = imageUploadResult.Uri.ToString();
                    channel.PublicId        = imageUploadResult.PublicId;
                    channel.UserId          = resultId.Data;
                    IResult result = _channelService.Add(channel);
                    if (result.IsSuccessful)
                    {
                        var mapResult = _mapper.Map <ChannelForDetailDto>(channel);
                        this.RemoveCacheByContains(resultId.Data + "/user-channels");
                        return(Ok(mapResult));
                    }
                    return(BadRequest(result.Message));
                }
                return(BadRequest(imageUploadResult.Error.Message));
            }
            return(BadRequest());
        }
Exemple #2
0
        public IActionResult Post([FromForm] PhotoForAddDto photoForAddDto)
        {
            if (photoForAddDto.File.Length > 0)
            {
                ImageUploadResult imageUploadResult = _photoUpload.ImageUpload(photoForAddDto.File);
                var mapResult = _mapper.Map <Photo>(photoForAddDto);
                mapResult.PhotoUrl = imageUploadResult.Uri.ToString();
                mapResult.PublicId = imageUploadResult.PublicId;
                mapResult.UserId   = User.Claims.GetUserId().Data;
                IResult result = _photoService.Add(mapResult);

                if (result.IsSuccessful)
                {
                    this.RemoveCache();
                    return(Ok(result.Message));
                }
                return(this.ServerError(result.Message));
            }
            return(BadRequest());
        }