public async Task <Cart> CreateAsync(Cart cart) { _dbContext.Add(cart); await _dbContext.SaveChangesAsync(); return(cart); }
//GET: Products/Verkoop public async Task <IActionResult> Verkoop(int?id) { if (id != null) { var customer = await _context.Customers.Include(c => c.Bags).Where(c => c.CustomerID == id).FirstOrDefaultAsync(); Shoppingbag bag; if (customer.Bags.Count == 0) { bag = new Shoppingbag() { Date = DateTime.Now, Customer = customer, CustomerID = customer.CustomerID }; _context.Add(bag); await _context.SaveChangesAsync(); //customer.Bags.Add(bag); } else { bag = customer.Bags.FirstOrDefault(b => b.Closed == false); } ViewData["Customer"] = customer; ViewData["Shoppingbag"] = bag; } return(View(await _context.Products.ToListAsync())); }
public void AddItemToCart(int Cart_given_id, int Given_ProductId) { var find_cart = (from carts in _context.CartProducts where carts.CartId == Cart_given_id select carts).ToArray(); var search_product = find_cart.FirstOrDefault(existing_cart_product => existing_cart_product.ProductId == Given_ProductId); if (search_product == null) { var cartproduct = new CartProduct { CartId = Cart_given_id, ProductId = Given_ProductId, CartQuantity = 1, CartDateAdded = DateTime.Now }; _context.Add(cartproduct); _context.SaveChanges(); } else { search_product.CartQuantity++; } ProductStock_GoDown(Given_ProductId); _context.SaveChanges(); }
public void Add(Product newProduct) { _context.Add(newProduct); _context.Database.OpenConnection(); try { _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Products ON"); _context.SaveChanges(); _context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Products OFF"); } finally { _context.Database.CloseConnection(); } }
public async Task <Address> CreateAsync(Address address) { _dbContext.Add(address); await _dbContext.SaveChangesAsync(); return(address); }
public async Task <Order> CreateAsync(Order order) { _dbContext.Add(order); await _dbContext.SaveChangesAsync(); return(order); }
public async Task <User> CreateAsync(User user) { _dbContext.Add(user); await _dbContext.SaveChangesAsync(); return(user); }
public async Task <Payment> CreateAsync(Payment payment) { _dbContext.Add(payment); await _dbContext.SaveChangesAsync(); return(payment); }
public async Task <IActionResult> Create([Bind("ShoppingitemID,Quantity,ProductID,ShoppingbagID")] Shoppingitem shoppingitem) { if (ModelState.IsValid) { if (shoppingitem.Quantity == 0) { return(RedirectToAction("Overzicht", "Shoppingbags", new { id = shoppingitem.ShoppingbagID })); } var checkproduct = await _context.Shoppingitems.Include(i => i.Product).Where(i => i.ProductID == shoppingitem.ProductID && i.ShoppingbagID == shoppingitem.ShoppingbagID).FirstOrDefaultAsync(); if (checkproduct == null) { _context.Add(shoppingitem); await _context.SaveChangesAsync(); checkproduct = shoppingitem; } else { checkproduct.Quantity += shoppingitem.Quantity; _context.Update(checkproduct); await _context.SaveChangesAsync(); } return(RedirectToAction("Overzicht", "Shoppingbags", new { id = checkproduct.ShoppingbagID })); //else quantity aanpassen //redirect naar shoppingbag overzicht (new view parameters=customerid,shoppingbagid } ViewData["ProductID"] = new SelectList(_context.Products, "ProductID", "Name", shoppingitem.ProductID); ViewData["ShoppingbagID"] = new SelectList(_context.Shoppingbags, "ShoppingbagID", "ShoppingbagID", shoppingitem.ShoppingbagID); return(View(shoppingitem)); }
public async Task <Discount> CreateAsync(CreateDiscount createDiscount) { var discount = _mapper.Map <Discount>(createDiscount); _dbContext.Add(discount); await _dbContext.SaveChangesAsync(); return(discount); }
public async Task <IActionResult> Aanmaak([Bind("CustomerID,Name,Firstname")] Customer customer) { var loginuser = await _context.Customers.FindAsync(1); ViewData["Customer"] = loginuser; if (ModelState.IsValid) { var checklogin = await _context.Customers.Where(s => s.Firstname == customer.Firstname && s.Name == customer.Name).FirstOrDefaultAsync(); if (checklogin == null) { _context.Add(customer); await _context.SaveChangesAsync(); checklogin = customer; } return(RedirectToAction("Verkoop", "Products", new { id = checklogin.CustomerID })); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("ProductID,Name,Imagepath,Description,Price,Stock")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("Id,Name,Email,BirthDate,CustomerGender")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("Id,Code,UnitPrice")] Products products) { if (ModelState.IsValid) { _context.Add(products); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(products)); }
public async Task <IActionResult> Create([Bind("ShoppingbagID,Date,TotalPrice,CustomerID,Closed")] Shoppingbag shoppingbag) { if (ModelState.IsValid) { _context.Add(shoppingbag); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CustomerID"] = new SelectList(_context.Customers, "CustomerID", "FullName", shoppingbag.CustomerID); return(View(shoppingbag)); }
public async Task <IActionResult> Create([Bind("Id,ClientId,ProductId,Quantity")] Order order) { if (ModelState.IsValid) { _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View()); }
public ActionResult Post([FromBody] NewWish newWish) { User user = GetClaimUser(); bool productExists = db.Product.Any(x => x.Id == newWish.id); bool wishExists = db.Wishlists.Any(x => x.UserId == user.Id && x.ProductId == newWish.id); if (productExists && !wishExists) { Wishlist wish = new Wishlist() { UserId = user.Id, ProductId = newWish.id }; db.Add(wish); db.SaveChanges(); return(StatusCode(201)); } else { return(NotFound()); } }
public ActionResult AdminPostCartItems([FromBody] CartViewModel _cartItem, int Id) { CartViewModelValidator validator = new CartViewModelValidator(); ValidationResult results = validator.Validate(_cartItem); if (!results.IsValid) { foreach (var failure in results.Errors) { Errors.AddErrorToModelState(failure.PropertyName, failure.ErrorMessage, ModelState); } } if (!ModelState.IsValid || _cartItem.CartQuantity == 0) { return(BadRequest(ModelState)); } if (_context.Users.Find(Id) != null) { var cartId = (from cart in _context.Carts where cart.UserId == Id select cart.Id).ToArray(); var stockid = (_context.Stock.Where(s => s.Product.Id == _cartItem.ProductId).Select(p => p.Id)).ToArray().First(); var stock = _context.Stock.Find(stockid); var remainingQuantity = _cartItem.CartQuantity; if (stock.ProductQuantity == 0) { return(Ok("Niet op vooraad")); } else if (stock.ProductQuantity < _cartItem.CartQuantity) { remainingQuantity = stock.ProductQuantity; stock.ProductQuantity = 0; } else { stock.ProductQuantity = stock.ProductQuantity - _cartItem.CartQuantity; } CartProduct product = new CartProduct() { CartId = cartId[0], ProductId = _cartItem.ProductId, CartQuantity = remainingQuantity, CartDateAdded = DateTime.Now }; TotalPrice(cartId[0]); _context.Add(product); _context.Stock.Update(stock); _context.SaveChanges(); return(Ok()); } return(NotFound()); }
public async Task <ActionResult> Post([FromBody] OrderProducts requestOrder) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Order order = new Order(); order.OrderStatus = OrderStatusEnum.Ordered; order.OrderDate = DateTime.Now; order.TaxPercentage = 21; order.Email = requestOrder.Email; order.FirstName = requestOrder.FirstName; order.Prefix = requestOrder.Prefix; order.LastName = requestOrder.LastName; order.Street = requestOrder.Street; order.BuildingNumber = requestOrder.BuildingNumber; order.PostalCode = requestOrder.PostalCode; order.Area = requestOrder.Area; order.OrderProducts = new List <OrderProduct>(); var productsAmount = ( from p in db.Product from p_a in requestOrder.orderProductAmount where p_a.ProductId == p.Id select new { product = p, amount = p_a.Amount } ).ToArray(); foreach (var productAmount in productsAmount) { order.OrderProducts.Add(new OrderProduct() { Product = productAmount.product, Price = productAmount.product.Price, Amount = productAmount.amount }); productAmount.product.Inventory -= productAmount.amount; db.Update(productAmount.product); } User user = GetClaimUser(); if (user != null) { order.User = user; if (requestOrder.SaveAddress) { user.Street = requestOrder.Street; user.BuildingNumber = requestOrder.BuildingNumber; user.PostalCode = requestOrder.PostalCode; user.Area = requestOrder.Area; } if (user.DiscountPoints == 10) { order.DiscountPercentage = this.discountPercentage; user.DiscountPoints = 0; } else { user.DiscountPoints++; } db.Update(user); } db.Add(order); await db.SaveChangesAsync(); return(CreatedAtAction("GetOrder", new { id = order.Id }, order.Id)); }