public Item UpdateItem(Item itemToUpdate) { var item = _context.Items.Find(itemToUpdate.ItemID); _context.Attach(item); item.Name = itemToUpdate.Name; item.Price = itemToUpdate.Price; item.Description = itemToUpdate.Description; item.Amount = itemToUpdate.Amount; _context.SaveChanges(); return(item); }
public async Task <PayOrderResult> HandleAsync(PayOrderCommand command, CancellationToken cancellationToken) { var order = await _dbContext.Orders .SingleAsync(o => o.OrderId == command.OrderId, cancellationToken) .ConfigureAwait(false); order.Status = OrderStatus.Payed; _dbContext.Attach(order); await _dbContext.SaveChangesAsync(cancellationToken); await _bus.Publish( new OrderHasBeenPayed(command.OrderId), cancellationToken).ConfigureAwait(false); return(new PayOrderResult { Message = "Some message in pay order result" }); }
public async Task HandleAsync(AddOrderContactsCommand command, CancellationToken cancellationToken) { var order = await _context.Orders .SingleAsync(o => o.OrderId == command.OrderId, cancellationToken) .ConfigureAwait(false); order.Name = command.Name; order.Email = command.Email; order.Phone = command.Phone; _context.Attach(order); await _context.SaveChangesAsync(cancellationToken); await _bus.Publish( new OrderContactsAdded( command.OrderId, command.Name, command.Email, command.Phone), cancellationToken); }