Exemplo n.º 1
0
        public async Task <JsonResult> UploadPhotoForAlbum()
        {
            var userId = this.User.Identity.GetUserIdGuid().Value;

            if (this.HttpContext.Request.Files == null ||
                this.HttpContext.Request.Files.Count == 0)
            {
                return(Json(new
                {
                    success = false,
                    errorMessage = "File not found."
                }));
            }

            var    photo   = this.HttpContext.Request.Files[0];
            string fileUrl = await this.SaveFile(userId, photo.FileName, photo.InputStream);

            await _userService.AddAlbumPhotoUrl(userId, fileUrl);

            _hubContext.Clients.All
            .GalleryPhotoUploaded(userId, PhotoUrlService.GetPhotoDto(fileUrl));

            return(Json(new
            {
                success = true
            }));
        }