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)); }
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)); }
public IActionResult Send([Bind("MessageTitle, MessageText")] MailMessage mail, int toProfileId) { DatingProfile fromUser = _context.DatingProfile.FirstOrDefault(p => p.UserAccountId == _userManager.GetUserId(User)); mail.FromProfileId = fromUser.Id; mail.IsRead = false; mail.FromProfile = fromUser; mail.ToProfileId = toProfileId; _context.Add(mail); _context.SaveChanges(); return(RedirectToAction("Browse", "DatingProfiles")); }
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)); }