Exemple #1
0
        public IActionResult Add([FromForm] int?id)
        {
            if (id != null)
            {
                var      userId   = _userManager.GetUserId(HttpContext.User);
                CartItem cartItem = new CartItem()
                {
                    CustomerId = userId,
                    AddedDate  = DateTime.Now,
                    ProductId  = Convert.ToInt32(id)
                };
                _db.CartItem.Add(cartItem);
                _db.SaveChanges();
            }
            else
            {
                ModelState.AddModelError("", "Product not found");
                return(NotFound());
            }

            return(RedirectToAction("Index", "Product"));
        }
Exemple #2
0
 public void Save()
 {
     _db.SaveChanges();
 }