public async Task <IActionResult> PutShipping([FromRoute] int id, [FromBody] Shipping shipping) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != shipping.Id) { return(BadRequest()); } _context.Entry(shipping).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShippingExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> Create([Bind("CustomerID,Name,Company")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("ScheduleID,Time,Location,BookingID,CustomerID")] Schedule schedule) { if (ModelState.IsValid) { _context.Add(schedule); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["BookingID"] = new SelectList(_context.Booking, "BookingID", "BookingID", schedule.BookingID); return(View(schedule)); }
public async Task <IActionResult> Create([Bind("BookingID,CustomerID,Schedule,NoContainer")] Booking booking) { if (ModelState.IsValid) { _context.Add(booking); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CustomerID"] = new SelectList(_context.Customer, "CustomerID", "CustomerID", booking.CustomerID); return(View(booking)); }
public async Task <IHttpActionResult> AddToCart(dynamic data) { var cartId = (int)data.CartId; var productId = (int)data.ProductId; var quantity = (int)data.Quantity; using (var db = new ShippingContext()) { var shippingDetails = db.ProductsShippingDetails .Where(o => o.ProductId == productId) .Single(); var cartItem = new ShoppingCartItem() { CartId = cartId, RequestId = Request.Headers.GetValues("request-id").Single(), ProductId = productId, Quantity = quantity, ItemShippingCost = shippingDetails.Cost, FreeShippingEligible = shippingDetails.FreeShippingEligible }; db.ShoppingCartItems.Add(cartItem); await db.SaveChangesAsync(); } return(StatusCode(HttpStatusCode.OK)); }
public async Task Handle(CleanupCart message, IMessageHandlerContext context) { using (var db = new ShippingContext()) { var shoppingCartItem = db.ShoppingCartItems.SingleOrDefault(item => item.RequestId == message.RequestId); if (shoppingCartItem != null) { db.ShoppingCartItems.Remove(shoppingCartItem); await db.SaveChangesAsync(); } } }
public async Task <IActionResult> PostProduct(ProductRequestDto productRequestDto) { if (productRequestDto.Name.EndsWith('1')) { return(new ConflictResult()); } var product = _mapper.Map <Product>(productRequestDto); _context.Products.Add(product); await _context.SaveChangesAsync(); return(new OkObjectResult(product.Id)); }
public async Task Handle(InactiveCartWiped message, IMessageHandlerContext context) { var backup = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"Ready to wipe cart {message.CartId}..."); using (var db = new ShippingContext()) { var cartItems = db.ShoppingCartItems.Where(i => i.CartId == message.CartId); foreach (var item in cartItems) { db.ShoppingCartItems.Remove(item); } await db.SaveChangesAsync(); } Console.WriteLine($"Cart {message.CartId} wiped."); Console.ForegroundColor = backup; }