public IActionResult Login(LoginUser userSubmission) { indexWrapper WMod = new indexWrapper(); // Validations if (ModelState.IsValid) { // Check db email with from email var userInDb = _context.Users.FirstOrDefault(u => u.Email == userSubmission.LogEmail); // No user in db if (userInDb == null) { ModelState.AddModelError("Email", "Invalid Email/Password"); return(View("index", WMod)); } // Check hashing are the same var hasher = new PasswordHasher <LoginUser>(); var result = hasher.VerifyHashedPassword(userSubmission, userInDb.Password, userSubmission.LogPassword); if (result == 0) { // ModelState.AddModelError("Email", "Invalid Email/Password"); // return View("index", WMod);// handle failure (this should be similar to how "existing email" is handled) } // Set Session Instance HttpContext.Session.SetInt32("UserId", userInDb.UserId); return(RedirectToAction("dashboard", WMod)); } return(View("index", WMod)); }
public IActionResult Redgister(User FromForm) { // Pass in Models so that parcial can use them indexWrapper WMod = new indexWrapper(); // Check if email is already in db if (_context.Users.Any(u => u.Email == FromForm.Email)) { ModelState.AddModelError("Email", "Email already in use!"); } // Validations if (ModelState.IsValid) { // #hash password PasswordHasher <User> Hasher = new PasswordHasher <User>(); FromForm.Password = Hasher.HashPassword(FromForm, FromForm.Password); // Add to db _context.Add(FromForm); _context.SaveChanges(); // Session HttpContext.Session.SetInt32("UserId", _context.Users.FirstOrDefault(i => i.UserId == FromForm.UserId).UserId); // Redirect System.Console.WriteLine("You may contine!"); return(RedirectToAction("dashboard", WMod)); } else { System.Console.WriteLine("Fix your erros!"); return(View("index", WMod)); } }
public IActionResult AddProduct(int id, indexWrapper addpro) { addpro.oneAssociation.CategoryId = id; _context.Add(addpro.oneAssociation); _context.SaveChanges(); return(RedirectToAction("index", new{ id = id })); }
public IActionResult NewCategory(indexWrapper newCategory) { if (ModelState.IsValid) { _context.Add(newCategory.oneCategory); _context.SaveChanges(); return(RedirectToAction("NewCategoryPage")); } return(View()); }
public IActionResult NewProduct(indexWrapper newProduct) { if (ModelState.IsValid) { _context.Add(newProduct.oneProduct); _context.SaveChanges(); return(RedirectToAction("NewProductPage")); } return(View()); }
public IActionResult AddCategories(int id, indexWrapper addcategory) { addcategory.oneAssociation.ProductId = id; // WMod.oneProduct = _context.Products // .Include(op => op.belongedCategory) // .ThenInclude(top => top.Category) // .FirstOrDefault(o => o.ProductId == addcategory.oneProduct.ProductId); _context.Add(addcategory.oneAssociation); _context.SaveChanges(); return(RedirectToAction("Product", new{ id = id })); }
public IActionResult index() { indexWrapper WMod = new indexWrapper(); return(View("index", WMod)); }