GetRestaurantBasicById() public method

public GetRestaurantBasicById ( string id ) : RestaurantBasicData
id string
return Spontaneous.DataModel.RestaurantBasicData
Example #1
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;
        }
Example #2
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;
        }