public async Task <Unit> Update(ToGoOrder order) { _dbContext.ToGoOrders.Update(order); await _dbContext.SaveChangesAsync(); return(Unit.Value); }
private Task <Unit> PersistOrder(ToGoOrder order, IList <MenuItem> orderedItems) { order.OrderedItems = orderedItems .Select(i => new ToGoOrderMenuItem { Id = Guid.NewGuid(), MenuItemId = i.Id, OrderId = order.Id }) .ToList(); return(_toGoOrderRepository.Add(order)); }
public async Task Add_WhenAddingNavigationEntities_Works() { var order = new ToGoOrder { CreatedDate = DateTime.Now, Name = "The 1st Order", }; _unitOfWork .GetRepository <ToGoOrderItem>() .AddRange(new[] { new ToGoOrderItem { Name = "Beef Burger", Size = Size.Big, Order = order }, new ToGoOrderItem { Name = "Chicken Burger", Size = Size.Small, Order = order } }); await _unitOfWork.SaveAsync(); var queryOrder = _unitOfWork .GetRepository <ToGoOrder>() .Query() .SingleOrDefault(); Assert.IsNotNull(queryOrder); Assert.AreEqual(order.Name, queryOrder.Name); Assert.AreEqual(order.CreatedDate, queryOrder.CreatedDate); }
protected async Task <Option <Unit, Error> > SetOrderStatus(ToGoOrderStatus status, ToGoOrder order) { order.Status = status; await ToGoOrderRepository.Update(order); return(Unit.Value.Some <Unit, Error>()); }
protected Option <ToGoOrderStatus, Error> OrderMustHaveStatus(ToGoOrderStatus expectedStatus, ToGoOrder order) => order.Status .SomeWhen( status => status == expectedStatus, Error.Validation($"The order must have a status of '{Enum.GetName(typeof(ToGoOrderStatus), expectedStatus)}'."));
private async Task <Unit> AssignOrderToBaristaIfAny(Option <Guid> baristaIdOption, ToGoOrder order) { await baristaIdOption.MapAsync( async baristaId => { var barista = (await _baristaRepository .Get(baristaId)) .ValueOr(() => throw new InvalidOperationException( $"Tried to assign an order to an unexisting barista. (id: {baristaId}) " + $"It is very likely that the claim assigning logic is broken.")); barista.CompletedOrders.Add(order); await _baristaRepository.Update(barista); return(Unit.Value); }); return(Unit.Value); }