protected void ReadAgain(Guid id)
 {
     using (var dbContext = new ExampleDbContext(_dbContextOptions))
     {
         var t = dbContext.Find <EfcThing>(id);
         Assert.That(t.Id, Is.EqualTo(id));
     }
 }
        public IActionResult HandCodedUpdate(int id, JsonPatchDocument <TodoItemHybrid> patch, [FromServices] ExampleDbContext context)
        {
            var entity = context.Find <TodoItemHybrid>(id);

            if (entity == null)
            {
                return(NoContent());
            }
            patch.ApplyTo(entity);
            context.SaveChanges();
            return(Ok());
        }
        public IStatusGeneric Handle(EntityEvents callingEntity, AllocateProductEvent domainEvent)
        {
            var status = new StatusGenericHandler();
            var stock  = _context.Find <ProductStock>(domainEvent.ProductName);

            if (stock == null)
            {
                throw new ApplicationException($"could not find the stock for product called {domainEvent.ProductName} ");
            }

            if (stock.NumInStock < domainEvent.NumOrdered)
            {
                return(status.AddError(
                           $"I could not accept this order because there wasn't enough {domainEvent.ProductName} in stock."));
            }

            stock.NumAllocated += domainEvent.NumOrdered;
            return(status);
        }
示例#4
0
        public async Task <ActionResult <Person> > PutPerson(int id, Person person)
        {
            if (id != person.Id)
            {
                return(NotFound());
            }

            if (_context.Find <Person>(id) != null)
            {
                _context.Update <Person>(person);
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            else
            {
                _context.Add <Person>(person);
                await _context.SaveChangesAsync();

                return(CreatedAtAction(nameof(GetPerson), new { person.Id }, person));
            }
        }
示例#5
0
        public IStatusGeneric Handle(EntityEvents callingEntity, OrderReadyToDispatchEvent domainEvent)
        {
            var status = new StatusGenericHandler();

            //Update the rate as the date may have changed
            domainEvent.SetTaxRatePercent(_rateFinder.GetTaxRateInEffect(domainEvent.ActualDispatchDate));

            var orderId = ((Order)callingEntity).OrderId;

            foreach (var lineItem in _context.LineItems.Where(x => x.OrderId == orderId))
            {
                var stock = _context.Find <ProductStock>(lineItem.ProductName);
                if (stock.NumInStock < lineItem.NumOrdered)
                {
                    return(status.AddError(
                               $"I could not dispatch this order because there wasn't enough {lineItem.ProductName} in stock."));
                }
                stock.NumAllocated -= lineItem.NumOrdered;
                stock.NumInStock   -= lineItem.NumOrdered;
            }

            return(status);
        }