Exemple #1
0
        public async Task <IActionResult> UploadProfilePicture(IFormFile file)
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            ViewBag.WaitList = mBotAppVar.users;

            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction(nameof(HomeController.Start), "Home"));
            }
            Cloudinary cloudinary = new Cloudinary(account);

            if (User.Identity.IsAuthenticated)
            {
                var filePath = Path.GetTempFileName();
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }
                var uploadParams = new ImageUploadParams()
                {
                    File = new FileDescription(filePath)
                };
                var uploadResult = cloudinary.Upload(uploadParams);

                user.ProfilePicture = uploadResult.SecureUri.AbsoluteUri;

                _context.Update(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(HomeController.Start), "Home"));
            }
            return(View());
        }
Exemple #2
0
        public async Task <IActionResult> SaveSnapshot()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction(nameof(HomeController.Start), "Home"));
            }
            bool saved = false;
            var  user  = await _userManager.GetUserAsync(HttpContext.User);

            string image = Request.Form["datatype"].ToString();

            var databaseimage = new GalleryImage
            {
                Title   = user.FirstName,
                Url     = image.ToString(),
                Created = DateTime.Now
            };

            _context.Add(databaseimage);
            await _context.SaveChangesAsync();

            saved = true;
            return(Json(saved ? "Your Snapshot stored in Gallery, you can see it there with your First Name on it" : "image not saved"));
        }