コード例 #1
0
        private async Task <string> GeneratePhotoUrl(int id, UserToSetPhotoDto userToSetPhotoDto)
        {
            string uploadPath = GetAndClearUserDirectoryPath(id);

            var uploadedPhoto = await filesUploader.Upload(userToSetPhotoDto.Photo, uploadPath);

            string photoUrl = null;

            if (uploadedPhoto != null)
            {
                photoUrl = filesUploader.CombinePaths($@"{filesUploader.FilesUrl}/{id}/", uploadedPhoto.FileName);
            }

            return(photoUrl);
        }
コード例 #2
0
        public async Task <IActionResult> SetPhoto(int id, [FromForm] UserToSetPhotoDto userToSetPhotoDto)
        {
            var user = await accountManager.GetUser(id);

            if (!filesUploader.IsValidExtension(userToSetPhotoDto.Photo.FileName, new string[] { ".img", ".jpg", ".png" }))
            {
                return(BadRequest("Niepoprawny format zdjęcia"));
            }

            string photoUrl = await GeneratePhotoUrl(id, userToSetPhotoDto);

            if (await accountManager.SetPhoto(user, photoUrl))
            {
                return(NoContent());
            }

            throw new AccountException("Wystąpił błąd podczas zmiany zdjęcia");
        }