public async Task <IActionResult> UploadPicture(IFormFile file)
        {
            var user = await this._userManager.GetUserAsync(HttpContext.User);

            using (var stream = new MemoryStream())
            {
                await file.CopyToAsync(stream);

                await this.blobStorageService.UploadAsync(user.Id, blobContainer, stream.ToArray());
            }

            var pictureUri = await this.blobStorageService.GetAsync(user.Id, blobContainer);

            user.ProfilePictureUrl = pictureUri.Url.ToString();
            var updated = await this._userManager.UpdateAsync(user);

            var faceAtributes = await faceService.DetectFaceAtribytesAsync(blobStorageService.GetAsync(user.Id, blobContainer).Result.Url);

            _emotionManager.ProcessSendingMessage(faceAtributes, user.Email, user.UserName);

            StatusMessage = "Your profile picture has been updated. Check your email!";
            var model = new IndexViewModel {
                StatusMessage = StatusMessage
            };

            return(RedirectToAction(nameof(Index)));
        }
예제 #2
0
        public async Task <IActionResult> UploadPicture(IFormFile file)
        {
            var user = await this._userManager.GetUserAsync(HttpContext.User);

            string currentUserEmail = user.Email;
            string userId           = user.Id;

            using (var stream = new MemoryStream())
            {
                await file.CopyToAsync(stream);

                await this.blobStorageService.UploadAsync(user.Id, blobContainer, stream.ToArray());
            }


            var pictureUri = await this.blobStorageService.GetAsync(userId, blobContainer);

            user.ProfilePictureUrl = pictureUri.Url.ToString();
            var updated = await this._userManager.UpdateAsync(user);

            var faceAtributes = await faceService.DetectFaceAtribytesAsync(blobStorageService.GetAsync(userId, blobContainer).Result.Url);

            try
            {
                smtpSender.SendMail(user.Email, GenerateMessageByEmotion(faceAtributes[0], user.UserName));
            }
            catch (IndexOutOfRangeException e)
            {
                smtpSender.SendMail(currentUserEmail, "No face on picture");
            }

            StatusMessage = "Your profile picture has been updated. Check your email!";
            var model = new IndexViewModel {
                StatusMessage = StatusMessage
            };

            return(RedirectToAction(nameof(Index)));
        }