Esempio n. 1
0
 public GetProductsQueryHandler(FoodContext context, IConfiguration configuration, ILogger <GetProductsQueryHandler> logger, IValidator <GetProductsQuery> validator)
 {
     _context       = context;
     _configuration = configuration;
     _logger        = logger;
     _validator     = validator;
 }
Esempio n. 2
0
 public AddProductCommandHandler(IConfiguration configuration, ILogger <AddProductCommandHandler> logger, IValidator <AddProductCommand> validator, FoodContext context)
 {
     _configuration = configuration;
     _logger        = logger;
     _validator     = validator;
     _context       = context;
 }
Esempio n. 3
0
        public FoodsController(FoodContext context)
        {
            _context = context;

            if (_context.Foods.Count() == 0)
            {
                _context.Foods.Add(new Foods
                {
                    Food_id     = 1,
                    FoodName    = "CLUB STEAK",
                    description = "The tasties part of the sirloin, the center cut. 13oz broiled",
                    price       = 20
                });
                _context.Foods.Add(new Foods
                {
                    Food_id     = 2,
                    FoodName    = "PORTER HOUSE",
                    description = "The perfect combination. This 26 oz steak.",
                    price       = 40
                });
                _context.Foods.Add(new Foods
                {
                    Food_id     = 3,
                    FoodName    = "BONE-IN RIB EYE",
                    description = "24 ounces of the juiciest, tastiest beef around",
                    price       = 32
                });
                _context.SaveChanges();
            }
        }
Esempio n. 4
0
 public static void Initialize(IConfiguration configuration)
 {
     using (var context = new FoodContext(configuration))
     {
         context.Database.Migrate();
     }
 }
Esempio n. 5
0
        private void AutoComplete_Populating(object sender, PopulatingEventArgs e)
        {
            // Search for matching foods and make sure that the ServingSize information is returned

            FoodContext autocompleteContext = new FoodContext();

            AutoComplete.ItemsSource = autocompleteContext.Foods;

            autocompleteContext.Load <FitnessTrackerPlus.Web.Data.Food>(autocompleteContext.SearchFoodsQuery(Globals.CurrentUser.id, Globals.MaxAutoCompleteResults, AutoComplete.Text, true),
                                                                        LoadBehavior.RefreshCurrent,
                                                                        (FoodsLoaded) =>
            {
                if (!FoodsLoaded.HasError)
                {
                    AutoComplete.PopulateComplete();

                    if (FoodsLoaded.TotalEntityCount == 0)
                    {
                        SearchingText.Text = "No foods found";
                    }
                }
            }, null);

            e.Cancel = true;
        }
        public async Task GivenRepoWhenExistingItemThenItemIsUpdated()
        {
            FoodDescription item;
            DateTimeOffset  date;

            using (var ctx = new FoodContext())
            {
                item = ctx.FoodDescriptions.AsNoTracking().FirstOrDefault();
                date = item.SomeDate;
            }

            using (var unit = new WorkUnit(Thread.CurrentPrincipal))
            {
                var repo = new FoodDescriptionRepo();
                item.SomeDate = date.AddDays(1);
                var success = await repo.UpdateOrAddFoodDescriptionAsync(unit, item);

                Assert.IsNotNull(success, "Test failed: operation should have returned the item.");
                await unit.CommitAsync();
            }

            using (var ctx = new FoodContext())
            {
                var actual = ctx.FoodDescriptions.FirstOrDefault(f => f.Id == item.Id);
                Assert.IsNotNull(actual, "Test failed: unable to obtain the item.");
                Assert.AreNotEqual(date, actual.SomeDate, "Test failed: the date was not updated.");
            }
        }
Esempio n. 7
0
 public FoodsController(FoodContext db)
 {
     this.db = db;
     if (this.db.Foods.Count() == 0)
     {
         this.db.Foods.Add(new Food()
         {
             Id          = 1,
             Name        = "Pork",
             Description = "Delicious braised pork",
             Price       = 12,
             Quantity    = 1,
             image       = "assets/pork.jpg",
             Seller      = "David",
             PlaceToMeet = "Ohio Union"
         });
         this.db.Foods.Add(new Food()
         {
             Id          = 2,
             Name        = "Chicken",
             Description = "General Tso Chicken",
             Price       = 10,
             Quantity    = 1,
             image       = "assets/chicken.jpg",
             Seller      = "David",
             PlaceToMeet = "Ohio Union"
         });
     }
     this.db.SaveChanges();
 }
Esempio n. 8
0
        public async Task AddNewFood()
        {
            //arrange
            var options = new DbContextOptionsBuilder <FoodContext>().UseInMemoryDatabase(databaseName: "FoodTestDb").Options;

            using (var dbContext = new FoodContext(options))
            {
                var quoteRepository = new FoodRepository(dbContext);

                //act
                dbContext.Foods.Add(new Food()
                {
                    Name    = "Orange",
                    Amount  = 1,
                    Calorie = 120
                });
                dbContext.SaveChanges();

                //assert
                string expected = "Orange";
                var    quote    = await dbContext.Foods.FirstOrDefaultAsync(f => f.Name.Equals("Orange"));

                Assert.Equal(expected, quote.Name);
            }
        }
        public async Task GivenRepoWhenDeleteCalledThenItemIsRemoved()
        {
            var id = string.Empty;

            using (var ctx = new FoodContext())
            {
                var description = TestHelper.GetNewFoodDescription();
                id = description.Id;
                ctx.FoodDescriptions.Add(description);
                await ctx.SaveChangesAsync();
            }

            using (var unit = new WorkUnit(Thread.CurrentPrincipal))
            {
                var repo    = new FoodDescriptionRepo();
                var success = await repo.DeleteFoodDescriptionAsync(unit, id);

                Assert.IsTrue(success, "Test failed: operation should have returned true.");
                await unit.CommitAsync();
            }

            using (var ctx = new FoodContext())
            {
                var exists = ctx.FoodDescriptions.Any(f => f.Id == id);
                Assert.IsFalse(exists, "Test failed: item was not deleted.");
            }
        }
Esempio n. 10
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "FoodsOrderAPI");
                c.RoutePrefix = string.Empty;
            });
            using var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope();
            FoodContext context = serviceScope.ServiceProvider.GetRequiredService <FoodContext>();

            DataInitializer.SeedData(context).Wait();


            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
        private void Seed(FoodContext context)
        {
            var categories = new[]
            {
                new Category()
                {
                    Name = "TestCategory", Id = 1
                },
            };

            var products = new[]
            {
                new Product {
                    Calories = 122, CarbsGrams = 11, FatsGrams = 22, ProteinsGrams = 33, Name = "Cheese"
                },
                new Product {
                    Calories = 112, CarbsGrams = 21, FatsGrams = 33, ProteinsGrams = 23, Name = "Ham"
                },
            };


            var meals = new[]
            {
                new Meal {
                    Name = "TestMeal", Category = categories.First()
                },
            };

            context.Products.AddRange(products);
            context.Categories.AddRange(categories);
            context.Meals.AddRange(meals);
            context.SaveChanges();
        }
Esempio n. 12
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 /// <param name="configuration">設定</param>
 /// <param name="logger">ロガー</param>
 public JsonTestController(IConfiguration configuration, ILogger <FoodController> logger, FoodContext context)
 {
     this.configuration = configuration;
     this.logger        = logger;
     this.context       = context;
     context.Database.EnsureCreatedAsync();
 }
Esempio n. 13
0
 public void Effect(FoodContext context)
 {
     context.Map.All.Remove(this);
     context.Map.Ghosts.ToList().ForEach(ghost => ghost.Frighten());
     context.GameState.UpScore(50);
     context.EventSink.Publish(new PelletEaten(true));
 }
Esempio n. 14
0
 public EditMealCommandHandler(FoodContext context, IConfiguration configuration, ILogger <EditMealCommandHandler> logger, IValidator <EditMealCommand> validator)
 {
     _context       = context;
     _configuration = configuration;
     _logger        = logger;
     _validator     = validator;
 }
Esempio n. 15
0
 public void Execute()
 {
     using (FoodContext dbContext = new FoodContext(dbOptions))
     {
         dbContext.Sessions.RemoveRange(dbContext.Sessions.Where(s => s.expires <= DateTime.UtcNow));
         dbContext.SaveChanges();
     }
 }
Esempio n. 16
0
 public void Setup()
 {
     _options = new DbContextOptionsBuilder <FoodContext>().UseInMemoryDatabase(databaseName: "FitLifeInMemory").Options;
     _context = new FoodContext(_options);
     _logger  = new Mock <ILogger <AddProductCommandHandler> >();
     _config  = new Mock <IConfiguration>();
     _context.Database.EnsureDeleted();
 }
Esempio n. 17
0
 public void AddMenu(Menu menu)
 {
     using (var db = new FoodContext())
     {
         db.Menus.Add(menu);
         db.SaveChanges();
     }
 }
Esempio n. 18
0
 public void AddOrder(Order order)
 {
     using (var db = new FoodContext())
     {
         db.Orders.Add(order);
         db.SaveChanges();
     }
 }
Esempio n. 19
0
 public IEnumerable <Food.Models.Food> GetFoodsById(int id)
 {
     using (var db = new FoodContext())
     {
         var foods = db.Foods.Where(f => f.Id == id).ToList();
         return(foods);
     }
 }
Esempio n. 20
0
 /// <summary>
 /// Constructor from Database
 /// </summary>
 /// <param name="meal"></param>
 public ReadyMeal(Meal meal, FoodContext foodContext)
 {
     _db = foodContext;
     FoodAndWeightList = new List <FoodIdWeightPair>();
     Origin            = meal;
     FoodAndWeightList = (List <FoodIdWeightPair>)JsonConvert.DeserializeObject <IEnumerable <FoodIdWeightPair> >(Origin.FoodsAndWeightJson);
     Reset();
 }
Esempio n. 21
0
 public IEnumerable <Food.Models.Food> GetFoods()
 {
     using (var db = new FoodContext())
     {
         var foods = db.Foods.ToList();
         return(foods);
     }
 }
Esempio n. 22
0
 public Food.Models.Food GetFoodById(int id)
 {
     using (var db = new FoodContext())
     {
         var food = db.Foods.FirstOrDefault(f => f.Id == id);
         return(food);
     }
 }
Esempio n. 23
0
 public MenuDetail GetMenuDetailById(int id)
 {
     using (var db = new FoodContext())
     {
         var menuDetail = db.MenuDetails.FirstOrDefault(md => md.Id == id);
         return(menuDetail);
     }
 }
Esempio n. 24
0
 public void AddMenuDetail(MenuDetail menuDetail)
 {
     using (var db = new FoodContext())
     {
         db.MenuDetails.Add(menuDetail);
         db.SaveChanges();
     }
 }
Esempio n. 25
0
 public void RemoveMenuDetail(MenuDetail menuDetail)
 {
     using (var db = new FoodContext())
     {
         var menuDetailToRemove = db.MenuDetails.FirstOrDefault(m => m.Id == menuDetail.Id);
         db.MenuDetails.Remove(menuDetailToRemove);
         db.SaveChanges();
     }
 }
Esempio n. 26
0
 public void EditMenuDetail(MenuDetail menuDetail)
 {
     using (var db = new FoodContext())
     {
         db.MenuDetails.Attach(menuDetail);
         db.Entry(menuDetail).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Esempio n. 27
0
 public List <MenuDetail> GetMenuDetailByMenu(int menuId)
 {
     using (var db = new FoodContext())
     {
         return(db.MenuDetails
                .Where(md => md.MenuId == menuId)
                .ToList());
     }
 }
Esempio n. 28
0
 public void GivenContextWhenFoodDescriptionsFetchedThenShouldReturnList()
 {
     using (var ctx = new FoodContext())
     {
         var list = ctx.FoodDescriptions.ToList();
         Assert.IsNotNull(list, "Test failed: list should exist.");
         Assert.IsTrue(list.Count > 0, "Test failed: at least one item should exist.");
     }
 }
Esempio n. 29
0
 public void RemoveOrder(Order order)
 {
     using (var db = new FoodContext())
     {
         var orderToRemove = db.Orders.FirstOrDefault(o => o.Id == order.Id);
         db.Orders.Remove(orderToRemove);
         db.SaveChanges();
     }
 }
Esempio n. 30
0
 public void EditOrder(Order order)
 {
     using (var db = new FoodContext())
     {
         db.Orders.Attach(order);
         db.Entry(order).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
Esempio n. 31
0
 public Repository()
 {
     try
     {
         dbContext = new FoodContext();
     }
     catch (Exception ex)
     {
         ErrorLogger.LogException(ex);
     }
 }