Beispiel #1
0
        public void AddSearchFilter(FilterModel newFilter, string newName)
        {
            StaticLog.LogServiceCall(string.Format("AddSearchFilter({0})", newFilter));

            try
            {
                using (var ctx = new VkContext())
                {
                    var exist = ctx.VkSearchFilters.FirstOrDefault(x => x.Name == newFilter.Name);

                    if (exist != null)
                    {
                        throw new Exception("Фильтр с заданным именем уже существует : " + newFilter.Name);
                    }

                    var newVkSearchFilter = new VkSearchFilter(newFilter);

                    newVkSearchFilter.Name = newName;

                    ctx.VkSearchFilters.Add(newVkSearchFilter);

                    ctx.SaveChanges();
                }
            }
            catch (Exception e)
            {
                StaticLog.LogException(e);
            }
        }
Beispiel #2
0
        public List <FilterModel> GetAllSearchFilters()
        {
            StaticLog.LogServiceCall(string.Format("GetAllSearchFilters()"));

            try
            {
                using (var ctx = new VkContext())
                {
                    var allFilters = new List <FilterModel>();

                    foreach (var x in ctx.VkSearchFilters)
                    {
                        var filter = new FilterModel(false);

                        VkSearchFilter.CopyToFilterModel(x, filter);

                        allFilters.Add(filter);
                    }

                    return(allFilters);
                }
            }
            catch (Exception e)
            {
                StaticLog.LogException(e);

                return(null);
            }
        }
Beispiel #3
0
 public static void CopyToFilterModel(VkSearchFilter copy, FilterModel filter)
 {
     filter.Name         = copy.Name;
     filter.City         = copy.City;
     filter.Coutry       = copy.Coutry;
     filter.FamilyStatus = copy.FamilyStatus;
     filter.FirstContact = false;
     filter.FriendStatus = copy.FriendStatus;
     filter.HasPhoto     = copy.HasPhoto;
     filter.IsOnline     = copy.IsOnline;
     filter.FriendsCount = copy.MinFriendsCount.HasValue && copy.MaxFriendsCount.HasValue
                         ? new IntervalValue <int>(copy.MinFriendsCount.Value, copy.MaxFriendsCount.Value)
                         : null;
     filter.SubsCount     = copy.MinSubsCount.HasValue && copy.MaxSubsCount.HasValue ?  new IntervalValue <int>(copy.MinSubsCount.Value, copy.MaxSubsCount.Value) : null;
     filter.Years         = copy.MinYear.HasValue && copy.MaxYear.HasValue ? new IntervalValue <int>(copy.MinYear.Value, copy.MaxYear.Value) : null;
     filter.Offset        = copy.Offset;
     filter.Sex           = copy.Sex;
     filter.SortBy        = copy.SortBy;
     filter.CommonFriends = copy.CommonFriendsCount;
 }