public void TestQueryFilterWorksOnShopStock()
        {
            //SETUP
            var options = SqliteInMemory.CreateOptions <CompanyDbContext>();

            using (var context = new CompanyDbContext(options, new FakeGetClaimsProvider("accessKey*")))
            {
                context.Database.EnsureCreated();
                var company = Company.AddTenantToDatabaseWithSaveChanges("TestCompany", PaidForModules.None, context);
                var shop    = RetailOutlet.AddTenantToDatabaseWithSaveChanges("TestShop", company, context);
                var stock   = new ShopStock {
                    Name = "dress", NumInStock = 5, Shop = shop
                };
                context.Add(stock);
                context.SaveChanges();

                var utData  = context.SetupSingleDtoAndEntities <SellItemDto>();
                var service = new CrudServices(context, utData.ConfigAndMapper);

                //ATTEMPT
                var dto = new SellItemDto
                {
                    TenantItemId = shop.TenantItemId,
                    ShopStockId  = stock.ShopStockId,
                    NumBought    = 1
                };
                var shopSale = service.CreateAndSave(dto);

                //VERIFY
                service.IsValid.ShouldBeTrue(service.GetAllErrors());
                context.ShopSales.Count().ShouldEqual(1);
                context.ShopStocks.Single().NumInStock.ShouldEqual(4);
            }
        }
        public IActionResult Till([FromServices] ICrudServices <CompanyDbContext> service)
        {
            var dto = new SellItemDto();

            dto.SetResetDto(service.ReadManyNoTracked <StockSelectDto>().ToList());
            return(View(dto));
        }
        public IActionResult Till([FromServices] ICrudServices <CompanyDbContext> service, SellItemDto dto)
        {
            if (!ModelState.IsValid)
            {
                dto.SetResetDto(service.ReadManyNoTracked <StockSelectDto>().ToList());
                return(View(dto));
            }

            var result = service.CreateAndSave(dto);

            if (service.IsValid)
            {
                return(RedirectToAction("BuySuccess", new { message = service.Message, result.ShopSaleId }));
            }

            //Error state
            service.CopyErrorsToModelState(ModelState, dto);
            dto.SetResetDto(service.ReadManyNoTracked <StockSelectDto>().ToList());
            return(View(dto));
        }