public void TestCopyPartialDishesListToNewMenuPart_shouldCopyOnlySpecificDishesToOtherMenuPart_andSaveAllProptertiesIncludeDishId() { //arrange MenuPart copyFrom = new MenuPart() { Id = 13, OrderBy = 2, Name = "מנות עיקריות" }; MenuPart copyTo = new MenuPart(); Dish dish1 = new Dish() { Id = 1, Description = "סלט ירקות עם חתיכות חזה עוף", DishState = DishStateEnum.Active, Name = "סלט קיסר", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 30, Longitude = 27 }, ImageUrl = "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRqKcIkvCQDkCNQkXq0TWtiqRSF5ryYK7NYB79ZBVebpjKBVPcA", IsItPublic = true, MappedState = new SuspiciousState() { Index = 7.77 }, RecipeId = 10, State = new SuspiciousState() { Index = 7.77 }, OverrideIngredients = new List<Ingredient>() }; Dish dish2 = new Dish() { Id = 3, Description = "שניצל מוגש עם צ'יפס", DishState = DishStateEnum.Active, Name = "שניצל", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 31, Longitude = 29 }, ImageUrl = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQX5WBzP336hF8Q0FQpk5TdX8m7GI7ymVqJMtyrzSA3afEkqfU8CA", IsItPublic = true, MappedState = new SuspiciousState() { Index = 8.88 }, RecipeId = 28, State = new SuspiciousState() { Index = 8.88 }, OverrideIngredients = new List<Ingredient>() }; Dish dish3 = new Dish() { Id = 15, Description = "המבורגר 220גר עם צ'יפס בצד", DishState = DishStateEnum.Active, Name = "המבורגר", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 32, Longitude = 30 }, ImageUrl = "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTmEsDLKjW9dj_Vl8SMdESJkTBGncjY5QDt0sqK77txEUwSi2RzUA", IsItPublic = true, MappedState = new SuspiciousState() { Index = 50 }, RecipeId = 169, State = new SuspiciousState() { Index = 50 }, OverrideIngredients = new List<Ingredient>() }; copyFrom.Dishes.Add(dish1); copyFrom.Dishes.Add(dish2); copyFrom.Dishes.Add(dish3); CopyList copyList = new CopyList() { CopyFromId = "11111", MenuPartsCopyList = new List<MenuPartCopy>() }; //CopyFromList menuCopyFrom = new CopyFromList() //{ // RestaurantId = "11111", // CopyMenuPartList = new List<MenuPartCopy>() //}; copyList.MenuPartsCopyList.Add(new MenuPartCopy() { MenuPartId = 1, DishesIdsList = new List<int> { 1, 15 }, PartialCopy = true }); //CopyList copyList = new CopyList() { CopyFrom = menuCopyFrom }; //Create copy from data //act copyTo.CopyPartialMenuPart(copyList, copyFrom); //assert int tempDishId; for(int i=0; i < 2 ; i++) { tempDishId = copyList.MenuPartsCopyList[0].DishesIdsList[i]; string tempDishName = copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).Name; int newDishId = copyTo.Dishes.FirstOrDefault(c => c.Name == tempDishName).Id; Assert.IsNull(copyTo.Dishes.FirstOrDefault(c => c.Id == 3)); Assert.IsNotNull(copyTo.Dishes.FirstOrDefault(c => c.Name == tempDishName)); Assert.AreEqual(copyTo.Dishes.FirstOrDefault(c => c.Id == newDishId).Description, copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).Description); Assert.AreEqual(copyTo.Dishes.FirstOrDefault(c => c.Id == newDishId).RecipeId, copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).RecipeId); Assert.AreEqual(copyTo.Dishes.FirstOrDefault(c => c.Id == newDishId).State, copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).State); //check all other properties } }
/// <summary> /// Function copy partial MenuPart (dishes which Ids in CopyList) /// </summary> /// <param name="copyList"></param> /// <param name="copyFrom"></param> public void CopyPartialMenuPart(CopyList copyList, MenuPart copyFrom) { int tempDishId; //count of dishes to copy int copyCount = copyList.MenuPartsCopyList[0].DishesIdsList.Count; for (int i = 0; i < copyCount; i++) { tempDishId = copyList.MenuPartsCopyList[0].DishesIdsList[i]; Dish tempDish = new Dish(); tempDish.CopyFrom(copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId)); tempDish.Id = this.MaxDishId() + 1; tempDish.OrderBy = tempDish.Id; this.Dishes.Add(tempDish); } }
public void TestCopyPartialDishesListToMenuPart_shouldCopyOnlySpecificDishesToOtherMenuPart_LeaveExistingDishes_updateIdsForInsertedDishes() { //arrange MenuPart copyFrom = new MenuPart() { Id = 13, OrderBy = 2, Name = "מנות עיקריות" }; MenuPart copyTo = new MenuPart(); Dish dish1 = new Dish() { Id = 1, Description = "סלט ירקות עם חתיכות חזה עוף", DishState = DishStateEnum.Active, Name = "סלט קיסר", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 30, Longitude = 27 }, ImageUrl = "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRqKcIkvCQDkCNQkXq0TWtiqRSF5ryYK7NYB79ZBVebpjKBVPcA", IsItPublic = true, MappedState = new SuspiciousState() { Index = 7.77 }, RecipeId = 10, State = new SuspiciousState() { Index = 7.77 }, OverrideIngredients = new List<Ingredient>() }; Dish dish2 = new Dish() { Id = 3, Description = "שניצל מוגש עם צ'יפס", DishState = DishStateEnum.Active, Name = "שניצל", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 31, Longitude = 29 }, ImageUrl = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQX5WBzP336hF8Q0FQpk5TdX8m7GI7ymVqJMtyrzSA3afEkqfU8CA", IsItPublic = true, MappedState = new SuspiciousState() { Index = 8.88 }, RecipeId = 28, State = new SuspiciousState() { Index = 8.88 }, OverrideIngredients = new List<Ingredient>() }; Dish dish3 = new Dish() { Id = 15, Description = "המבורגר 220גר עם צ'יפס בצד", DishState = DishStateEnum.Active, Name = "המבורגר", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 32, Longitude = 30 }, ImageUrl = "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTmEsDLKjW9dj_Vl8SMdESJkTBGncjY5QDt0sqK77txEUwSi2RzUA", IsItPublic = true, MappedState = new SuspiciousState() { Index = 50 }, RecipeId = 169, State = new SuspiciousState() { Index = 50 }, OverrideIngredients = new List<Ingredient>() }; Dish dish4 = new Dish() { Id = 4, Description = "חזה עך עם תוספת", DishState = DishStateEnum.Active, Name = "חזה עוף", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 32.89654, Longitude = 31.321 }, IsItPublic = true, MappedState = new SuspiciousState() { Index = 45.5 }, RecipeId = 169, State = new SuspiciousState() { Index = 45.5 }, OverrideIngredients = new List<Ingredient>() }; Dish dish5 = new Dish() { Id = 7, Description = "סטייק פרגית עם תוספת", DishState = DishStateEnum.Active, Name = "סטייק פרגית", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 31.2222, Longitude = 30.3333 }, IsItPublic = true, MappedState = new SuspiciousState() { Index = 35}, RecipeId = 169, State = new SuspiciousState() { Index = 35 }, OverrideIngredients = new List<Ingredient>() }; copyFrom.Dishes.Add(dish1); copyFrom.Dishes.Add(dish2); copyFrom.Dishes.Add(dish3); copyTo.Dishes.Add(dish4); copyTo.Dishes.Add(dish5); CopyList copyList = new CopyList() { CopyFromId = "11111", MenuPartsCopyList = new List<MenuPartCopy>() }; copyList.MenuPartsCopyList.Add(new MenuPartCopy() { MenuPartId = 1, DishesIdsList = new List<int> { 1, 15 }, PartialCopy = true }); //Create copy from data //act copyTo.CopyPartialMenuPart(copyList, copyFrom); //assert Assert.AreEqual(4, copyTo.Dishes.Count); //Checks if copy function does not deleted existing dishes Assert.IsNotNull(copyTo.Dishes.FirstOrDefault(c => c.Name == "חזה עוף")); Assert.IsNotNull(copyTo.Dishes.FirstOrDefault(c => c.Name == "סטייק פרגית")); int tempDishId; for (int i = 0; i < copyList.MenuPartsCopyList[0].DishesIdsList.Count; i++) { tempDishId = copyList.MenuPartsCopyList[0].DishesIdsList[i]; string tempDishName = copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).Name; int newDishId = copyTo.Dishes.FirstOrDefault(c => c.Name == tempDishName).Id; //There is no Dish with id=3, which is not in CopyList Assert.IsNull(copyTo.Dishes.FirstOrDefault(c => c.Name == "שניצל")); Assert.IsNotNull(copyTo.Dishes.FirstOrDefault(c => c.Name == tempDishName)); //check all other properties } foreach(var dish in copyTo.Dishes) { //There is no Dishes with same Id Assert.AreEqual(copyTo.Dishes.Where(c => c.Id == dish.Id).Count(), 1); Assert.AreEqual(copyTo.Dishes.FindAll(c => c.Name == dish.Name).Count, 1); } }
public void CopySelectedDishes(CopyList copyList) { log.InfoFormat("[CopySelectedDishes] copyList={0} ", copyList.ToString()); foreach (var item in copyList.SelectedDishesList) { AddNewDishBasic(copyList.CopyToRestId, copyList.CopyToMenuPartId, GetDishBasic(copyList.MenuPartIdCopyFrom, copyList.CopyFromId, item)); } }
public void CopySelectedMemuParts(CopyList copyList) { log.DebugFormat("[CopySellectedMemuParts] menuCopy={0}.", copyList.ToString()); foreach (var item in copyList.MenuPartsSelectedListCopyFrom) { MenuPart temp = new MenuPart(); temp.CopyAllMenuPart(GetMenuPartBasic(item, copyList.CopyFromId)); AddNewMenuPartBasic(copyList.CopyToRestId, temp); } }
//========================================================================================== //Copy MenuPart //========================================================================================== public ActionResult SelectRestCopyMenuPartFrom(string restaurantId) { log.InfoFormat("[SelectRestCopyMenuPartFrom] RestaurantId={0}", restaurantId); CopyList copyList = new CopyList() { CopyToRestId = restaurantId, RestaurantsList = m_serviceLayer.GetAllRestaurantsInStringList() }; return View(copyList); }
public ActionResult SelectRestCopyMenuPartFromConfirmed(CopyList copyList) { copyList.CopyFromId = copyList.RestaurantsSelectedListCopyFrom[0]; if (m_serviceLayer.GetMenuListBasic(copyList.CopyFromId) == null) { copyList.RestaurantsList = m_serviceLayer.GetAllRestaurantsInStringList(); return View(copyList); } return RedirectToAction("SelectMenuPartsCopyFrom", copyList); }
public ActionResult SelectMenuPartsCopyFrom(CopyList copyList) { copyList.MenuList = m_serviceLayer.GetMenuListBasic(copyList.CopyFromId); return View(copyList); }
public ActionResult SelectMenuPartsCopyFromConfirmed(CopyList copyList) { m_serviceLayer.CopySelectedMemuParts(copyList); return RedirectToAction("Index", new { id = copyList.CopyToRestId }); }
public ActionResult SelectMenuPartCopyDishesFromConfirmed(CopyList copyList) { copyList.MenuPartIdCopyFrom = copyList.MenuPartsSelectedListCopyFrom[0]; return RedirectToAction("SelectDishes", copyList); }
public ActionResult SelectDishesConfirmed(CopyList copyList) { m_serviceLayer.CopySelectedDishes(copyList); return RedirectToAction("DishesIndex", new { MenuPartId=copyList.CopyToMenuPartId, RestaurantId=copyList.CopyToRestId }); }
public ActionResult SelectDishes(CopyList copyList) { copyList.DishList = m_serviceLayer.GetDishEntitiesList(copyList.CopyFromId, copyList.MenuPartIdCopyFrom); return View(copyList); }
public ActionResult SelectRestCopyMenuPartFromConfirmed(CopyList copyList) { log.InfoFormat("[SelectRestCopyMenuPartFromConfirmed] copyList.CopyFromId={0}, copyList.CopyToRestId={1}, copyList.PartialCopy={2}, copyList.CopyFromBackupDB={3}.", copyList.CopyFromId, copyList.CopyToRestId, copyList.PartialCopy, copyList.CopyFromBackupDB); try { if (copyList.CopyFromBackupDB) { RestaurantBasicData rest = m_serviceLayer.GetRestaurantBasicById(copyList.CopyToRestId); RestaurantBasicData backupDBRest = m_serviceLayer.GetRestaurantBasicByIdFromBackup(copyList.CopyToRestId); if (rest != null && backupDBRest != null && backupDBRest.Menu != null && backupDBRest.Menu.MenuParts.Count > 0) { rest.Menu = backupDBRest.Menu; m_serviceLayer.UpdateRestaurant(rest); } return RedirectToAction("Index", new { id = copyList.CopyToRestId }); } else { copyList.CopyFromId = copyList.RestaurantsSelectedListCopyFrom[0]; if (m_serviceLayer.GetMenuListBasic(copyList.CopyFromId) == null) { copyList.RestaurantsList = m_serviceLayer.GetAllRestaurantsInStringList(); return View(copyList); } return RedirectToAction("SelectMenuPartsCopyFrom", copyList); } } catch (Exception e) { log.ErrorFormat("[SelectRestCopyMenuPartFromConfirmed] Exception={0}.", e); return RedirectToAction("Index", new { id = copyList.CopyToRestId }); } }
//========================================================================================== //Copy MenuPart //========================================================================================== public ActionResult SelectRestCopyMenuPartFrom(string restaurantId) { log.InfoFormat("[SelectRestCopyMenuPartFrom] RestaurantId={0}", restaurantId); RestaurantsSearchUtilities restaurantsSearchUtilty = new RestaurantsSearchUtilities(); restaurantsSearchUtilty.GetllAllRestaurantsBasicDataWithDefaultMenu(); CopyList copyList = new CopyList() { CopyToRestId = restaurantId, //RestaurantsList = m_serviceLayer.GetAllRestaurantsInStringList() RestaurantsList = restaurantsSearchUtilty.GetllAllRestaurantsBasicDataWithDefaultMenuInStringList() }; return View(copyList); }