Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Age,Gender,Bio,UserAccountId, DisplayName")] DatingProfile datingProfile,
                                                 IFormFile FilePhoto)
        {
            if (FilePhoto.Length > 0)
            {
                string photoPath = _webroot.WebRootPath + "\\userPhotos\\";
                var    fileName  = Path.GetFileName(FilePhoto.FileName);

                using (var stream = System.IO.File.Create(photoPath + fileName))
                {
                    await FilePhoto.CopyToAsync(stream);

                    datingProfile.Photopath = fileName;
                }
            }

            if (ModelState.IsValid)
            {
                _context.Add(datingProfile);
                await _context.SaveChangesAsync();

                return(RedirectToAction("ProfileInfo"));
            }
            return(View(datingProfile));
        }
        //[Authorize]
        public async Task <IActionResult> Create([Bind("Id,DisplayName,FirstName,LastName,Age,Gender,Bio,UserAccountId")]
                                                 DatingProfile datingProfile, IFormFile FilePhoto)
        {
            if (FilePhoto.Length > 0)
            {
                //see for free images:pexels.com

                string photoPath = _webRoot.WebRootPath + "\\userPhotos\\";
                //get the name of the photo ie, filename of photo
                var fileName = Path.GetFileName(FilePhoto.FileName);

                using (var datastream = System.IO.File.Create(photoPath + fileName))
                {
                    await FilePhoto.CopyToAsync(datastream);

                    datingProfile.PhotoPath = fileName;
                }
            }

            if (ModelState.IsValid)
            {
                _context.Add(datingProfile);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(datingProfile));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Age,Gender,Bio,UserAccountId")] DatingProfile datingProfile)
        {
            if (ModelState.IsValid)
            {
                _context.Add(datingProfile);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(datingProfile));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Age,Gender,Bio,UserAccountId")] DatingProfile datingProfile)
        {
            if (ModelState.IsValid)
            {
                _context.Add(datingProfile);
                await _context.SaveChangesAsync();

                // Clean up the Home Page
                // Change Profile Info to go back to the Home Page
                return(RedirectToAction("Index", "Home"));
                // return RedirectToAction(nameof(Index)); ...commented out by th 08192020
            }
            return(View(datingProfile));
        }