Esempio n. 1
0
        public void AddFoodKeyword(string food)
        {
            try
            {
                using (var entityContext = new LunchEntities())
                {
                    var foodKeyword = new FoodKeyword
                    {
                        Word = food
                    };

                    entityContext.FoodKeywords.AddObject(foodKeyword);
                    entityContext.SaveChanges();
                }
            }
            catch (UpdateException updateException)
            {
                var baseError = updateException.GetBaseException();
                if (baseError.Message.Contains("not unique"))
                {
                    return;
                }

                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a new lunch restaurant or updates an existing one.
        /// </summary>
        public void UpdateLunchRestaurant(LunchRestaurant lunchRestaurant)
        {
            try
            {
                using (var entityContext = new LunchEntities())
                {
                    var existingUrl = FindExistingLunchRestaurant(lunchRestaurant.URL);
                    if (existingUrl != null)
                    {
                        existingUrl.Status = lunchRestaurant.Status;
                        existingUrl.SiteHash = lunchRestaurant.SiteHash;
                        existingUrl.LunchMenuProbability = lunchRestaurant.LunchMenuProbability;
                        existingUrl.TotalPoints = lunchRestaurant.TotalPoints;
                        existingUrl.TotalKeywordDetections = lunchRestaurant.TotalKeywordDetections;
                        existingUrl.ExactKeywordDetections = lunchRestaurant.ExactKeywordDetections;
                        existingUrl.PartialKeywordDetections = lunchRestaurant.PartialKeywordDetections;
                        existingUrl.FuzzyKeywordDetections = lunchRestaurant.FuzzyKeywordDetections;
                        existingUrl.DateUpdated = DateTime.UtcNow;
                    }
                    else
                    {
                        lunchRestaurant.DateAdded = DateTime.UtcNow;
                        entityContext.LunchRestaurants.AddObject(lunchRestaurant);
                    }

                    entityContext.SaveChanges();
                }
            }
            catch (UpdateException updateException)
            {
                var baseError = updateException.GetBaseException();
                if (baseError.Message.Contains("not unique"))
                {
                    return;
                }

                throw;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a new lunch restaurant or updates an existing one.
        /// </summary>
        public void UpdateLunchRestaurantDeepLinks(string restaurantUrl, IList<RestaurantDeepLink> deepLinks)
        {
            if (deepLinks == null)
            {
                return;
            }

            try
            {
                using (var entityContext = new LunchEntities())
                {
                    foreach (var deepLink in deepLinks)
                    {
                        deepLink.RestaurantURL = restaurantUrl;
                        entityContext.RestaurantDeepLinks.AddObject(deepLink);
                    }

                    entityContext.SaveChanges();
                }
            }
            catch (UpdateException updateException)
            {
                var baseError = updateException.GetBaseException();
                if (baseError.Message.Contains("not unique"))
                {
                    return;
                }

                throw;
            }
        }
Esempio n. 4
0
        public void UpdateLunchMenuKeywordDetectionCounts(IDictionary<string, int> keywordCounts)
        {
            using (var entityContext = new LunchEntities())
            {
                foreach (var keywordPair in keywordCounts)
                {
                    var keywordName = keywordPair.Key;
                    var keywordCount = keywordPair.Value;

                    var existingKeyword = entityContext.LunchMenuKeywords
                                                       .FirstOrDefault(keyword => keyword.Word.Equals(keywordName,
                                                                                                      StringComparison.InvariantCultureIgnoreCase));
                    if (existingKeyword == null)
                    {
                        continue;
                    }

                    var existingDetectionCount = existingKeyword.DetectionCount;
                    var newDetectionCount = existingDetectionCount + keywordCount;

                    existingKeyword.DetectionCount = newDetectionCount;
                }

                entityContext.SaveChanges();
            }
        }