Ejemplo n.º 1
0
        public async Task <IActionResult> Signup(UserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _context.User.FirstOrDefaultAsync(u => u.UserName == model.UserName);

                if (user != null)
                {
                    return(RedirectToAction("Signup", new { msg = "Username exists" }));
                }
                else
                {
                    byte[] hash, salt;
                    PasswordHashing(model.Password, out hash, out salt);
                    var newUser = new User
                    {
                        UserName     = model.UserName,
                        PasswordHash = hash,
                        PasswordSalt = salt
                    };
                    _context.User.Add(newUser);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(CategoryViewModel model)
        {
            if (HttpContext.Session.GetString("adminname") == null)
            {
                return(RedirectToAction("Login", "Home", new { msg = "Login first!" }));
            }
            if (ModelState.IsValid)
            {
                var category = new Category
                {
                    CategoryName = model.CategoryName,
                };
                _context.Category.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(ProductViewModel model)
        {
            if (HttpContext.Session.GetString("adminname") == null)
            {
                return(RedirectToAction("Login", "Home", new { msg = "Login first!" }));
            }
            if (ModelState.IsValid)
            {
                string filename = UploadedFile(model.Photo);
                var    product  = new Product
                {
                    ProductName = model.ProductName,
                    Price       = model.Price,
                    CategoryID  = model.ProductCategory,
                    Photo       = filename
                };
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Processed(int id)
        {
            if (HttpContext.Session.GetString("adminname") == null)
            {
                return(RedirectToAction("Login", "Home", new { msg = "Login first!" }));
            }
            var order = await _context.Order.Include(o => o.OrderedProducts).FirstOrDefaultAsync(o => o.OrderID == id);

            foreach (var prod in order.OrderedProducts)
            {
                _context.OrderedProducts.Remove(prod);
            }
            _context.Order.Remove(order);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }