Пример #1
0
        public Filter[] GetFilter(string key)
        {
            switch (key)
            {
            case "AutoAddFriendByPhonePage":
                return(AddFriendByPhoneConfigSet.ToArray().Select(Mapper.Map <AddFriendByPhoneConfigDto, Filter>).ToArray());

            case "AutoAddFriendNearByPage":
                return(AddFriendNearByConfigSet.ToArray().Select(Mapper.Map <AddFriendNearByConfigDto, Filter>).ToArray());

            case "AutoSendMessageToFriendPage":
                return(MessageToFriendConfigSet.ToArray().Select(Mapper.Map <MessageToFriendConfigDto, Filter>).ToArray());

            case "AutoSendMessageToStrangerByPhonePage":
                return(MessageToStrangerByPhoneConfigSet.ToArray().Select(Mapper.Map <MessageToStrangerByPhoneConfigDto, Filter>).ToArray());

            case "AutoSendMessageToStrangerNearByPage":
                return(MessageToStrangerNearByConfigSet.ToArray().Select(Mapper.Map <MessageToStrangerNearByConfigDto, Filter>).ToArray());
            }

            return(null);
        }
Пример #2
0
        public void SaveFilter(ObservableCollection <Filter> sources, string key)
        {
            switch (key)
            {
            case "AutoAddFriendByPhonePage":
                foreach (var item in sources)
                {
                    var itemConfig   = Mapper.Map <Filter, AddFriendByPhoneConfigDto>(item);
                    var dbItemConfig = AddFriendByPhoneConfigSet.FirstOrDefault(x => x.Id == itemConfig.Id);
                    if (dbItemConfig == null)
                    {
                        itemConfig.Id = 0;
                        AddFriendByPhoneConfigSet.Add(itemConfig);
                    }
                    else
                    {
                        CopyFilter(item, dbItemConfig);
                    }
                }
                break;

            case "AutoAddFriendNearByPage":
                foreach (var item in sources)
                {
                    var itemConfig   = Mapper.Map <Filter, AddFriendNearByConfigDto>(item);
                    var dbItemConfig = AddFriendNearByConfigSet.FirstOrDefault(x => x.Id == itemConfig.Id);
                    if (dbItemConfig == null)
                    {
                        itemConfig.Id = 0;
                        AddFriendNearByConfigSet.Add(itemConfig);
                    }
                    else
                    {
                        CopyFilter(item, dbItemConfig);
                    }
                }
                break;

            case "AutoSendMessageToFriendPage":
                foreach (var item in sources)
                {
                    var itemConfig   = Mapper.Map <Filter, MessageToFriendConfigDto>(item);
                    var dbItemConfig = MessageToFriendConfigSet.FirstOrDefault(x => x.Id == itemConfig.Id);
                    if (dbItemConfig == null)
                    {
                        itemConfig.Id = 0;
                        MessageToFriendConfigSet.Add(itemConfig);
                    }
                    else
                    {
                        CopyFilter(item, dbItemConfig);
                    }
                }
                break;

            case "AutoSendMessageToStrangerByPhonePage":
                foreach (var item in sources)
                {
                    var itemConfig   = Mapper.Map <Filter, MessageToStrangerByPhoneConfigDto>(item);
                    var dbItemConfig = MessageToStrangerByPhoneConfigSet.FirstOrDefault(x => x.Id == itemConfig.Id);
                    if (dbItemConfig == null)
                    {
                        itemConfig.Id = 0;
                        MessageToStrangerByPhoneConfigSet.Add(itemConfig);
                    }
                    else
                    {
                        CopyFilter(item, dbItemConfig);
                    }
                }
                break;

            case "AutoSendMessageToStrangerNearByPage":

                foreach (var item in sources)
                {
                    var itemConfig   = Mapper.Map <Filter, MessageToStrangerNearByConfigDto>(item);
                    var dbItemConfig = MessageToStrangerNearByConfigSet.FirstOrDefault(x => x.Id == itemConfig.Id);
                    if (dbItemConfig == null)
                    {
                        itemConfig.Id = 0;
                        MessageToStrangerNearByConfigSet.Add(itemConfig);
                    }
                    else
                    {
                        CopyFilter(item, dbItemConfig);
                    }
                }
                break;
            }
            SaveChanges();
        }