public string GetDescripion(MealType mealType) { string prefix; switch (mealType) { case MealType.Price: prefix = string.Empty; break; case MealType.Chicken: prefix = "Chicken "; break; case MealType.Lamb: prefix = "Lamb "; break; case MealType.Vegetable: prefix = "Veg. "; break; case MealType.Prawn: prefix = "Prawn "; break; case MealType.KingPrawn: prefix = "King Prawn "; break; default: throw new ArgumentOutOfRangeException(); } return prefix + Title; }
public override bool ValidateOrder(MealType mealType) { if (!Enum.IsDefined(typeof(MealType), mealType)) return false; // At night, you can have multiple orders of potatoes return mealType == MealType.Side || OrderedItems.Count(x => x.MealType == mealType) == 0; }
public override bool ValidateOrder(MealType mealType) { if (!Enum.IsDefined(typeof(MealType), mealType)) return false; // There is no dessert for morning meals // In the morning, you can order multiple cups of coffee return mealType != MealType.Dessert && (mealType == MealType.Drink || OrderedItems.Count(x => x.MealType == mealType) == 0); }
public ActionResult Edit([Bind(Include = "MealTypeID,Name")] MealType mealType) { if (ModelState.IsValid) { db.Entry(mealType).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mealType)); }
public void TestMealTypeNameReturnsStringPassedOnValueOf() { string name = ExistingMealTypesService.ExistingMealTypes[0]; MealType type = MealType.ValueOf(name); string mealTypeName = type.Name; Assert.Equal(name, mealTypeName); }
public void TestMealTypeDoesNotProveEqualityToDifferentClassObject() { string name = ExistingMealTypesService.ExistingMealTypes[0]; MealType mealType = MealType.ValueOf(name); object differentClassObject = ""; Assert.NotEqual(mealType, differentClassObject); }
// // GET: /MealType/Delete/5 public ActionResult Delete(int id = 0) { MealType mealtype = db.MealTypes.Find(id); if (mealtype == null) { return(HttpNotFound()); } return(View(mealtype)); }
public void TestMealTypeProvesEqualityToMealTypeWithEqualName() { string name = ExistingMealTypesService.ExistingMealTypes[0]; MealType mealType = MealType.ValueOf(name); MealType equalMealType = MealType.ValueOf(name); Assert.Equal(mealType, equalMealType); }
public RepositoryActionResult <MealType> UpdateMealType(MealType entity) { return(RepositoryActionResultExtensions <MealType, sRecipeContext> .Update(_ctx, _ctx.MealTypes .Where(s => s.Id == entity.Id) .FirstOrDefault(), entity )); }
/// <summary> /// This method returns the best restaurant services according to the input orders and their avaiable capacity. /// </summary> /// <param name="orders">List of orders.</param> /// <param name="restaurants">List of restaurants</param> /// <returns>Result of how orders are provided by restaurants.</returns> public List <Result> GetBestService(Dictionary <MealType, int> orders, List <Restaurant> restaurants) { var results = new List <Result>(); if (orders == null || restaurants == null) { return(results); } // sorts restuarants by rate var orderedRestaurants = restaurants.OrderByDescending(res => res.Rate).AsQueryable(); MealType[] orderedMealTypes = new MealType[orders.Count]; orders.Keys.CopyTo(orderedMealTypes, 0); // chooses restaurants by rate ascending foreach (var restaurant in orderedRestaurants) { var result = new Result(); result.Restaurant = restaurant; var meals = new Dictionary <MealType, int>(); foreach (var mealType in orderedMealTypes) { int requestedMeals = orders[mealType]; int availableMeals; restaurant.AvailableMeals.TryGetValue(mealType, out availableMeals); if (availableMeals == 0) { continue; } if (availableMeals < requestedMeals) { int providedMeals = requestedMeals - availableMeals; meals.Add(mealType, availableMeals); orders[mealType] = providedMeals; restaurant.AvailableMeals[mealType] = 0; } else { meals.Add(mealType, requestedMeals); orders[mealType] = 0; restaurant.AvailableMeals[mealType] = availableMeals - requestedMeals; } } if (meals.Count != 0) { result.ProvidedFoods = meals; results.Add(result); } } return(results); }
public async Task <IActionResult> Create([Bind("MealTypeId,MealTypeName,ShelfLocation")] MealType mealType) { if (ModelState.IsValid) { _context.Add(mealType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(mealType)); }
private void assertOrderShouldReturnMealNameAndTypeIfValidationPass(MealType mealType, string expectedNameResult) { var abstractMealOrder = new MockedMealOrder(new MockedMealMenu(), true); abstractMealOrder.Order(mealType); Assert.AreEqual(1, abstractMealOrder.BaseOrderedItems.Count); var addedItem = abstractMealOrder.BaseOrderedItems.First(); Assert.AreEqual(expectedNameResult, addedItem.MealName); Assert.AreEqual(mealType, addedItem.MealType); }
public ActionResult Create(MealType mealtype) { if (ModelState.IsValid) { db.MealTypes.Add(mealtype); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mealtype)); }
public int InsertOrUpdateMealType(MealType mt) { //Create the SQL Query for inserting an mt string createQuery = String.Format("Insert into MealTypes (FoodID, MealType) Values({0}, {1});" + "Select @@Identity", mt.FoodID, mt.Type); string updateQuery = String.Format("Update MealTypes SET FoodID={0}, MealType={1} Where MealTypeID = {2};", mt.FoodID, mt.Type, mt.MealTypeID); //Create and open a connection to SQL Server SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["sports_db"].ConnectionString); connection.Open(); //Create a Command object SqlCommand command = null; // new SqlCommand(createQuery, connection); if (mt.MealTypeID != 0) { command = new SqlCommand(updateQuery, connection); } else { command = new SqlCommand(createQuery, connection); } int savedMtID = 0; try { //Execute the command to SQL Server and return the newly created ID var commandResult = command.ExecuteScalar(); if (commandResult != null) { savedMtID = Convert.ToInt32(commandResult); } else { //the update SQL query will not return the primary key but if doesn't throw exception //then we will take it from the already provided data savedMtID = mt.MealTypeID; } } catch (Exception) { //there was a problem executing the script } //Close and dispose CloseAndDispose(command, connection); // Set return value return(savedMtID); }
private static Meal GetMealFromDR(NpgsqlDataReader dr) { int intMealID = Convert.ToInt32(dr["intMealID"]); MealType mealType = (MealType)Enum.Parse(typeof(MealType), dr["mealType"].ToString()); int intUserID = Convert.ToInt32(dr["intUserID"]); List <FoodItem> lstContents = FoodItemDAL.GetFoodByMealAndUser(intMealID, intUserID); Meal meal = Meal.of(intMealID, mealType, lstContents); return(meal); }
public Food(int id, string name, int calories, double fat, double protein, double carbs, int[] allergies, MealType type) { this.id = id; this.name = name; this.calories = calories; this.fat = fat; this.protein = protein; this.carbs = carbs; this.allergies = allergies; this.type = type; }
public void ConstructorTest() { // Arrange MealType testMealType = MealType.Breakfast; // Act Meal testMeal = new Meal(testMealType); // Assert Assert.AreEqual(testMealType, testMeal.ThisMealType); }
public ActionResult Create([Bind(Include = "MealTypeID,Name")] MealType mealType) { if (ModelState.IsValid) { db.MealTypes.Add(mealType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(mealType)); }
private List <Meal> parseMeals(HtmlNodeCollection htmlNodes, MealType mealType) { var meals = new List <Meal>(); foreach (HtmlNode node in htmlNodes) { var tbody = node.SelectSingleNode("./tbody"); if (tbody == null) // sometimes the tbody is ommited { tbody = node; } for (int i = 0; i < tbody.ChildNodes.Count; i++) { if (tbody.ChildNodes[i].Name != "tr") { continue; } var tr = tbody.ChildNodes[i]; if (!tr.HasClass("j_radek1")) { logger.LogWarning($"First row in food table didn't have class 'j_radek1'. InnerText ({tbody.InnerText}), classes ({string.Join(", ", tr.GetClasses())})"); continue; } var mealName = tr.SelectSingleNode("./td[contains(@class, 'j_jidlo')]").InnerText.Trim(); mealName = spacesTrimmer.Replace(mealName, " "); var priceStr = tr.SelectSingleNode("./td[contains(@class, 'j_cena')]").InnerText.Trim(); int price = int.Parse(priceStr.Split(" ")[0]); var info = ""; // skip weird nodes while (i + 1 < tbody.ChildNodes.Count && tbody.ChildNodes[i + 1].Name != "tr") { i++; } if (i + 1 < tbody.ChildNodes.Count && tbody.ChildNodes[i + 1].HasClass("j_radek2")) { var infoTd = tbody.ChildNodes[i + 1].SelectSingleNode("./td[contains(@class, 'j_popis')]"); if (infoTd != null) { info = spacesTrimmer.Replace(infoTd.InnerText.Trim(), " "); } i++; } meals.Add(new Meal { Info = info, MealType = mealType, Name = mealName, Price = price }); } } return(meals); }
protected Meal(string products, MealType type, string name) { if (!Enum.IsDefined(typeof(MealType), type)) { throw new ArgumentException("The provided meal type is not valid!"); } this.Products = products ?? throw new ArgumentNullException("You must add some products!"); this.Type = type; //Guard.WhenArgument(name, "Name cannot be null or empty").IsNullOrWhiteSpace().Throw(); this.Name = name ?? throw new ArgumentNullException("Name cannot be null or empty"); }
public void CreateMeal() { var day = new DateTime(); var mealType = new MealType("Lunch", 1); var recipe = new Recipe("Soup", 3, new Ingredient[] { }); var testee = new Meal(day, mealType, recipe); testee.Day.Should().Be(day); testee.MealType.Should().Be(mealType); testee.Recipe.Should().Be(recipe); }
public ActionResult AddFoodToMeal(MealType mealType, DateTime dateTime) { var result = new AddFoodToMealViewModel(); var userId = User.Identity.GetUserId(); var viewModel = _unitOfWork.DailyMenus.GetDailyMenu(userId, dateTime); result.FoodModels = viewModel.FoodModels.Where(f => f.MealType == mealType).ToList(); result.Date = viewModel.DailyMenuDate; result.Id = viewModel.Id; result.MealType = mealType; return(View(result)); }
public async Task <IActionResult> Update(string id, MealType updatedMealType) { var queriedMealType = await _mealTypeService.GetByIdAsync(id); if (queriedMealType == null) { return(NotFound()); } await _mealTypeService.UpdateAsync(id, updatedMealType); return(NoContent()); }
async Task AddItem(MealType mealType) { FoodPerDay entry = new FoodPerDay() { MealType = mealType, Date = viewModel.Date, Time = viewModel.Date }; var repo = Injector.Resolve <IFoodRepository>(); await Navigation.PushModalAsync(new NavigationPage(new LogAddPage(new LogAddViewModel(repo, entry)))); }
public MenuRepositoryClass(string mealNumber, string mealName, string mealDescription, string mealListOfIngridients, double mealPrice, MealType typeOfMeal) //contructor { //property //parameter MealNumber = mealNumber; MealName = mealName; MealDescription = mealDescription; MealListOfIngridients = mealListOfIngridients; MealPrice = mealPrice; TypeOfMeal = typeOfMeal; }
public RecipeInfo(int difficultyLevel, int preparationTime, decimal approximateCost, int servings, MealType mealTypes) { DifficultyLevel = difficultyLevel; PreparationTime = preparationTime; ApproximateCost = approximateCost; Servings = servings; MealTypes = mealTypes; }
public void GetRecipesForMeals() { var mealType = new MealType("Lunch", 1); var meal1 = new Meal(new DateTime(), mealType, new Recipe("Recipe 1", 3, new Ingredient[] { })); var meal2 = new Meal(new DateTime(), mealType, new Recipe("Recipe 2", 3, new Ingredient[] { })); var meals = new[] { meal1, meal2 }; var testee = new GetRecipesForMealsAction(); var results = testee.GetRecipesForMeals(meals); results.Should().HaveCount(2); }
public bool isInputValid(string input, out MealType meal) { bool isOK = false; meal = MealType.NOTAVAILABLE; try { if (!string.IsNullOrEmpty(input)) { string[] inputArray = input.Split(',').ToArray(); if (inputArray.Length >= 4) { meal = this.GetMealType(inputArray[0]); if (meal != MealType.NOTAVAILABLE) { try { listDishes = new List <int>(); for (int i = 1; i < inputArray.Length; i++) { int dishNumber = 0; bool aux = int.TryParse(inputArray[i].ToString().Trim(), out dishNumber); if (aux) { listDishes.Add(dishNumber); } else { listDishes.Add(0); } } isOK = true; } catch (Exception e) { Console.WriteLine(e); } } } } } catch (Exception e) { Console.WriteLine(e.ToString()); } return(isOK); }
public void TestMealTypeHasSameHashCodeAsMealTypeWithEqualName() { string name = ExistingMealTypesService.ExistingMealTypes[0]; MealType mealType = MealType.ValueOf(name); MealType equalMealType = MealType.ValueOf(name); int mealTypeHashCode = mealType.GetHashCode(); int equalMealTypeHashCode = equalMealType.GetHashCode(); Assert.Equal(mealTypeHashCode, equalMealTypeHashCode); }
public void TestMealTypeHasDifferentHashCodeAsMealTypeWithEqualName() { string name = ExistingMealTypesService.ExistingMealTypes[0]; MealType mealType = MealType.ValueOf(name); MealType differentMealType = MealType.ValueOf(ExistingMealTypesService.ExistingMealTypes[1]); int mealTypeHashCode = mealType.GetHashCode(); int differentMealTypeHashCode = differentMealType.GetHashCode(); Assert.NotEqual(mealTypeHashCode, differentMealTypeHashCode); }
public static Meal.Meal CreateMeal(MealType type) { Meal.Meal meal = null; switch (type) { case MealType.MORNING: meal = MorningFactory.Create(); break; case MealType.NIGHT: meal = NightFactory.Create(); break; } return meal; }
public bool isInputValid(string input, out MealType meal) { bool isOK = false; meal = MealType.NOTAVAILABLE; try { if(!string.IsNullOrEmpty(input)) { string[] inputArray = input.Split(',').ToArray(); //Step 1, first item should have at least 4 itens if (inputArray.Length >= 4) { //Step 2, firt item show be Morning or Night meal = this.GetMealType(inputArray[0]); if (meal != MealType.NOTAVAILABLE) { //Step 3, the next itens should be number to 1 to 4 try { listDishes = new List<int>(); for (int i = 1; i < inputArray.Length; i++) { int dishNumber = 0; bool aux = int.TryParse(inputArray[i].ToString().Trim(), out dishNumber); if (aux) listDishes.Add(dishNumber); else listDishes.Add(0); } isOK = true; } catch (Exception e) { Framework.Log.Logger.Error(e); } } } } } catch (Exception e) { Console.WriteLine(e.ToString()); Framework.Log.Logger.Error(e); } return isOK; }
public static Meal Create(string name, DateTime date, MealType type = MealType.Other) { var meal = new Meal(); meal.SetName(name); meal.SetDate(date); meal.SetType(type); meal.Ingredients = new List <Ingredient>(); return(meal); }
public void Post_Creates_New_MealType() { var newMealType = new MealType(1, "New MealType"); var mealtypeList = new List <MealType>(); mealtypeRepo.When(t => t.Create(newMealType)) .Do(t => mealtypeList.Add(newMealType)); mealtypeRepo.GetAll().Returns(mealtypeList); var result = underTest.Post(newMealType); Assert.Contains(newMealType, result); }
private void RefreshData() { int fitem = cmbFilter.SelectedIndex; if (fitem == 0) { dgvMeals.DataSource = list; } else { MealType t = (MealType)fitem; dgvMeals.DataSource = list.FindAll(x => x.Type == t); } }
public void AddMealType(string name) { using (var db = this._settings.GeneralSettings.GetMealRecipeDbContext()) using (var tran = db.Database.BeginTransaction()) { var mt = new MealType { Name = name }; db.MealTypes.Add(mt); db.SaveChanges(); tran.Commit(); this.MealTypes.Add(mt); this._settings.DbChangeNotifier.Notify(nameof(db.MealTypes)); } }
private Order GetMealByType(MealType mealType) { switch (mealType) { case MealType.Entree: return new Order(mealType, MealMenu.GetAvailableEntree()); case MealType.Side: return new Order(mealType, MealMenu.GetAvailableSide()); case MealType.Drink: return new Order(mealType, MealMenu.GetAvailableDrink()); case MealType.Dessert: return new Order(mealType, MealMenu.GetAvailableDessert()); } throw new NotImplementedException(string.Format("Meal type not implemented. Meal type: {0}.", mealType)); }
public decimal GetPrice(MealType mealType) { decimal price; switch (mealType) { case MealType.Price: price = Price; break; case MealType.Chicken: price = ChickenPrice; break; case MealType.Lamb: price = LambPrice; break; case MealType.Vegetable: price = VegetablePrice; break; case MealType.Prawn: price = PrawnPrice; break; case MealType.KingPrawn: price = KingPrawnPrice; break; default: throw new ArgumentOutOfRangeException(); } return price; }
public override bool ValidateOrder(MealType mealType) { return _expectedValidation; }
public Order(MealType mealType, string mealName) { MealType = mealType; MealName = mealName; }
public abstract bool ValidateOrder(MealType mealType);
private void SeedMealTypes() { using (var context = new RestaurantsContext()) { var firstNewMealType = new MealType { Name = "Salad", Order = 10 }; var secondNewMealType = new MealType { Name = "Soup", Order = 20 }; context.MealTypes.Add(firstNewMealType); context.MealTypes.Add(secondNewMealType); context.SaveChanges(); this.firstMealTypeId = firstNewMealType.Id; this.secondMealTypeId = secondNewMealType.Id; } }
public MealDetails(Meal meal, MealType mealType) { _meal = meal; _mealType = mealType; }