Removes the specified friend from the the user's friend list
Inheritance: Command
Exemplo n.º 1
0
        public void ShouldValidateWhenRemoveCommandIsValid()
        {
            var command = new RemoveFriendCommand()
            {
                Id = Guid.NewGuid()
            };

            Assert.True(command.Valid());
        }
Exemplo n.º 2
0
        public async Task <ICommandResult> Delete(Guid id)
        {
            var command = new RemoveFriendCommand()
            {
                Id = id
            };
            var result = _handler.Handle(command);

            return(await Response(result));
        }
Exemplo n.º 3
0
        public void ShouldRemoveFriendWhenCommandIsValid()
        {
            var command = new RemoveFriendCommand()
            {
                Id = Guid.NewGuid()
            };
            var result = _handler.Handle(command);

            Assert.NotEqual(null, result);
            Assert.True(_handler.Valid);
        }
Exemplo n.º 4
0
        public FriendListViewModel CreateFriendListViewModel(FriendList friendList, Action refreshFriendListAction)
        {
            var friendListViewModel = new FriendListViewModel()
            {
                FriendListItems = new ObservableCollection <FriendListItem>()
            };

            var acceptFriendCommand = new AcceptFriendRequestCommand(friendListViewModel, refreshFriendListAction, _friendService, _logger);
            var removeFriendCommand = new RemoveFriendCommand(friendListViewModel, refreshFriendListAction, _friendService, _logger);

            foreach (var incomingRequest in friendList.IncomingRequests)
            {
                friendListViewModel.FriendListItems.Add(MapFriendRequestToViewModel(incomingRequest, acceptFriendCommand, removeFriendCommand));
            }

            foreach (var friend in friendList.Friends.Where(t => t.IsOnline))
            {
                friendListViewModel.FriendListItems.Add(MapFriendToViewModel(friend, removeFriendCommand));
            }

            foreach (var friend in friendList.Friends.Where(t => !t.IsOnline))
            {
                friendListViewModel.FriendListItems.Add(MapFriendToViewModel(friend, removeFriendCommand));
            }

            friendListViewModel.FriendListItems.Add(new FriendListSeparator());

            foreach (var outgoingRequest in friendList.OutgoingRequests)
            {
                friendListViewModel.FriendListItems.Add(MapOutoingFriendRequest(outgoingRequest, removeFriendCommand));
            }

            friendListViewModel.OnlineFriendsCount = friendListViewModel.FriendListItems.Count(t => t is OnlineFriend);
            friendListViewModel.FriendListCount    = friendList.Friends.Count;

            return(friendListViewModel);
        }
Exemplo n.º 5
0
 public Task Handle(RemoveFriendCommand message, IMessageHandlerContext context)
 => Task.FromResult(_friendsService.RemoveFriendForCharacter(message));
Exemplo n.º 6
0
        public void Execute(Message msg, IMessageSenderService sender, IBot bot)
        {
            if (Main.Api.Users.IsBanned(msg))
            {
                return;
            }

            if (!Main.Api.Users.CheckUser(msg))
            {
                var kb2 = new KeyboardBuilder(bot);
                kb2.AddButton("➕ Зарегистрироваться", "start");
                sender.Text("❌ Вы не зарегистрированы, нажмите на кнопку ниже, чтобы начать", msg.ChatId, kb2.Build());
                return;
            }

            var user    = Main.Api.Users.GetUser(msg);
            var command = UsersCommandHelper.GetHelper().Get(user.Id);

            //TODO: написать с использованием команд-менеджера.
            var text = string.Empty;

            if (command == "")
            {
                if (msg.ChatId > 2000000000)
                {
                    return;
                }
                sender.Text("❌ Неизвестная команда", msg.ChatId);
                return;
            }
            else if (command == "putrawmoney")
            {
                long count;
                try
                {
                    count = long.Parse(msg.Text);
                    text  = PutCommand.PutMoney(user, count);
                }
                catch
                {
                    text = "❌ Вы ввели неверное число. Попробуйте ещё раз.";
                }
            }
            else if (command == "withdrawmoney")
            {
                long count;
                try
                {
                    count = long.Parse(msg.Text);
                    text  = WithdrawCommand.Withdraw(user, count);
                }
                catch
                {
                    text = "❌ Вы ввели неверное число. Попробуйте ещё раз.";
                }
            }
            else if (command == "exchangedonate")
            {
                long count;
                try
                {
                    count = long.Parse(msg.Text);
                    text  = ExchangeDonateCommand.Exchange(msg, count);
                }catch
                {
                    text = "❌ Вы ввели неверное число. Попробуйте ещё раз.";
                }
            }
            else if (command == "creategang")
            {
                text = CreateCommand.Create(msg.Text, user.Id);
            }
            else if (command == "renamegang")
            {
                text = RenameCommand.Rename(user, msg.Text);
            }
            else if (command == "opencontribution")
            {
                try
                {
                    var array = msg.Text.Split(" ");

                    var count = long.Parse(array[0]);
                    var days  = long.Parse(array[1]);
                    text = OpenContributionCommand.Open(user.Id, count, days);
                }
                catch
                {
                    text = "❌ Вы указали неверные числа";
                }
            }
            else if (command == "racefriend")
            {
                try
                {
                    var array = msg.Text.Split(" ");
                    var id    = long.Parse(array[0]);
                    text = RaceFriendCommand.RunFriendBattle(user.Id, id, sender, bot, msg);
                }catch
                {
                    text = "Вы указали неверный id";
                }
            }
            else if (command == "addfriend")
            {
                try
                {
                    text = AddFriendCommand.AddFriend(user, msg.Text.ToLong(), sender);
                }
                catch
                {
                    text = "❌ Вы указали неверный Id.";
                }
            }
            else if (command == "removefriend")
            {
                try
                {
                    text = RemoveFriendCommand.RemoveFriend(user, msg.Text.ToLong());
                }
                catch
                {
                    text = "❌ Вы указали невеный Id.";
                }
            }
            else if (command == "sellcar")
            {
                try
                {
                    var array  = msg.Text.Split(" ");
                    var idUser = long.Parse(array[0]);
                    var price  = long.Parse(array[1]);

                    text = SellCarCommand.Sell(user, idUser, sender, price);
                }catch
                {
                    text = "❌ Произошла ошибка.";
                }
            }
            else if (command == "buycarnumber")
            {
                try
                {
                    var region = long.Parse(msg.Text);
                    if (region < 1 || region > 999)
                    {
                        text = "❌ Регион находится за пределом допустимого значения.";
                    }
                    else
                    {
                        text = BuyCarNumberCommand.BuyNumber(user, region);
                    }
                }
                catch
                {
                    text = "❌ Произошла ошибка.";
                }
            }
            else if (command == "sellnumber")
            {
                try
                {
                    var array  = msg.Text.Split(" ");
                    var idUser = long.Parse(array[0]);
                    var price  = long.Parse(array[1]);

                    text = SellNumberCommand.Sell(user, idUser, sender, price);
                }catch
                {
                    text = "❌ Произошла ошибка.";
                }
            }
            else if (command == "buychips")
            {
                try
                {
                    var count = msg.Text.ToLong();
                    text = BuyChipsCommand.BuyChips(user, count);
                }
                catch
                {
                    text = "❌ Произошла ошибка.";
                }
            }
            else if (command == "exchangechips")
            {
                try
                {
                    var count = msg.Text.ToLong();
                    text = ExchangeChipsCommand.ExchangeChips(user, count);
                }
                catch
                {
                    text = "❌ Произошла ошибка.";
                }
            }
            else if (command == "vipDonateBuy")
            {
                try
                {
                    var count = msg.Text.ToLong();
                    text = ExpDonateCommand.BuyExp(count, user);
                }
                catch
                {
                    text = "❌ Произошла ошибка.";
                }
            }
            else if (command == "carDonate")
            {
                try
                {
                    text = CarDonateCommand.CreateCar(msg.Text, user);
                }
                catch
                {
                    text = "❌ Произошла ошибка.";
                }
            }
            else if (command == "expDonate")
            {
                try
                {
                    var array  = msg.Text.Split(" ");
                    var power  = long.Parse(array[0]);
                    var weight = long.Parse(array[1]);

                    text = AcceptCustomCarCommand.SetParams(power, weight, user, sender);
                }catch
                {
                    text = "❌ Произошла ошибка.";
                }
            }
            else if (command == "customNumber")
            {
                try
                {
                    var number = msg.Text.ToLong();
                    text = BuyOtherItemCommand.CustomNumber(number.ToString(), user);
                }
                catch
                {
                    text = "❌ Произошла ошибка.";
                }
            }
            else if (command == "chatSend")
            {
                try
                {
                    var textMsg = msg.Text;
                    text = ChatCommand.Send(textMsg, user, sender);
                }
                catch (Exception e)
                {
                    text = $"❌ Произошла ошибка. {e}";
                }
            }
            else if (command == "newChatCreate")
            {
                try
                {
                    var number = msg.Text;
                    text = NewChatCommand.CreateChat(number, user, sender, bot);
                }
                catch
                {
                    text = "❌ Произошла ошибка.";
                }
            }

            var kb = new KeyboardBuilder(bot);

            kb.AddButton(ButtonsHelper.ToHomeButton());
            sender.Text(text, msg.ChatId, kb.Build());
            // UsersCommandHelper.GetHelper().Add("", user.Id);
        }
Exemplo n.º 7
0
 public ICommandResult Handle(RemoveFriendCommand command)
 {
     _repository.Remove(command.Id);
     return(new FriendCommandResult(true, "Registro apagado com sucesso", command.Id));
 }
Exemplo n.º 8
0
 public Task RemoveFriendForCharacter(RemoveFriendCommand command)
 => _characterRepository.RemoveCharacterFriend(command.CharacterId, command.FriendId);
Exemplo n.º 9
0
        public async Task <IActionResult> Remove([FromBody] RemoveFriendCommand command)
        {
            await _messageSession.Send(command).ConfigureAwait(false);

            return(Accepted());
        }