public async Task <string> UploadProfilePicAsync(ImageModel imageModel)
        {
            try
            {
                ApplicationUser user = await checkUserExistAsync(imageModel.Id);

                if (user != null)
                {
                    string       sasKey      = Startup.Configuration.GetConnectionString("BlobSASkey");
                    BlobServices blobService = new BlobServices();
                    user.ProfilePictureImage = await blobService.UploadImageToBlobStorageAsync(Convert.FromBase64String(imageModel.ImageBase64), imageModel.Id);

                    await _userManager.UpdateAsync(user);

                    return(user.ProfilePictureImage + sasKey);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }
        public async Task <IActionResult> UploadMultiplePicAsync(IFormFile file)
        {
            bool   isSavedSuccessfully = false;
            string id     = Request.Headers["UserId"];
            string url    = "";
            string sasKey = Startup.Configuration.GetConnectionString("BlobSASkey");
            string error  = "";

            if (id != null)
            {
                try
                {
                    BlobServices blobService = new BlobServices();

                    //foreach (var file in files)
                    //{

                    //Save file content goes here
                    if (file != null && file.Length > 0)
                    {
                        using (var fileStream = file.OpenReadStream())
                            using (var ms = new MemoryStream())
                            {
                                fileStream.CopyTo(ms);
                                var fileBytes = ms.ToArray();
                                url = await blobService.UploadImageToBlobStorageAsync(fileBytes, id);

                                isSavedSuccessfully = true;
                            }
                    }
                }
                catch (Exception ex)
                {
                    error = ex.ToString();
                    isSavedSuccessfully = false;
                }
            }

            if (isSavedSuccessfully)
            {
                return(Json(new { ImageURL = url + sasKey }));
            }
            else
            {
                return(Json(new { Message = error }));
            }

            //BlobServices blobService = new BlobServices();
            //List<string> uploadedUri = new List<string>();

            //foreach (var image in imageModel.ListOfBase64)
            //{
            //    uploadedUri.Add(await blobService.UploadImageToBlobStorageAsync(Convert.FromBase64String(image), imageModel.Id));
            //}
            //return uploadedUri;
        }
        //[ValidateAntiForgeryToken]
        public async Task <string> UploadPictureAsync([FromBody] ImageModel imageModel)
        {
            BlobServices blobService = new BlobServices();

            return(await blobService.UploadImageToBlobStorageAsync(Convert.FromBase64String(imageModel.ImageBase64), imageModel.Id));
        }
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Register(UserViewModel model, string returnUrl = null)
        {
            var errors = ModelState.Values.SelectMany(v => v.Errors);

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName       = model.Email,
                    Email          = model.Email,
                    Name           = model.Name,
                    Reknown        = model.Reknown,
                    Bio            = model.Bio,
                    EmailConfirmed = false
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Action(nameof(ConfirmEmail), "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    URLShortenerService urlShortener = new URLShortenerService();

                    await new EmailServices().SendEmailAsync(model.Email, "Confirm your account",
                                                             urlShortener.ShortenIt(callbackUrl), EmailServices.EmailType.Register);

                    ApplicationRole mRole = null;
                    if (model.ApplicationRoleId != null)
                    {
                        mRole = await _roleManager.FindByIdAsync(model.ApplicationRoleId);
                    }
                    ApplicationRole applicationRole = mRole != null && mRole.Name.Equals("Admin") ? mRole : await _roleManager.FindByIdAsync(_roleManager.Roles.Single(r => r.Name.Equals("User")).Id);

                    if (applicationRole != null)
                    {
                        IdentityResult roleResult = await _userManager.AddToRoleAsync(user, applicationRole.Name);

                        if (roleResult.Succeeded)
                        {
                            BlobServices bs = new BlobServices();
                            if (user.ProfilePictureImage != null)
                            {
                                user.ProfilePictureImage = await bs.UploadImageToBlobStorageAsync(Convert.FromBase64String(model.ProfilePictureImage), user.Id);
                            }
                            await _userManager.UpdateAsync(user);

                            string message = "User created a new account with password.";
                            _logger.LogInformation(3, message);
                            return(Ok(Json(new { message = message, user = user })));
                        }
                    }
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(BadRequest(Json(new { messages = errors })));
        }