public async Task <IActionResult> Create([Bind("UserID,FirstName,LastName,Email,Username,Password,Image,ConfirmPassword")] UserAccount userAccount, List <IFormFile> Image) { string reason = String.Empty; if (userAccount.Password != null && userAccount.ConfirmPassword != null) { userAccount.Password = EncodeDecodeSecurity.EncriptPassword(userAccount.Password); userAccount.ConfirmPassword = EncodeDecodeSecurity.EncriptPassword(userAccount.ConfirmPassword); } var verifyEmail = _context.userAccount.Where(u => u.Email == userAccount.Email).FirstOrDefault(); if (verifyEmail != null) { ModelState.AddModelError("", "Email in use"); } else { if (ModelState.IsValid) { if (Image != null) { foreach (var item in Image) { if (item.Length > 0) { using (var stream = new MemoryStream()) { await item.CopyToAsync(stream); userAccount.Image = stream.ToArray(); } } } } _context.Add(userAccount); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } return(View(userAccount)); }
public async Task <IActionResult> Edit(int id, [Bind("UserID,FirstName,LastName,Email,Username,Password,Image,ConfirmPassword")] UserAccount userAccount, List <IFormFile> Image) { if (userAccount.Password != null && userAccount.ConfirmPassword != null) { userAccount.Password = EncodeDecodeSecurity.EncriptPassword(userAccount.Password); userAccount.ConfirmPassword = EncodeDecodeSecurity.EncriptPassword(userAccount.ConfirmPassword); } if (id != userAccount.UserID) { return(NotFound()); } if (ModelState.IsValid) { if (Image != null) { foreach (var item2 in Image) { if (item2.Length > 0) { using (var stream = new MemoryStream()) { await item2.CopyToAsync(stream); userAccount.Image = stream.ToArray(); } } } _context.Update(userAccount); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Profile", new { id = userAccount.UserID })); } } return(View(userAccount)); }
public ActionResult Login(UserAccount user) { var accountEm = _context.userAccount.Where(u => u.Email.Trim() == user.Email && u.Password.Trim() == EncodeDecodeSecurity.EncriptPassword(user.Password)).FirstOrDefault(); ///user.Password = EncodeDecodeSecurity.DecryptPassword(user.Password); if (accountEm != null) { HttpContext.Session.SetString("UserID", accountEm.UserID.ToString()); HttpContext.Session.SetString("Username", accountEm.Username); return(RedirectToAction("Details", "Profile", new { id = accountEm.UserID })); } else { ModelState.AddModelError("", "EMAIL OCONTRASEÑA INCORRECTA."); } //var perfil=_context.userAccount return(View()); }