Ejemplo n.º 1
0
 public override DishModel ToDishModel(Dish dishData, string restId, int MenuPId, string lang = DefaultLang, RestaurantModel restaurantModel = null)
 {
     if (restaurantModel == null)
     {
         restaurantModel = new RestaurantModel();
     }
     if(restaurantModel.GetType() == typeof(RestaurantModelBackOffice))
     {
         return ((RestaurantModelBackOffice)restaurantModel).GetDishModel(dishData, restId, MenuPId, false, lang);
     }
     return restaurantModel.GetDishModel(dishData, restId, MenuPId, false, lang);
     //return dishData.ToDishModel(restId, MenuPId, false, lang, restaurantModel);
 }
        public void GetDishModelTest_ShouldReturnDishModelIfCalledFromRestaurantModel()
        {
            RestaurantModel rest = new RestaurantModel();
            Dish dish = new Dish()
            {
                Name = "TempDish",
                Description = "description",
                Id = 1,
                NutritionFacts = new NutritionFacts(),
                BaseLineNutritionFacts = new NutritionFacts()
            };
            dish.NutritionFacts.TotalCarbohydrate = 20;
            dish.BaseLineNutritionFacts.TotalCarbohydrate = 33;
            DishModel dishModel = rest.GetDishModel(dish, "111", false, "he");

            var type = dishModel.GetType();
            Assert.IsFalse(type == typeof(DishModelBackOffice));
            Assert.IsTrue(type == typeof(DishModel));
        }
Ejemplo n.º 3
0
 public static DishModel ToDishModelBaseLine(this Dish dishData, string restId, int MenuPId, string lang = DefaultLang, RestaurantModel restModel = null)
 {
     return dishData.ToDishModel(restId, MenuPId, true, lang, restModel);
 }
Ejemplo n.º 4
0
        //"en-US"
        public static DishModel ToDishModel(this Dish dishData, string restId, bool baseLine, string lang = DefaultLang, RestaurantModel restModel = null)
        {
            if (restModel == null) restModel = new RestaurantModel();
            DishModel dishModel = restModel.GetDishModel(dishData, restId, baseLine, lang);
            var tempDish = dishModel;

            DishModel returnValue = new DishModel()
            {
                Id = dishData.Id,
                OrderBy = dishData.OrderBy,
                Name = dishData.Name,
                Language = lang,
                Description = dishData.Description,
                ItemLocation = new LocationModel(dishData.ItemLocation),
                RestaurantId = restId,
                //MenuPartId = MenuPId,
                RecipeId = dishData.RecipeId,
                //Images = item.Images,
                //OverrideIngredients = item.OverrideIngredients,
                CreatedAt = dishData.CreatedAt.ToLocalTime(),
                UpdatedAt = dishData.UpdatedAt.ToLocalTime(),
                State = baseLine ? new SuspiciousState() : dishData.State,
                IsItPublic = dishData.IsItPublic,
                DishState = dishData.DishState,
                NutritionFacts = baseLine && dishData.BaseLineNutritionFacts != null ? new NutritionFactsViewModel(dishData.BaseLineNutritionFacts) : new NutritionFactsViewModel(dishData.NutritionFacts),
                ImageUrl = dishData.ImageUrl
            };
            if (dishData.Image != null)
            {
                returnValue.LocalUrl = "/Restaurant/GetImage/" + dishData.Image.Id.ToString();
            }
            if (dishData.DefaultWeight != null) returnValue.DefaultWeight = dishData.DefaultWeight.ToWeightTypeModel(lang);

            if (dishData.LocalizedName != null)
            {
                string locName = dishData.LocalizedName.GetDescription(lang);
                if (locName != null) returnValue.Name = locName;
            }
            if (dishData.LocalizedDescription != null)
            {
                string locDesc = dishData.LocalizedDescription.GetDescription(lang);
                if (locDesc != null) returnValue.Description = locDesc;
            }
            return returnValue;
        }
Ejemplo n.º 5
0
 public static DishModel ToDishModel(this Dish dishData, string restId, int MenuPId, bool baseLine, string lang = DefaultLang, RestaurantModel restModel = null)
 {
     DishModel returnValue = dishData.ToDishModel(restId, baseLine, lang, restModel);
     returnValue.MenuPartId = MenuPId;
     return returnValue;
 }
Ejemplo n.º 6
0
        public static List<DishModel> ToDishModel(this List<Dish> DishesData, string RestId, int MenuPId, string lang = DefaultLang, RestaurantModel restaurantModel = null)
        {
            if (DishesData == null) return new List<DishModel>();

            List<DishModel> returnValue = new List<DishModel>();

            ToViewModelConverter converter = ConverterCreator.ModelConverterFactory();

            foreach (var item in DishesData)
            {
                if (item.State == null) { item.State = new SuspiciousState(); }

                DishModel temp = converter.ToDishModel(item, RestId, MenuPId, lang, restaurantModel);
                //DishModel temp = item.ToDishModel(RestId, MenuPId, lang);
                returnValue.Add(temp);
            }

            return returnValue.OrderBy(c => c.OrderBy).ToList();
        }
Ejemplo n.º 7
0
 public static RestaurantModel ToRestaurantModel(this RestaurantBasicData restaurantData, bool withMenu = true)
 {
     //State - MappedState
     RestaurantModel returnValue = new RestaurantModel()
     {
         Id = restaurantData.Id.ToString(),
         Name = restaurantData.Name,
         Description = restaurantData.Description,
         LogoUrl = restaurantData.LogoUrl,
         Menu = withMenu ? ToMenuModel(restaurantData.Menu, restaurantData.Id.ToString()) : ToMenuModel(null, restaurantData.Id.ToString()),
         Adress = restaurantData.Adress,
         Location = new LocationModel(restaurantData.ItemLocation),
         Distance = restaurantData.Distance,
         Phone = restaurantData.Phone,
         MappedState = GetRestauranMappedState(restaurantData),
         CarbsLevel = restaurantData.CalculateCarbsLevel(),
         CreatedAt = restaurantData.CreatedAt,
         UpdatedAt = restaurantData.UpdatedAt
     };
     if (restaurantData.Image != null)
     {
         returnValue.LocalUrl = "/Restaurant/GetImage/" + restaurantData.Image.Id.ToString();
     }
     return returnValue;
 }
Ejemplo n.º 8
0
 public ActionResult UpdateRestaurantInfo(RestaurantModel rest)
 {
     log.InfoFormat("[UpdateRestaurantInfo] rest={0}", rest.ToString());
     m_serviceLayer.UserUpdateRestaurant(rest);
     return Content("success", "text/plain");
 }
        public void GetDishModelTest_ShouldReturnListOfDishModelIfCalledWithRestaurantModelParameter()
        {
            RestaurantModel restModel = new RestaurantModel();
            Dish dish1 = new Dish()
            {
                Name = "TempDish1",
                Description = "description",
                Id = 1,
                NutritionFacts = new NutritionFacts(),
                BaseLineNutritionFacts = new NutritionFacts()
            };
            Dish dish2 = new Dish()
            {
                Name = "TempDish2",
                Description = "description",
                Id = 2,
                NutritionFacts = new NutritionFacts(),
                BaseLineNutritionFacts = new NutritionFacts()
            };
            var dishList = new List<Dish>();
            dishList.Add(dish1);
            dishList.Add(dish2);

            List<DishModel> dishListModel = dishList.ToDishModel("111", 1, "he", restModel);

            foreach (DishModel dishModel in dishListModel)
            {
                Assert.IsTrue(dishModel.GetType() != typeof(DishModelBackOffice));
            }
        }
Ejemplo n.º 10
0
 public string AddRestaurantToDB(RestaurantModel restaurantmodel)
 {
     log.DebugFormat("[AddRestaurantToDB] restaurantmodel={0}.", restaurantmodel.ToString());
     using (Restaurants restaurantsDb = new Restaurants())
     {
         MongoEntityRepositoryBase<RestaurantBasicData> basicData =
                       new MongoEntityRepositoryBase<RestaurantBasicData>(restaurantsDb.DB);
         RestaurantBasicData tempRest = new RestaurantBasicData()
         {
             //Id = ObjectId.Parse(restaurantmodel.Id),
             Name = restaurantmodel.Name,
             Description = restaurantmodel.Description,
             LogoUrl = (restaurantmodel.LogoUrl != null) ? restaurantmodel.LogoUrl : "",
             Menu = restaurantmodel.Menu.ToMenuBasicModel(),
             Adress = restaurantmodel.Adress,
             ItemLocation = (restaurantmodel.Location != null) ? restaurantmodel.Location.toLoaction() : null,
             Phone = restaurantmodel.Phone,
             CreatedAt = DateTime.UtcNow,
             UpdatedAt = DateTime.UtcNow
         };
         basicData.Add(tempRest);
         if (tempRest.LogoUrl != "" && tempRest.Image == null)
         {
             ImageServices m_imageService = new ImageServices();
             m_imageService.UploadImageToRestaurant(tempRest, tempRest.LogoUrl);
         }
         if (m_userProfile.AppName != ApplicationName.BackOffice)
         {
             SaveUserActivity(new AddRestaurantActivity()
             {
                 RestaurantID = tempRest.Id.ToString(),
                 LocationAdd = tempRest.ItemLocation,
                 ActivityLocation = tempRest.ItemLocation
             });
         }
         return tempRest.Id.ToString();
     }
 }
Ejemplo n.º 11
0
 public static RestaurantModel ToRestaurantModel(this RestaurantBasicData restaurantData, bool withMenu = true, string lang = DefaultLang, RestaurantModel restModel = null)
 {
     //State - MappedState
     if (restModel == null) restModel = new RestaurantModel();
     RestaurantModel returnValue = new RestaurantModel()
     {
         Id = restaurantData.Id.ToString(),
         Name = restaurantData.Name,
         Description = restaurantData.Description,
         Language = lang,
         LogoUrl = restaurantData.LogoUrl,
         Cuisine = restaurantData.Cuisine != null ? restaurantData.Cuisine : "",
         Cuisines = restaurantData.Cuisines != null ? restaurantData.Cuisines : new List<string>(), //( new string[] { "shawarma", "midle east", "drinks" }),
         Operator = restaurantData.Operator != null ? restaurantData.Operator : "",
         Source = restaurantData.Source != null ? restaurantData.Source : "",
         Menu = withMenu ? ToMenuModel(restaurantData.Menu, restaurantData.Id.ToString(), lang, restModel) : ToMenuModel(null, restaurantData.Id.ToString(), lang),
         Adress = restaurantData.Adress,
         Location = new LocationModel(restaurantData.ItemLocation),
         Distance = restaurantData.Distance,
         Phone = restaurantData.Phone,
         MappedState = GetRestauranMappedState(restaurantData),
         CarbsLevel = restaurantData.CalculateCarbsLevel(),
         CreatedAt = restaurantData.CreatedAt,
         UpdatedAt = restaurantData.UpdatedAt
     };
     if (restaurantData.Image != null)
     {
         returnValue.LocalUrl = "/Restaurant/GetImage/" + restaurantData.Image.Id.ToString();
     }
     if (restaurantData.LocalizedName != null && lang != null)
     {
         string locName = restaurantData.LocalizedName.GetDescription(lang);
         if (locName != null) returnValue.Name = locName;
     }
     if (restaurantData.LocalizedDescription != null && lang != null)
     {
         string locDesc = restaurantData.LocalizedDescription.GetDescription(lang);
         if (locDesc != null) returnValue.Description = locDesc;
     }
     if (restaurantData.Menu != null && restaurantData.Menu.MenuParts != null)
     {
         int count = 0;
         if (restaurantData.Menu.MenuParts.Count > 0)
         {
             foreach (var menuPart in restaurantData.Menu.MenuParts)
             {
                 count += menuPart.Dishes.Count;
             }
         }
         returnValue.DishCount = count;
     }
     return returnValue;
 }
Ejemplo n.º 12
0
        public JsonResult DishSearch(string q, double lat=0, double lng=0)
        {
            try
            {
                Stopwatch stop = Stopwatch.StartNew();

                Spontaneous.WebApp.Models.RestaurantModel restaurant = new RestaurantModel();
                List<DishModel> dishList = new List<DishModel>();

                RestaurantModel baseRest = m_serviceLayer.GetRestaurantById("52cbed8e3720e811740b9193");
                if (q != "" || q != null)
                {
                    foreach (MenuPartModel menuPart in baseRest.Menu.MenuParts)
                    {
                        List<DishModel> restDishes = menuPart.Dishes.FindAll(d => d.Name.IndexOf(q) >= 0);
                        if (restDishes.Count > 0)
                        {
                            restaurant.Menu.MenuParts.Add(new MenuPartModel()
                            {
                                Name = menuPart.Name,
                                Id = menuPart.Id,
                                Dishes = restDishes
                            });
                            dishList.AddRange(restDishes);
                        }
                    }

                    restaurant.Menu.MenuParts.Add(new MenuPartModel() { Name = q, Id = 100 });
                    int dishCount = restaurant.DishCount;
                    if (dishCount < 20)
                    {
                        List<GeneralDish> dishes = m_serviceLayer.SearchGeneralDish(null, new Location(lat, lng), (20 - dishCount), q);

                        if (dishes != null && dishes.Count > 0)
                        {
                            //RestaurantModel basicProductRest = m_serviceLayer.GetRestaurantById("52cbed8e3720e811740b9193");
                            List<DishModel> dishModelList = dishes.ToDishModelList();
                            if (dishModelList != null)
                            {
                                foreach (DishModel tempDish in dishModelList)
                                {
                                    restaurant.Menu.MenuParts.Find(m => m.Id == 100).Dishes.Add(tempDish);
                                }
                            }

                            log.InfoFormat("[DishSearch] q={0}, exeTime={1}", q, stop.ElapsedMilliseconds);
                        }
                    }
                }//(q != "" || q != null)
                else
                {
                    restaurant = baseRest;
                }
                m_serviceLayer.SaveUserActivity(new PageViewActivity("DishSearch") { ActivityLocation = new Location(lat, lng) });
                return Json(restaurant, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                log.ErrorFormat("[DishSearch] q={0}, exception={1}.", q, ex);
                return Json(null, JsonRequestBehavior.AllowGet);
                //throw;
            }
        }
Ejemplo n.º 13
0
 public override DishModel ToDishModel(Dish dishData, string restId, string lang = DefaultLang, RestaurantModel restaurantModel = null)
 {
     return dishData.ToDishModel(restId, false, lang, restaurantModel);
 }
Ejemplo n.º 14
0
 public override DishModel ToDishModel(Dish dishData, string restId, int MenuPId, string lang = DefaultLang, RestaurantModel restaurantModel = null)
 {
     return dishData.ToDishModelBaseLine(restId, MenuPId, lang, restaurantModel);
 }
Ejemplo n.º 15
0
        public string AddRestaurantToDB(RestaurantModel restaurantmodel)
        {
            log.DebugFormat("[AddRestaurantToDB] restaurantmodel={0}.", restaurantmodel.ToString());
            using (Restaurants restaurantsDb = new Restaurants())
            {
                MongoEntityRepositoryBase<RestaurantBasicData> basicData =
                              new MongoEntityRepositoryBase<RestaurantBasicData>(restaurantsDb.DB);
                RestaurantBasicData tempRest = new RestaurantBasicData()
                {
                    //Id = ObjectId.Parse(restaurantmodel.Id),
                    Name = restaurantmodel.Name,
                    Description = restaurantmodel.Description,
                    LogoUrl = (restaurantmodel.LogoUrl != null) ? restaurantmodel.LogoUrl : "",
                    Menu = restaurantmodel.Menu.ToMenuBasicModel(),
                    Adress = restaurantmodel.Adress,
                    ItemLocation = (restaurantmodel.Location != null) ? restaurantmodel.Location.toLoaction() : null,
                    Phone = restaurantmodel.Phone,
                    CreatedAt = DateTime.UtcNow,
                    UpdatedAt = DateTime.UtcNow
                };
                basicData.Add(tempRest);

                SaveUserActivity(new AddRestaurantActivity()
                {
                    RestaurantID = tempRest.Id.ToString(),
                    Location = tempRest.ItemLocation
                });
                return tempRest.Id.ToString();
            }
        }
Ejemplo n.º 16
0
        public static MenuModel ToMenuModel(this Menu MenuData, string RestId, string lang, RestaurantModel restaurantModel = null)
        {
            if (MenuData == null) return new MenuModel() { RestaurantId = RestId };

            MenuModel returnValue = new MenuModel()
            {
                RestaurantId = RestId,
                MenuParts = ToMenuPartsModel(MenuData.MenuParts, RestId, lang, restaurantModel)
            };

            return returnValue;
        }
Ejemplo n.º 17
0
        public static List<MenuPartModel> ToMenuPartsModel(this List<MenuPart> MenuData, string RestId, string lang, RestaurantModel restaurantModel)
        {
            if (MenuData == null) return new List<MenuPartModel>();

            List<MenuPartModel> returnValue = new List<MenuPartModel>();
            foreach (var item in MenuData)
            {
                MenuPartModel temp = new MenuPartModel()
                {
                    Id = item.Id,
                    OrderBy = item.OrderBy,
                    RestaurantId = RestId,
                    Name = item.Name,
                    Language = lang,
                    AvailableFrom = item.AvailableFrom.ToLocalTime(),
                    AvailableTill = item.AvailableTill.ToLocalTime(),
                    Dishes = ToDishModel(item.Dishes, RestId, item.Id, lang, restaurantModel)
                };
                if (item.LocalizedName != null && lang != null)
                {
                    string locName = item.LocalizedName.GetDescription(lang);
                    if (locName != null)
                    {
                        temp.Name = locName;
                        //temp.Language = lang;
                    }
                }
                returnValue.Add(temp);
            }
            return returnValue.OrderBy(c=> c.OrderBy).ToList();
        }
Ejemplo n.º 18
0
 public DishModel GetDish(int MenuPartId, string RestaurantId, int Id, string lang = DefaultLang, RestaurantModel restaurantModel = null)
 {
     log.InfoFormat("[GetDish] MenuPartId={0}, RestaurantId={1}, Id={2}", MenuPartId, RestaurantId, Id);
     return (GetMenuPart(MenuPartId, RestaurantId, lang).Dishes.FirstOrDefault(d => d.Id == Id));
 }
Ejemplo n.º 19
0
 public void UpdateRestaurant(RestaurantModel restaurantmodel)
 {
     log.DebugFormat("[UpdateRestaurant(RestaurantModel)] RestaurantModel={0}.", restaurantmodel.ToString());
     restaurantmodel.UpdatedAt = DateTime.UtcNow;
     RestaurantBasicData restData = restaurantmodel.ToRestaurantBasicModel();
     RestaurantBasicData previousRest = GetRestaurantBasicById(restaurantmodel.Id);
     if (previousRest.Image != null && (previousRest.LogoUrl == restData.LogoUrl || previousRest.LogoUrl == null || previousRest.LogoUrl == "" || restData.LogoUrl == null))
     {
         restData.Image = previousRest.Image;
     }
     UpdateRestaurant(restData);
 }
Ejemplo n.º 20
0
        public void UserUpdateRestaurant(RestaurantModel restaurantmodel)
        {
            log.DebugFormat("[UserEditRestaurant(RestaurantModel)] RestaurantModel={0}.", restaurantmodel.ToString());
            RestaurantModel tempRest = GetRestaurantById(restaurantmodel.Id);
            tempRest.Name = restaurantmodel.Name;
            tempRest.Description = restaurantmodel.Description;
            tempRest.Adress.City = restaurantmodel.Adress.City;
            tempRest.Adress.Street = restaurantmodel.Adress.Street;
            tempRest.Adress.BuildingNum = restaurantmodel.Adress.BuildingNum;
            tempRest.Adress.Description = restaurantmodel.Adress.Description;
            tempRest.Phone = restaurantmodel.Phone;

            RestaurantBasicData rest = tempRest.ToRestaurantBasicModel();
            rest.Menu = GetRestaurantBasicById(restaurantmodel.Id).Menu;
            UpdateRestaurant(rest);
            //UpdateRestaurant(tempRest);

            //SaveUserActivity(new UserActivity()
            //{
            //    Type = "UpdateRestaurant",
            //    RestaurantID = restaurantmodel.Id,
            //    Location = tempRest.Location.toLoaction()
            //});
        }
Ejemplo n.º 21
0
 public ActionResult AddRestaurant(RestaurantModel rest)
 {
     log.InfoFormat("[AddRestaurant] rest={0}", rest.ToString());
     var id = m_serviceLayer.AddRestaurantToDB(rest);
     return Content(id, "text/plain");
 }
Ejemplo n.º 22
0
 public abstract DishModel ToDishModel(Dish dish, string restId, int MenuPId, string lang = DefaultLang, RestaurantModel restaurantModel = null);