public async Task <Result <Order> > ChangeOrderStatus(CancelOrderContext context) { var order = await _dbContext.Orders.FindAsync(context.OrderId); if (order == null) { _logger.LogInformation($"Order {context.OrderId} could not be found."); return(new Result <Order> { Reason = ReasonType.CourierNotFound, IsSuccessful = false }); } order.Status = (int)context.Status; order.StatusTimestamp = DateTime.Now; _dbContext.Update(order); int changes = await _dbContext.SaveChangesAsync(); if (changes <= 0) { _logger.LogInformation($"Order {context.OrderId} status was not updated."); return(new Result <Order> { Reason = ReasonType.DatabaseError, ChangeCount = changes, IsSuccessful = false }); } _logger.LogInformation($"Order {context.OrderId} status was updated."); return(new Result <Order> { ChangeCount = changes, Value = MapToOrder(order), IsSuccessful = true }); }
public async Task <IActionResult> Edit(int id, [Bind("Id,OrderNumber,OrderDate,ClientName")] 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)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,FirstName,Surname,Phone,Address")] Customercs customercs) { if (id != customercs.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(customercs); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomercsExists(customercs.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(customercs)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Price,AvailableQuantity")] Product product) { if (id != product.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(product); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(product.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Category category) { if (id != category.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(category); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(category.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,CustomerID,MenuID,OrderDate")] 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))); } ViewData["MenuID"] = new SelectList(_context.Menu, "ID", "ID", order.MenuID); return(View(order)); }
public async Task <IActionResult> Edit(int id, [Bind("ProductId,OrderId,Quantity")] Product_Order product_Order) { if (id != product_Order.ProductId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(product_Order); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Product_OrderExists(product_Order.ProductId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["OrderId"] = new SelectList(_context.Orders, "Id", "ClientName", product_Order.OrderId); ViewData["ProductId"] = new SelectList(_context.Products, "Id", "Name", product_Order.ProductId); return(View(product_Order)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,DishName,DitearyRestrictions,Price,Rating")] Menu menu) { if (id != menu.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(menu); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MenuExists(menu.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(menu)); }
public async Task <Result <Courier> > Decline(CourierDispatchRequest request) { var courier = await _db.Couriers.FindAsync(request.CourierId); if (courier == null) { Log.Information($"Courier {request.CourierId} could not be found."); return(new Result <Courier> { Reason = ReasonType.CourierNotFound, IsSuccessful = false }); } courier.Status = (int)CourierStatus.DispatchDeclined; courier.StatusTimestamp = DateTime.Now; _db.Update(courier); var order = await _db.Orders.FindAsync(request.OrderId); if (order == null) { Log.Information($"Order {request.OrderId} could not be found."); return(new Result <Courier> { Reason = ReasonType.OrderNotFound, IsSuccessful = false }); } order.CourierId = null; order.StatusTimestamp = DateTime.Now; _db.Update(order); var changes = await _db.SaveChangesAsync(); if (changes <= 0) { Log.Information($"Courier {request.CourierId} was not updated."); return(new Result <Courier> { Reason = ReasonType.DatabaseError, ChangeCount = changes, IsSuccessful = false }); } var address = await _db.Addresses.FindAsync(courier.AddressId); Log.Information($"Order {request.OrderId} and courier {request.CourierId} information was updated."); return(new Result <Courier> { ChangeCount = changes, Value = MapEntity(courier, address), IsSuccessful = true }); }
public IActionResult Add([FromBody] Payment model) { try { if (db.Payments.Any(s => s.id == model.id)) { var item = db.Payments.SingleOrDefault(s => s.id == model.id); item.sum = model.sum; db.Update(item); db.SaveChanges(); } } catch (Exception ex) { return(BadRequest(ex.Message)); } return(RedirectToAction("Payments")); }
public async Task UpdateAsync <T>(T resource) { _ordersDb.Entry(resource).State = EntityState.Modified; _ordersDb.Update(resource); }
public void UpdateOrder(Order order) { _context.Update(order); _context.Entry(order).State = Microsoft.EntityFrameworkCore.EntityState.Modified; }
public void Update(Order model) { _dbContext.Update(model); _dbContext.SaveChanges(); }
public async Task Update(T entity) { _context.Update <T>(entity); await _context.SaveChangesAsync(); }