Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Username,FirstName,LastName,Email,Password,ConfirmPassword,RegistrationDate,Type")] Account account)
        {
            if (id != account.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(account);
                    await _context.SaveChangesAsync();

                    //we may change to Role so we need to update the Claims
                    var user = _context.Account.FirstOrDefault(u => u.Id == id);
                    CookieAuthentication(user);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AccountExists(account.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Admin)));
            }
            return(View(account));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,OrderDate,TotalPrice,Status,FirstName,LastName,Email,StreetAddress,ZipCode,City,Country,PhoneNumber,CreditCardNum")] Order order)
        {
            if (id != order.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(order);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrderExists(order.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(order));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,ImageUrl")] Brand brand)
        {
            if (ModelState.IsValid)
            {
                _context.Add(brand);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(brand));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,City")] Branch branch)
        {
            if (ModelState.IsValid)
            {
                _context.Add(branch);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(branch));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,UnitPrice,Quantity")] OrderDetail orderDetail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orderDetail);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(orderDetail));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,Description,ImageUrl,FrontImageUrl,BackImageUrl,UnitsInStock")] Product product, int BrandId, int CategoryId)
        {
            product.TotalPurchases = 0;
            product.Brand          = _context.Brand.First(b => b.Id == BrandId);
            product.Category       = _context.Category.First(c => c.Id == CategoryId);

            if (product.ImageUrl == null)
            {
                product.ImageUrl = "/images/Default.png";
            }
            if (product.BackImageUrl == null)
            {
                product.BackImageUrl = "/images/Default.png";
            }
            if (product.FrontImageUrl == null)
            {
                product.FrontImageUrl = "/images/Default.png";
            }

            if (product.Brand == null)
            {
                ModelState.AddModelError("Brand", "Please select a brand.");
            }

            if (product.Category == null)
            {
                ModelState.AddModelError("Category", "Please select a category.");
            }

            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Id,Title,Content")] Review review, int productId)
        {
            review.Date = DateTime.Now;

            string accountUserName = User.Claims.FirstOrDefault(c => c.Type == "AccountUserName").Value;

            review.SentBy  = _context.Account.FirstOrDefault(i => i.Username == accountUserName);
            review.Product = _context.Product.FirstOrDefault(p => p.Id == productId);



            if (ModelState.IsValid)
            {
                _context.Add(review);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(review));
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ///
        ///                                                         ShoppingCart&Checokout:
        ///
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        //View your cart
        public async Task <IActionResult> Index()
        {
            var cart = GetShoppingCart();

            //if entering the cart and one items became out of stock
            var itemsList = _context.ShoppingCartItem.Where(i => i.AssociatedShoppingCart.Id == cart.Id).Include(c => c.Product);

            foreach (var item in itemsList)
            {
                if (item.Product.InStock == false)
                {
                    _context.Remove(item);
                }
            }

            await _context.SaveChangesAsync();

            ViewBag.Total = GetTotalPrice();
            return(View(await _context.ShoppingCartItem.Where(i => i.AssociatedShoppingCart.Id == cart.Id).Include(c => c.Product).ToListAsync()));
        }