public GetProductsQueryHandler(FoodContext context, IConfiguration configuration, ILogger <GetProductsQueryHandler> logger, IValidator <GetProductsQuery> validator) { _context = context; _configuration = configuration; _logger = logger; _validator = validator; }
public AddProductCommandHandler(IConfiguration configuration, ILogger <AddProductCommandHandler> logger, IValidator <AddProductCommand> validator, FoodContext context) { _configuration = configuration; _logger = logger; _validator = validator; _context = context; }
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(); } }
public static void Initialize(IConfiguration configuration) { using (var context = new FoodContext(configuration)) { context.Database.Migrate(); } }
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."); } }
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(); }
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."); } }
// 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(); }
/// <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(); }
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)); }
public EditMealCommandHandler(FoodContext context, IConfiguration configuration, ILogger <EditMealCommandHandler> logger, IValidator <EditMealCommand> validator) { _context = context; _configuration = configuration; _logger = logger; _validator = validator; }
public void Execute() { using (FoodContext dbContext = new FoodContext(dbOptions)) { dbContext.Sessions.RemoveRange(dbContext.Sessions.Where(s => s.expires <= DateTime.UtcNow)); dbContext.SaveChanges(); } }
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(); }
public void AddMenu(Menu menu) { using (var db = new FoodContext()) { db.Menus.Add(menu); db.SaveChanges(); } }
public void AddOrder(Order order) { using (var db = new FoodContext()) { db.Orders.Add(order); db.SaveChanges(); } }
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); } }
/// <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(); }
public IEnumerable <Food.Models.Food> GetFoods() { using (var db = new FoodContext()) { var foods = db.Foods.ToList(); return(foods); } }
public Food.Models.Food GetFoodById(int id) { using (var db = new FoodContext()) { var food = db.Foods.FirstOrDefault(f => f.Id == id); return(food); } }
public MenuDetail GetMenuDetailById(int id) { using (var db = new FoodContext()) { var menuDetail = db.MenuDetails.FirstOrDefault(md => md.Id == id); return(menuDetail); } }
public void AddMenuDetail(MenuDetail menuDetail) { using (var db = new FoodContext()) { db.MenuDetails.Add(menuDetail); db.SaveChanges(); } }
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(); } }
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(); } }
public List <MenuDetail> GetMenuDetailByMenu(int menuId) { using (var db = new FoodContext()) { return(db.MenuDetails .Where(md => md.MenuId == menuId) .ToList()); } }
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."); } }
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(); } }
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(); } }
public Repository() { try { dbContext = new FoodContext(); } catch (Exception ex) { ErrorLogger.LogException(ex); } }