Inheritance: IServicesLayer, IBackofficeService
 public RestuarntsChainUtility()
 {
     serviceLayer = new ServiceLayerImpl();
     cuisineServices = new CuisineMapServices();
     operatorSevices = new OperatorMapServices();
     restaurantsSearchUtilty = new RestaurantsSearchUtilities();
 }
Esempio n. 2
0
 public USDAImport()
 {
     serviceLayer = new ServiceLayerImpl();
     charsCount = 0;
     LongDescCount = 0;
     ComNameCount = 0;
     IngredientCount = 0;
 }
        public void FindAllRestaurantsByOperatorTest_ShouldFindAllRestsByInputString()
        {
            //act
            List<RestaurantBasicData> restsList = restaurantsSearchUtilty.FindAllRestaurantsByOperator("דונלד", true);

            ServiceLayerImpl serviceLayer = new ServiceLayerImpl();
            double distance = 2.0 / 6371.0; // 2000 meters
            RestaurantBasicData restaurant = null;
            int count = 0;

            Assert.IsNotNull(restsList);

            foreach(var rest in restsList)
            {
                bool foundFlag = false;
                var searchResult = restaurantsSearchUtilty.FindNearestRestaurantsByOperator("Donald", rest.ItemLocation, distance);

                if (searchResult != null && searchResult.Count > 0)
                {
                    foreach (RestaurantBasicData foundRest in searchResult)
                    {
                        if (restaurantsSearchUtilty.CheckForCorrectChainMenu(foundRest))
                        {
                            count++;
                            foundFlag = true;
                            rest.Menu = foundRest.Menu;
                        }
                    }
                }

                if (!foundFlag)
                {
                    searchResult = restaurantsSearchUtilty.FindNearestRestaurantsByOperator("דונלד", rest.ItemLocation, distance);

                    if (searchResult != null && searchResult.Count > 0)
                    {
                        foreach (RestaurantBasicData foundRest in searchResult)
                        {
                            if (restaurantsSearchUtilty.CheckForCorrectChainMenu(foundRest))
                            {
                                count++;
                                rest.Menu = foundRest.Menu;
                            }
                        }
                    }
                }

            }

            Assert.IsNotNull(restaurant);
            Assert.IsTrue(restaurant.Menu.MenuParts.Count >= 3);
            Assert.IsTrue(count > 0);
        }
Esempio n. 4
0
 public static void CalcDistance(this CouponTypeModel coupon, LocationModel location)
 {
     if (location == null) location = new LocationModel(32.067141, 34.804314); // default location Teatron Givataim
     IServicesLayer m_serviceLayer = new ServiceLayerImpl();
     if (coupon.Location != null && location != null)
     {
         coupon.Distance = m_serviceLayer.CalculateDistanceInKm(coupon.Location, location);
     }
     else
     {
         coupon.Distance = 6000;
     }
 }
        public void Index()
        {
            // Arrange
            IBackofficeService service = new ServiceLayerImpl();
            RestaurantController controller = new RestaurantController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            ViewDataDictionary viewData = result.ViewData;

            List<RestaurantModel> restaurantList = service.GetAllRestaurants();

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Model, restaurantList);
        }
Esempio n. 6
0
 public static IEnumerable<RestaurantModel> CalculateHealthState(this  IEnumerable<RestaurantModel> restaurants)
 {
     IServicesLayer m_serviceLayer = new ServiceLayerImpl();
     int green, yellow, red;
     green = yellow = red = 0;
     if (restaurants != null)
     {
         foreach (RestaurantModel rest in restaurants)
         {
             if (rest != null)
             {
                 var tempRest = m_serviceLayer.GetRestaurantById(rest.Id);
                 if(tempRest.Menu.MenuParts != null)
                 {
                     foreach (MenuPartModel menuPart in tempRest.Menu.MenuParts)
                     {
                         if (menuPart.Dishes != null && menuPart.Dishes.Count > 0)
                         foreach (DishModel dish in menuPart.Dishes)
                         {
                             if (dish.NutritionFacts.TotalCarbohydrate < 20){
                                 green++;
                             }
                             else
                             {
                                 if (dish.NutritionFacts.TotalCarbohydrate < 40)
                                 {
                                     yellow++;
                                 }
                                 else
                                 {
                                     red++;
                                 }
                             }
                         }
                     }
                 }
             }
             int max =  Math.Max(green, Math.Max(yellow, red));
             if (max == red) rest.CarbsLevel = 0;
             if (max == yellow) rest.CarbsLevel = 1;
             if (max == green) rest.CarbsLevel = 2;
             green = yellow = red = 0;
         }
     }
     return restaurants;
 }
Esempio n. 7
0
 public static int CalculateCarbsLevel(this RestaurantBasicData rest)
 {
     IServicesLayer m_serviceLayer = new ServiceLayerImpl();
     int green, yellow, red;
     green = yellow = red = 0;
     if (rest != null)
     {
         if ( rest.Menu != null && rest.Menu.MenuParts != null && rest.Menu.MenuParts.Count > 0)
         {
             foreach (MenuPart menuPart in rest.Menu.MenuParts)
             {
                 if (menuPart.Dishes != null && menuPart.Dishes.Count > 0)
                     foreach (Dish dish in menuPart.Dishes)
                     {
                         if (dish.NutritionFacts != null && dish.NutritionFacts.TotalCarbohydrate != null)
                         {
                             if (dish.NutritionFacts.TotalCarbohydrate < 20)
                             {
                                 green++;
                             }
                             else
                             {
                                 if (dish.NutritionFacts.TotalCarbohydrate < 40)
                                 {
                                     yellow++;
                                 }
                                 else
                                 {
                                     red++;
                                 }
                             }
                         }
                     }
             }
         }else
         {
             return 1; // uknown menu return yellow
         }
         int max = Math.Max(green, Math.Max(yellow, red));
         if (max == red) return 0;
         if (max == yellow) return 1;
         if (max == green) return 2;
     }
     return -1;
 }
Esempio n. 8
0
        public void AddDefaultMenuToRestaurant(RestaurantBasicData rest) 
        {
            try
            {
                if (rest != null)
                {
                    string cuisinesList = rest.Cuisines != null ? String.Join(", ", rest.Cuisines.ToArray()) : "Empty";
                    var TempMenus = GetDefaultMenusList(rest);
                    if (TempMenus != null && TempMenus.Count > 0)
                    {
                        ServiceLayerImpl serviceLayer = new ServiceLayerImpl();
                        rest.Menu = CombineMenus(TempMenus);
                        log.InfoFormat("[AddDefaultMenuToRestaurant] Found default Menu for rest.Name={0}, rest.Id={1}, Cuisines List={2}.", rest.Name, rest.Id.ToString(), cuisinesList);
                        rest.UpdateDishesLocation();
                        serviceLayer.UpdateRestaurant(rest);
                    }
                    else 
                    {
                        log.InfoFormat("[AddDefaultMenuToRestaurant] Not found default Menu for rest.Name={0}, rest.Id={1}, Cuisines List={2}.", rest.Name, rest.Id.ToString(), cuisinesList);
                    }

                }
                else 
                {
                    log.WarnFormat("[AddDefaultMenuToRestaurant] input restayrant is null.");
                }
            }
            catch (Exception e) 
            {
                log.ErrorFormat("[AddDefaultMenuToRest] Exception={0}.", e.Message);
            }
        }
        public void GetMenuPartTest_ShouldReturnMenuPartWithRegularDishModelIfCalledFromServiceLayerClass()
        {
            ServiceLayerImpl serviceLayerImpl = new ServiceLayerImpl();
            //ID Mojo | נתניה | גיבורי ישראל
            var menuPart = serviceLayerImpl.GetMenuPart(0, "50e5d1f23720e80db83478c5");

            foreach (DishModel dishModel in menuPart.Dishes)
            {
                Assert.IsTrue(dishModel.GetType() != typeof(DishModelBackOffice));
            }
        }
Esempio n. 10
0
 public void Initialize()
 {
     defMenuUtility = new DefaultMenuUtility();
     cuisineServices = new CuisineMapServices();
     serviceLayer = new ServiceLayerImpl();
     restaurantsSearchUtilty = new RestaurantsSearchUtilities();
 }
Esempio n. 11
0
        public void UpdateDish_shouldUpdateSameObjectAndNotCreateNewOne()
        {
            //arrange
            ServiceLayerImpl serviceLayer = new ServiceLayerImpl();
            var restaurants = m_MocBackOfficeService.GetAllRestaurants();

            var restaurnat = restaurants.FirstOrDefault(c => c.Menu.MenuParts.Count > 0);
            var menuPart = restaurnat.Menu.MenuParts.FirstOrDefault();

            var dish = restaurnat.Menu.MenuParts.FirstOrDefault().Dishes.First();
            dish.UpdatedAt  = DateTime.UtcNow;
            Guid dishId = dish.dishId;

            //act
            m_MocServiceLayer.UpdateDish(dish);

            //assert
            DishModel updatedDish = serviceLayer.GetDish(dishId);
            Assert.AreEqual(updatedDish.Id, dish.Id);
            Assert.AreEqual(updatedDish.dishId, dish.dishId);
            Assert.AreEqual(updatedDish.UpdatedAt, dish.UpdatedAt);
        }
Esempio n. 12
0
        public void ToDefaultMenuRestaurant()
        {
            ServiceLayerImpl serviceLayer = new ServiceLayerImpl();
            //RestaurantBasicData basicRest = serviceLayer.GetRestaurantBasicById("5330222c3720e816d87310bd");
            RestaurantBasicData basicRest = new RestaurantBasicData()
            {
                Name = "falafel default menu",
                Description = "falafel default menu",
                Cuisine = "falafel",
                Id = ObjectId.Parse("5330222c3720e816d87310bd")
            };

            // Act
            DefaultMenuRestaurant defMenuRest = defMenuUtility.ToDefaultMenuRestaurant(basicRest);

            // Assert
            Assert.IsNotNull(defMenuRest);
            Assert.AreEqual(defMenuRest.Name, basicRest.Name);
            Assert.AreEqual(defMenuRest.Description, basicRest.Description);
            Assert.AreEqual(defMenuRest.Cuisine, basicRest.Cuisine);
            Assert.IsNotNull(defMenuRest.Menu);
            Assert.AreEqual(defMenuRest.Menu.MenuParts.Count, basicRest.Menu.MenuParts.Count);
            Assert.AreNotEqual(defMenuRest.Id, basicRest.Id);
        }
Esempio n. 13
0
        public static RestaurantBasicData ToRestaurantBasicModel(this RestaurantModel restaurantData)
        {
            RestaurantBasicData returnValue = new RestaurantBasicData()
            {
                Id = ObjectId.Parse(restaurantData.Id),
                //Name = restaurantData.Name,
                //Description = restaurantData.Description,
                LogoUrl = restaurantData.LogoUrl,

                Menu = ToMenuBasicModel(restaurantData.Menu),
                Adress = restaurantData.Adress,
                ItemLocation = restaurantData.Location.toLoaction(),
                Phone = restaurantData.Phone,
                CreatedAt = restaurantData.CreatedAt,
                UpdatedAt = restaurantData.UpdatedAt
            };

            if (restaurantData.Cuisine != null && restaurantData.Cuisine != "") returnValue.Cuisine = restaurantData.Cuisine;
            if (restaurantData.Cuisines != null && restaurantData.Cuisines.Count > 0) returnValue.Cuisines = restaurantData.Cuisines;
            if (restaurantData.Operator != null && restaurantData.Operator != "") returnValue.Operator = restaurantData.Operator;
            if (restaurantData.Source != null && restaurantData.Source != "") returnValue.Source = restaurantData.Source;

            if (restaurantData.Language == null || restaurantData.Language == DefaultLang)
            {
                returnValue.Name = restaurantData.Name;
                returnValue.Description = restaurantData.Description;
            }

            try
            {
                IServicesLayer m_serviceLayer = new ServiceLayerImpl();
                RestaurantBasicData dbRest = m_serviceLayer.GetRestaurantBasicById(restaurantData.Id);
                if (dbRest != null)
                {
                    if (restaurantData.Language == null || restaurantData.Language == DefaultLang)
                    {
                        returnValue.Name = restaurantData.Name;
                        returnValue.Description = restaurantData.Description;
                    }
                    else
                    {
                        returnValue.Name = dbRest.Name;
                        returnValue.Description = dbRest.Description;
                    }

                    if (dbRest.LocalizedName == null && restaurantData.Language != null)
                    {
                        returnValue.LocalizedName = new Localized(restaurantData.Language, restaurantData.Name);
                    }
                    else
                    {
                        returnValue.LocalizedName = dbRest.LocalizedName;
                        if (restaurantData.Language != null) returnValue.LocalizedName.UpdateDescription(restaurantData.Language, restaurantData.Name);
                    }

                    if (dbRest.LocalizedDescription == null && restaurantData.Language != null)
                    {
                        returnValue.LocalizedDescription = new Localized(restaurantData.Language, restaurantData.Description);
                    }
                    else
                    {
                        returnValue.LocalizedDescription = dbRest.LocalizedDescription;
                        if (restaurantData.Language != null) returnValue.LocalizedDescription.UpdateDescription(restaurantData.Language, restaurantData.Description);
                    }
                }
            }
            catch (Exception e)
            {
                log.ErrorFormat("[ToRestaurantBasicModel] Exception={0}", e);
            }

            return returnValue;
        }
Esempio n. 14
0
        public static MenuPart ToMenuPartBasic(this MenuPartModel menuPartModel)
        {
            MenuPart menuPart = new MenuPart()
            {
                Id = menuPartModel.Id,
                OrderBy = menuPartModel.OrderBy,
                //Name = menuPartModel.Name,
                AvailableFrom = menuPartModel.AvailableFrom.ToUniversalTime(),
                AvailableTill = menuPartModel.AvailableTill.ToUniversalTime(),
                Dishes = ToDishBasicModel(menuPartModel.Dishes)
            };

            //If already has Localized Description
            try
            {
                IServicesLayer m_serviceLayer = new ServiceLayerImpl();
                MenuPart dbMenuPart = m_serviceLayer.GetMenuPartBasic(menuPartModel.Id, menuPartModel.RestaurantId);
                if (dbMenuPart != null)
                {
                    if (menuPartModel.Language == null || menuPartModel.Language == DefaultLang)
                    {
                        menuPart.Name = menuPartModel.Name;
                    }
                    else
                    {
                        menuPart.Name = dbMenuPart.Name;
                    }
                    if (dbMenuPart.LocalizedName != null)
                    {
                        menuPart.LocalizedName = dbMenuPart.LocalizedName;
                    }
                }
                if (menuPartModel.Language != null)
                {
                    if (menuPart.LocalizedName == null)
                    {
                        menuPart.LocalizedName = new Localized(menuPartModel.Language, menuPartModel.Name);
                    }
                    else menuPart.LocalizedName.UpdateDescription(menuPartModel.Language, menuPartModel.Name);
                }
                else
                {
                    menuPart.Name = menuPartModel.Name != null ? menuPartModel.Name : "";
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("[ExtensionMethods: ToMenuPartBasic] Exception={0}", ex.ToString());
            }

            return menuPart;
        }
Esempio n. 15
0
        public static UserMedalModel ToUserMedalModel(this UserMedal medal)
        {
            if (medal == null)
            {
                log.WarnFormat("[ToUserMedalModel] medal=null.");
                return null;
            }
            try
            {
                log.InfoFormat("[ToUserMedalModel] medalType={0}, CreatedAt={1}.", medal.GetType().Name, medal.CreatedAt);
                IServicesLayer m_serviceLayer = new ServiceLayerImpl();

                string medalName = "undefined";
                UserMedalModel returnValue = new UserMedalModel() { CreatedAt = medal.CreatedAt };

                //if (item.State == null) { item.State = new SuspiciousState(); }
                medalName = medal.GetType().Name;
                returnValue.MedalName = medalName;
                if (medal is WelcomeUserMedal) returnValue.MedalName = "ברוכים הבאים";
                if (medal is FlowCompleteMedal) returnValue.MedalName = "רמת סוכר לאחר שעתיים";
                if (medal is RestaurantAdviserMedal) returnValue.MedalName = "מבקר מסעדות";
                if (medal is ReservationMedal) returnValue.MedalName = "מבקר מסעדות";
                if (medal is AddRestaurantMedal) returnValue.MedalName = "הוספת מסעדות";

                if (medal.Coupon != null)
                {
                    returnValue.Coupon = medal.Coupon.ToCouponTypeModel();
                }

                return returnValue;
            }
            catch (Exception e)
            {
                log.ErrorFormat("[ToUserMedalModel] Exception={0}.", e.ToString());
                return null;
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Find or fix cuisine and operator for all restaurants from Osm source
        /// </summary>
        public void UpdateCuisinesAndOperators() 
        {
            log.InfoFormat("[UpdateCuisinesAndOperators].");
            //var allRests = GetAllRestaurantsWithOsmSource();
            var allRests = restaurantsSearchUtilty.FindAllRestaurantsWithCusine();
            ServiceLayerImpl serviceLayer = new ServiceLayerImpl();
            foreach (var rest in allRests)
            {
                string restName = rest.Name != null ? rest.Name : "";
                string restDescription = rest.Description != null ? rest.Description : "";
                //var operatorMap = operatorSevices.OperatorMapSearch(rest);
                //if (operatorMap != null)
                //{
                //    log.InfoFormat("[UpdateCuisinesAndOperators] Operator found. Operator={0}, Restaurant.Name={1}, Restaurant.Description={2}.", operatorMap.Name, restName, restDescription);
                //}

                List<CuisineMap> cuisineMaps = cuisineServices.CuisineMapSearch(rest);
                if (cuisineMaps != null && cuisineMaps.Count > 0)
                {
                    string cuisinesList = rest.Cuisines != null ? String.Join(", ", rest.Cuisines.ToArray()) : "Empty";
                    log.InfoFormat("[UpdateCuisinesAndOperators] Cuisine found. Cuisines list={0}, Cuisine.Count={1}, Restaurant.Name={2}, Restaurant.Description={3}.", cuisinesList, cuisineMaps.Count, restName, restDescription);
                    serviceLayer.UpdateRestaurant(rest);
                }
            }
        }
Esempio n. 17
0
        public void AddDefaultsMenus(List<RestaurantBasicData> restList) 
        {
            ServiceLayerImpl serviceLayer = new ServiceLayerImpl();
            int AddMenuCount = 0;
            int notNullMenuCount = 0;
            int notFoundDefMenuCount = 0;

            if (restList != null && restList.Count > 0) 
            {
                foreach (var rest in restList)
                {
                    var TempMenus = GetDefaultMenusList(rest);
                    if (TempMenus != null && TempMenus.Count > 0)
                    {
                        //if (rest.Menu != null && rest.Menu.MenuParts != null &&  (rest.Menu.MenuParts.Count == 0 || (rest.Menu.MenuParts.Count == 1 && rest.Menu.MenuParts[0].Name.IndexOf("כל המנות") >= 0))) //|| rest.UpdatedBy == "Back office")
                        if (rest.Menu != null && rest.Menu.MenuParts != null && rest.Menu.MenuParts.Count == 0)
                        {
                            AddMenuCount++;
                            ////If Menu contain "כל המנות" MenuPart combine it with other menus
                            //if (rest.Menu.MenuParts[0].Name.IndexOf("כל המנות") >= 0) 
                            //{
                            //    TempMenus.Add(rest.Menu);
                            //}

                            rest.Menu = CombineMenus(TempMenus);
                            string cuisineName = rest.Cuisine != null ? rest.Cuisine : "";
                            string cuisinesList = rest.Cuisines != null ? String.Join(", ", rest.Cuisines.ToArray()) : "Empty";
                            log.InfoFormat("[AddDefaultsMenus] Found default Menu and rest has null menu, for rest.Name={0}, Cuisine={1}, Cuisines List={2}.", rest.Name, cuisineName, cuisinesList);
                            //rest.UpdatedBy = "SupervisedCuisine_2014.05.29";
                            //rest.UpdatedBy = "AutoFoundCuisine_2014.06.12";
                            rest.UpdateDishesLocation();
                            serviceLayer.UpdateRestaurant(rest);
                        }
                        else
                        {
                            if (rest.Menu != null)
                            {
                                notNullMenuCount++;
                                string cuisineName = rest.Cuisine != null ? rest.Cuisine : "";
                                log.InfoFormat("[AddDefaultsMenus] Found default Menu and rest has Not null menu, for Cuisine={0}, rest.Name={1}.", cuisineName, rest.Name);
                            }
                        }
                    }
                    else
                    {
                        notFoundDefMenuCount++;
                        string cuisineName = rest.Cuisine != null ? rest.Cuisine : "";
                        log.InfoFormat("[AddDefaultsMenus] Not found default menu for Cuisine={0}, rest.Name={1}.", cuisineName, rest.Name);
                    }
                }
            }
            log.InfoFormat("[AddDefaultsMenus] Added menu to restaurants, count={0}.", AddMenuCount);
            log.InfoFormat("[AddDefaultsMenus] Found Cuisine for rest and rest.Menu was NOT empty count={0}.", notNullMenuCount);
            log.InfoFormat("[AddDefaultsMenus] Not found default menu count={0}.", notFoundDefMenuCount);
        }
Esempio n. 18
0
        public static CouponTypeModel ToCouponTypeModel(this CouponType coupon)
        {
            try
            {
                log.InfoFormat("[ToCouponTypeModel] coupon.Id={0}, coupon.Description={1}.", coupon.Id.ToString(), coupon.Description);
                IServicesLayer m_serviceLayer = new ServiceLayerImpl();

                CouponTypeModel returnValue = new CouponTypeModel()
                {
                    Id = coupon.Id.ToString(),
                    Description = coupon.Description,
                    ValidFrom = coupon.ValidFrom,
                    ValidUntil = coupon.ValidUntil
                };

                if (coupon.RestaurantsIDs != null && coupon.RestaurantsIDs.Count > 0)
                {
                    returnValue.RestaurantID = coupon.RestaurantsIDs[0].ToString();
                    var tempRest = m_serviceLayer.GetRestaurantById(returnValue.RestaurantID);
                    if (tempRest != null) returnValue.LogoUrl = (tempRest.LocalUrl != null) ? tempRest.LocalUrl : tempRest.LogoUrl;
                    //returnValue.LogoUrl = "/Restaurant/GetImage/" + returnValue.RestaurantID;
                }
                if (coupon.LocationsList != null && coupon.LocationsList.Count > 0)
                {
                    returnValue.Location = new LocationModel(coupon.LocationsList[0]);
                }
                else
                {
                    returnValue.Location = new LocationModel(0, 0);
                    if (returnValue.Description.IndexOf("Nelly's Kitchen") > 0) returnValue.Location = new LocationModel(32.051, 34.755);
                    if (returnValue.Description.IndexOf("BG99") > 0) returnValue.Location = new LocationModel(32.016652, 34.738724);
                    if (returnValue.Description.IndexOf("קולומבוס") > 0) returnValue.Location = new LocationModel(32.161, 34.81);
                    if (returnValue.Description.IndexOf("Red Burger Bar") > 0) returnValue.Location = new LocationModel(32.33, 34.85);
                    if (returnValue.Description.IndexOf("Palamida") > 0) returnValue.Location = new LocationModel(32.084638, 34.803035);
                }

                return returnValue;
            }
            catch (Exception e)
            {
                log.ErrorFormat("[ToCouponTypeModel] Exception={0}.", e.ToString());
                return null;
            }
        }
Esempio n. 19
0
        public static CouponType ToCouponType(this CouponTypeModel coupon)
        {
            try
            {
                IServicesLayer m_serviceLayer = new ServiceLayerImpl();

                CouponType returnValue = new CouponType()
                {
                    Description = coupon.Description,
                    ValidFrom = coupon.ValidFrom,
                    ValidUntil = coupon.ValidUntil,
                    RestaurantsIDs = new List<string>() { coupon.RestaurantID },
                    LocationsList = new List<Location>() { coupon.Location.toLoaction() }
                };

                returnValue.Id = (coupon.Id != null && coupon.Id != "") ? ObjectId.Parse(coupon.Id) : returnValue.Id;
                log.InfoFormat("[ToCouponType] coupon.Description={0}.", coupon.ToString());
                return returnValue;
            }
            catch (Exception e)
            {
                log.ErrorFormat("[ToCouponType] Exception={0}.", e.ToString());
                return null;
            }
        }
Esempio n. 20
0
        public void AddDefaultsMenusToSwedenFinlandRests(List<RestaurantBasicData> restList)
        {
            ServiceLayerImpl serviceLayer = new ServiceLayerImpl();
            int AddMenuCount = 0;
            //int notNullMenuCount = 0;
            int notFoundDefMenuCount = 0;

            Menu finnishDefaultMenu = GetDefaultMenuFromCuisinesList(new List<string>() { "finnish_finland_sweden" });

            if (restList != null && restList.Count > 0)
            {
                foreach (var rest in restList)
                {
                    var TempMenus = GetDefaultMenusList(rest);
                    if (TempMenus != null && TempMenus.Count > 0)
                    {
                        //if (rest.Menu != null && rest.Menu.MenuParts != null && rest.Menu.MenuParts.Count == 0)
                        //{
                            AddMenuCount++;
                            rest.Menu = CombineMenus(TempMenus);
                            string cuisineName = rest.Cuisine != null ? rest.Cuisine : "";
                            string cuisinesList = rest.Cuisines != null ? String.Join(", ", rest.Cuisines.ToArray()) : "Empty";
                            log.InfoFormat("[AddDefaultsMenusToSwedenFinlandRests] Found default Menu and rest has null menu, for rest.Name={0}, Cuisine={1}, Cuisines List={2}.", rest.Name, cuisineName, cuisinesList);
                            //rest.UpdatedBy = "SupervisedCuisine_2014.05.29";
                            //rest.UpdatedBy = "AutoFoundCuisine_2014.06.12";
                            rest.UpdateDishesLocation();
                            serviceLayer.UpdateRestaurant(rest);
                        //}
                        //else
                        //{
                        //    if (rest.Menu != null)
                        //    {
                        //        notNullMenuCount++;
                        //        string cuisineName = rest.Cuisine != null ? rest.Cuisine : "";
                        //        log.InfoFormat("[AddDefaultsMenusToSwedenFinlandRests] Found default Menu and rest has Not null menu, for Cuisine={0}, rest.Name={1}.", cuisineName, rest.Name);
                        //    }
                        //}
                    }
                    else
                    {
                        notFoundDefMenuCount++;
                        string cuisineName = rest.Cuisine != null ? rest.Cuisine : "";
                        log.InfoFormat("[AddDefaultsMenusToSwedenFinlandRests] Not found default menu, added default Finnish menu, rest.Name={0}.", rest.Name);
                        rest.Menu = finnishDefaultMenu;
                        rest.UpdateDishesLocation();
                        serviceLayer.UpdateRestaurant(rest);
                    }
                }
            }
            log.InfoFormat("[AddDefaultsMenusToSwedenFinlandRests] Added menu to restaurants, count={0}.", AddMenuCount);
            //log.InfoFormat("[AddDefaultsMenusToSwedenFinlandRests] Found Cuisine for rest and rest.Menu was NOT empty count={0}.", notNullMenuCount);
            log.InfoFormat("[AddDefaultsMenusToSwedenFinlandRests] Not found default menu count={0}.", notFoundDefMenuCount);
        }
Esempio n. 21
0
        // If conversion for new created dishModel then creat new Dish Object
        // If conversion for existing dish then update changed attributes
        public static Dish ToDish(this DishModel item, Dish dish = null)
        {
            IServicesLayer m_serviceLayer = new ServiceLayerImpl();
            if (dish == null)
            {
                dish = new Dish();
            }
            dish.Id = item.Id;
            dish.OrderBy = item.OrderBy;
            if (item.Language == null || item.Language == DefaultLang)
            {
                dish.Name = item.Name;
                dish.Description = item.Description;
            }
            if (dish.LocalizedName == null && item.Language != null) dish.LocalizedName = new Localized(item.Language, item.Name);
            else
            {
                if (item.Language != null) dish.LocalizedName.UpdateDescription(item.Language, item.Name);
            }

            if (dish.LocalizedDescription == null && item.Language != null) dish.LocalizedDescription = new Localized(item.Language, item.Description);
            else
            {
                if (item.Language != null) dish.LocalizedDescription.UpdateDescription(item.Language, item.Description);
            }

            if (item.ItemLocation == null)
            {
                var restaurnat = m_serviceLayer.GetRestaurantBasicById(item.RestaurantId);
                dish.ItemLocation = restaurnat.ItemLocation;
            }
            else
            {
                dish.ItemLocation = item.ItemLocation.toLoaction();
            }
            dish.RecipeId = item.RecipeId;
            //dish.Images = item.Images;
            //dish.OverrideIngredients = item.OverrideIngredients;
            dish.CreatedAt = item.CreatedAt.ToUniversalTime();
            dish.UpdatedAt = item.UpdatedAt.ToUniversalTime();
            dish.State = item.State;
            dish.IsItPublic = item.IsItPublic;
            dish.DishState = item.DishState;
            dish.NutritionFacts = item.NutritionFacts.ToNutritionFacts();
            dish.ImageUrl = item.ImageUrl;

            if (item.GetType() == typeof(DishModelBackOffice) && ((DishModelBackOffice)item).BaseLineNutritionFacts != null)
            {
                dish.BaseLineNutritionFacts = ((DishModelBackOffice)item).BaseLineNutritionFacts.ToNutritionFacts();
            }
            try
            {
                Dish dbDish = m_serviceLayer.GetDishBasic(item.MenuPartId, item.RestaurantId, item.Id);
                if (dbDish != null)
                {
                    if (dbDish.Image != null) dish.Image = dbDish.Image;
                    if (dbDish.Images != null) dish.Images = dbDish.Images;
                    if (item.DefaultWeight != null) dish.DefaultWeight = item.DefaultWeight.ToWeightType(dbDish, item.Language);
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("[ExtensionMethods: ToDish] Exception={0}", ex.ToString());
            }
            return dish;
        }
Esempio n. 22
0
        /// <summary>
        /// Find or fix cuisine and operator for all restaurants from Sweden and Finland
        /// </summary>
        public void SwedenFinlandUpdateCuisines()
        {
            log.InfoFormat("[SwedenFinlandUpdateCuisines].");
            RestaurantsSearch searchUtility = new RestaurantsSearch();
            var allRests = searchUtility.FindAllSwedenFinlandRestaurantsWithCusine();
            ServiceLayerImpl serviceLayer = new ServiceLayerImpl();
            int foundCuisines = 0, notFoundCuisine = 0;
            foreach (var rest in allRests)
            {
                string restName = rest.Name != null ? rest.Name : "";
                string restDescription = rest.Description != null ? rest.Description : "";

                List<CuisineMap> cuisineMaps = cuisineServices.CuisineMapSearch(rest, "Finland");
                if (cuisineMaps != null && cuisineMaps.Count > 0)
                {
                    string cuisinesList = rest.Cuisines != null ? String.Join(", ", rest.Cuisines.ToArray()) : "Empty";
                    log.InfoFormat("[SwedenFinlandUpdateCuisines] Cuisine found. Cuisines list={0}, Cuisine.Count={1}, Restaurant.Name={2}, Restaurant.Description={3}.", cuisinesList, cuisineMaps.Count, restName, restDescription);
                    serviceLayer.UpdateRestaurant(rest);
                    foundCuisines++;
                }
                else 
                {
                    log.InfoFormat("[SwedenFinlandUpdateCuisines] Cuisine not found. Restaurant.Name={0}, Restaurant.Id={1}, Restaurant.Description={2}.", restName, rest.Id.ToString(), restDescription);
                    notFoundCuisine++;
                }
            }
            log.InfoFormat("[SwedenFinlandUpdateCuisines] foundCuisines={0}, notFoundCuisine={1}, allRests={2}.", foundCuisines, notFoundCuisine, allRests.Count);
        }
Esempio n. 23
0
        public static Meal ToMeal(this List<PortionModel> portionsModel)
        {
            Meal returnvalue = null;
            if (portionsModel != null)
            {
                IServicesLayer m_serviceLayer = new ServiceLayerImpl();
                var restaurnat = m_serviceLayer.GetRestaurantById(portionsModel[0].PortionFrom.RestaurantId);
                if (restaurnat != null)
                {
                    double totalCarbs = 0;
                    List<Portion> portions = new List<Portion>();
                    foreach (var portionModel in portionsModel)
                    {
                        Portion portion = portionModel.ToPortion();
                        portions.Add(portion);
                        totalCarbs += portionModel.CarbAmount;
                    }

                    returnvalue = new Meal()
                    {
                        CreatedAt = DateTime.UtcNow,
                        RestaurantId = restaurnat.Id,
                        Name = restaurnat.Name,
                        Portions = portions,
                        CarbAmount = totalCarbs
                    };
                }
            }
            return returnvalue;
        }
Esempio n. 24
0
 public void MyTestInitialize()
 {
     serviceLayer = new ServiceLayerImpl();
 }
Esempio n. 25
0
 public static MealViewModel ToMealViewModel(this Meal meal)
 {
     MealViewModel returnvalue = null;
     if (meal != null)
     {
         IServicesLayer m_serviceLayer = new ServiceLayerImpl();
         var restaurnat = m_serviceLayer.GetRestaurantById(meal.RestaurantId);
         if (restaurnat != null)
         {
             List<DishModel> dishes = new List<DishModel>();
             List<PortionModel> portionsModel = new List<PortionModel>();
             if (meal.Portions != null)
             {
                 foreach (var dish in meal.Portions)
                 {
                     DishModel dishVM = dish.PrtionFrom.ToDishModel(restaurnat.Id, dish.MenuPartId);
                     dishes.Add(dishVM);
                     PortionModel portion = dish.ToPortionModel(restaurnat.Id, dish.MenuPartId);
                     portionsModel.Add(portion);
                 }
             }
             returnvalue = new MealViewModel()
             {
                 CreatedAt = meal.CreatedAt,
                 RestaurantId = restaurnat.Id,
                 RestaurantName = restaurnat.Name,
                 City = restaurnat.Adress.City,
                 Street = restaurnat.Adress.Street,
                 Dishes = dishes,
                 Portions = portionsModel
             };
             if (meal.CarbAmount != null) returnvalue.CarbAmount = meal.CarbAmount;
         }
     }
     return returnvalue;
 }