Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("UserName,PassWord,Email")] User newuser)
        {
            if (!ModelState.IsValid)
            {
                return(View("Register", newuser));
            }
            // Check if username and email already is in DB;
            var dupeName  = _context.User.Any(el => el.UserName == newuser.UserName);
            var dupeEmail = _context.User.Any(el => el.Email == newuser.Email);

            if (dupeName)
            {
                ViewBag.Result = $"User with username {newuser.UserName}  already exists!";
                return(View("Register", newuser));
            }
            if (dupeEmail)
            {
                ViewBag.Result = $"Email:  {newuser.Email}  already exists!";
                return(View("Register", newuser));
            }
            string hashedPassword = BCrypt.Net.BCrypt.HashPassword(newuser.PassWord); // Bcrypt password hashing and later in login Verifying

            newuser.PassWord = hashedPassword;
            if (ModelState.IsValid)
            {
                var result = _context.Add(newuser);
                await _context.SaveChangesAsync();

                HttpContext.Session.SetString("user", newuser.UserName);
                return(RedirectToAction("Index", "Home"));
            }

            return(View(newuser));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("CategoryID,CategoryName,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("SupplierID,CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax,HomePage")] Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supplier);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplier));
        }
        public async Task <IActionResult> Create([Bind("CompanyName,ContactName,ContactTitle,Address,City,Region,PostalCode,Country,Phone,Fax")] Customer customer)
        {
            customer.CustomerId = RandomString(5);
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
        public async Task <IActionResult> Create([Bind("ShipperId,CompanyName,Phone,RegionId")] Shipper shipper)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shipper);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RegionId"] = new SelectList(_context.Regions, "RegionId", "RegionDescription", shipper.RegionId);
            return(View(shipper));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit,UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "CategoryName", product.CategoryID);
            ViewData["SupplierID"] = new SelectList(_context.Suppliers, "SupplierID", "CompanyName", product.SupplierID);
            return(View(product));
        }