public IActionResult Post([FromBody] ProjectProgrammer pp) { if (pp == null) { return(BadRequest()); } db.ProjectProgrammers.Add(pp); db.SaveChanges(); return(Ok(pp)); }
public IActionResult Post([FromBody] Project pc) { if (pc == null) { return(BadRequest()); } db.Projects.Add(pc); db.SaveChanges(); return(Ok(pc)); }
public async Task <IActionResult> AddProduct(int id) { var customer = await _context.Customer.Where(e => e.Email.Equals(User.Identity.Name)).Select(e => e.CustomerId).FirstAsync(); var ordering = await _context.Order.Where(i => i.CustomerId.Equals(customer) && i.OrderStatus.Equals("Cart")).FirstOrDefaultAsync(); if (ordering != null) { var product = await _context.OrderProduct.Where(i => i.ProductId.Equals(id) && i.OrderId.Equals(ordering.OrderId)).FirstOrDefaultAsync(); if (product != null) { product.Quantity++; } else { //object initialization OrderProduct order_product = new OrderProduct(); order_product.OrderId = ordering.OrderId; order_product.ProductId = id; order_product.Quantity = 1; _context.OrderProduct.Add(order_product); } await _context.SaveChangesAsync(); } else { //object initialization simplified Order order = new Order { OrderStatus = "Cart", CustomerId = customer }; _context.Order.Add(order); _context.SaveChanges(); var order_id = await _context.Order.Where(i => i.CustomerId.Equals(customer) && i.OrderStatus.Equals("Cart")).Select(e => e.OrderId).FirstAsync(); OrderProduct order_product = new OrderProduct(); order_product.OrderId = order_id; order_product.ProductId = id; order_product.Quantity = 1; _context.OrderProduct.Add(order_product); await _context.SaveChangesAsync(); } return(RedirectToAction("Index", "Products")); }