public async Task <IActionResult> UpdatePhoto([FromForm] UpdateUserPhotoCommand command, [FromQuery] bool random = false)
     {
         if (random)
         {
             command = new UpdateUserPhotoCommand {
                 IsRandom = true
             }
         }
         ;
         return(HandleResult(await Mediator.Send(command)));
     }
 }
Esempio n. 2
0
        public async Task <Response <bool> > Handle(UpdateUserPhotoCommand request, CancellationToken cancellationToken)
        {
            UploadedFileData uploadedData = await fileManager.AddFileAsync(request.Photo, FileTypeEnum.UserPhoto);

            Img userPhoto = await photoRepo.GetImgByUserIdAsync(request.Userid);

            // remove from hard
            fileManager.DeleteFile(userPhoto.Path);
            // remove from db
            await photoRepo.Remove(userPhoto);

            Img newImg = new Img {
                UserId = request.Userid,
                Url    = uploadedData.Url,
                Path   = uploadedData.Path
            };
            await photoRepo.AddAsync(newImg);

            return(Response.Ok());
        }
 public async Task <Response <bool> > UserPhoto([FromForm] UpdateUserPhotoCommand userPhotoCommand)
 {
     return(await mediator.Send(userPhotoCommand));
 }