Esempio n. 1
0
        public IActionResult CreateProduct(ProductsAndListProducts newPro)
        {
            if (ModelState.IsValid)
            {
                dbContext.Add(newPro.NewProduct);
                dbContext.SaveChanges();
                return(RedirectToAction("Index")); //CHANGE LATER TO REDIRECT TO PRODUCT ID PAGE
            }
            ProductsAndListProducts viewModel = ListOfProductsViewModel();

            return(View("Index", viewModel));
        }
Esempio n. 2
0
 public IActionResult AddCategoryToProduct(Category addCategoryToProduct)
 {
     if (ModelState.IsValid)
     {
         Association newAssociation = new Association();
         newAssociation.ProductID  = (int)HttpContext.Session.GetInt32("ProductID");
         newAssociation.CategoryID = Int32.Parse(addCategoryToProduct.Name);
         dbContext.Add(newAssociation);
         dbContext.SaveChanges();
         return(RedirectToAction("ViewProduct", new { ProductID = HttpContext.Session.GetInt32("ProductID") }));
     }
     TempData["errorC"] = "Theres no more categories to add";
     return(RedirectToAction("ViewProduct", new { ProductID = HttpContext.Session.GetInt32("ProductID") }));
 }
Esempio n. 3
0
        public IActionResult CreateProduct(Product newProduct)
        {
            if (ModelState.IsValid)
            {
                db.Add(newProduct);
                int SavedProductId = db.SaveChanges();

                // Console.WriteLine(newProduct.ProductId);
                // Console.WriteLine(SavedProductId);

                return(Redirect($"/product/{newProduct.ProductId}"));
                // return RedirectToAction("SingleProduct", new { productId = newProduct.ProductId });
            }
            return(View("NewProduct", newProduct));
        }
        public IActionResult Register(User _user)
        {
            // Check initial ModelState
            if (ModelState.IsValid)
            {
                // If a User exists with provided email
                if (dbContext.Users.Any(u => u.Email == _user.Email))
                {
                    // Manually add a ModelState error to the Email field, with provided
                    // error message
                    ModelState.AddModelError("Email", "Email already in use!");
                    return(Redirect("/"));
                    // You may consider returning to the View at this point
                }
                // Initializing a PasswordHasher object, providing our User class as its
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                _user.Password = Hasher.HashPassword(_user, _user.Password);

                dbContext.Add(_user);
                dbContext.SaveChanges();

                return(Redirect("Login"));
            }
            else
            {
                // Oh no!  We need to return a ViewResponse to preserve the ModelState, and the errors it now contains!
                return(View("Index"));
            }
        }