public async Task <Order> GetAsync(int orderId) { var order = await _context .Orders .Include(x => x.Address) .FirstOrDefaultAsync(o => o.Id == orderId); if (order == null) { order = _context .Orders .Local .FirstOrDefault(o => o.Id == orderId); } if (order != null) { await _context.Entry(order) .Collection(i => i.OrderItems).LoadAsync(); await _context.Entry(order) .Reference(i => i.OrderStatus).LoadAsync(); } return(order); }
public Order Get(int orderId) { var order = _context.Orders.Find(orderId); if (order != null) { _context.Entry(order) .Collection(o => o.OrderItems).Load(); } return(order); }
public async Task <Order> FindAsycn(int orderId) { var order = await context.Orders.FindAsync(orderId); if (order != null) { await context.Entry(order) .Collection(i => i.OrderItems).LoadAsync(); await context.Entry(order) .Reference(i => i.Address).LoadAsync(); } return(order); }
public async Task <Order> GetAsync(int orderId) { var order = await _context.Orders.FindAsync(orderId); if (order != null) { await _context.Entry(order).Collection(e => e.OrderItems).LoadAsync(); await _context.Entry(order).Reference(e => e.OrderStatus).LoadAsync(); await _context.Entry(order).Reference(e => e.Address).LoadAsync(); } return(order); }
public async Task <IActionResult> PutCategoryInfo([FromRoute] long id, [FromBody] CategoryInfo categoryInfo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != categoryInfo.Id) { return(BadRequest()); } _context.Entry(categoryInfo).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryInfoExists(id)) { return(NotFound()); } throw; } return(NoContent()); }
public void Update(Domain.Table item) { var entity = EntityFrom(item); var existingEntity = context.Tables.FirstOrDefault(e => e.Id == entity.Id) ?? throw new ArgumentException($"The table {entity.Id} was not found"); logger.Log(context, "Table", "Update", existingEntity, entity); context.Entry(existingEntity).CurrentValues.SetValues(entity); context.SaveChanges(); }
//添加订单操作 public static void AddOrder(Order order) { //if (orders.Contains(order)) //{ // throw new ApplicationException($"the order {order.OrderId} already exists!"); //} //orders.Add(order); using (var db = new OrderingContext()) { db.Entry(order).State = EntityState.Added; db.SaveChanges(); } }
public ActionResult Edit(int id, Customer customer) { //customer.FirstName = "Test"; try { using (OrderingContext context = new OrderingContext()) { context.Entry(customer).State = EntityState.Modified; context.SaveChanges(); } return(RedirectToAction("Index")); } catch { return(View()); } }
public void Update(Domain.Order item) { var entity = EntityFrom(item); var existingEntity = context.Orders .Include(e => e.Lines) .FirstOrDefault(e => e.Id == entity.Id) ?? throw new ArgumentException($"The order {entity.Id} was not found"); if (existingEntity.Closed) { throw new InvalidOperationException($"The order {entity.Id} has already been closed"); } logger.Log(context, "Order", "Update", existingEntity, entity); context.Entry(existingEntity).CurrentValues.SetValues(entity); existingEntity.Table = entity.Table; existingEntity.Lines.Clear(); existingEntity.Lines.AddRange(entity.Lines); context.SaveChanges(); }
public void Update(Purchaser purchaser) { context.Entry(purchaser).State = EntityState.Modified; }
public void Update(Order order) { _context.Entry(order).State = EntityState.Modified; }
public SalesOrder UpdateOrder(SalesOrder orderToUpdate) { var existingOrder = _orderingContext.SalesOrders .Include(x => x.Customer) .Include(x => x.SalesStatus) .Include(x => x.Details).ThenInclude(x => x.Product) .FirstOrDefault(so => so.SalesOrderId == orderToUpdate.SalesOrderId); if (existingOrder is null) { return(null); } _orderingContext.Entry(existingOrder).CurrentValues.SetValues(orderToUpdate); UpdateCustomer(); UpdateSalesStatus(); UpdateSalesOrderDetailCollection(); _orderingContext.SaveChanges(); return(orderToUpdate); void UpdateCustomer() { if (!_orderingContext.Customers.Local.Any(c => c.CustomerId == orderToUpdate.Customer.CustomerId)) { _orderingContext.Attach(orderToUpdate.Customer); } existingOrder.Customer = _orderingContext.Customers.Local.First(c => c.CustomerId == orderToUpdate.Customer.CustomerId); } void UpdateSalesStatus() { if (!_orderingContext.SalesStatuses.Local.Any(s => s.SalesStatusId == orderToUpdate.SalesStatus.SalesStatusId)) { _orderingContext.Attach(orderToUpdate.SalesStatus); } existingOrder.SalesStatus = _orderingContext.SalesStatuses.Local.First(s => s.SalesStatusId == orderToUpdate.SalesStatus.SalesStatusId); } void UpdateSalesOrderDetailCollection() { const int UndefinedDetailId = 0; foreach (var detail in orderToUpdate.Details) { if (!_orderingContext.Products.Local.Any(p => p.ProductId == detail.Product.ProductId)) { _orderingContext.Attach(detail.Product); } if (detail.Id == UndefinedDetailId) { existingOrder.Details.Add(detail); } else { var existingDetail = existingOrder.Details.First(sod => sod.Id == detail.Id); _orderingContext.Entry(existingDetail).CurrentValues.SetValues(detail); existingDetail.Product = _orderingContext.Products.Local.First(p => p.ProductId == detail.Product.ProductId); } } foreach (var existingDetail in existingOrder.Details) { if (!orderToUpdate.Details.Any(sod => sod.Id == existingDetail.Id)) { _orderingContext.Remove(existingDetail); } } } }
public Customer Update(Customer customer) { _dbContext.Entry(customer).State = EntityState.Modified; return(_dbContext.Entry(customer).Entity); }