Adds the Friend user to the friendlist of the user with PlayFabId. At least one of FriendPlayFabId,FriendUsername,FriendEmail, or FriendTitleDisplayName should be initialized.
Inheritance: Command
        public AddFriendCommandResult Handler(AddFriendCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new AddFriendCommandResult(false, false, command.Notifications.ToList()));
            }

            if (friendRepository.LocationAlreadyExists(Latitude: command.Latitude, Longitude: command.Longitude))
            {
                AddNotification("Location", "Já existe um amigo cadastrado nesta localização.");
            }

            if (Invalid)
            {
                return(new AddFriendCommandResult(false, false, Notifications.ToList()));
            }

            var friend = new Friend(command.Name, new Point(command.Latitude, command.Longitude));

            AddNotifications(friend);

            if (Invalid)
            {
                return(new AddFriendCommandResult(false, false, Notifications.ToList()));
            }

            friendRepository.Add(friend);

            return(new AddFriendCommandResult(true, true, new Message()
            {
                MessageType = MessageType.Information, Description = "Amigo cadastrado com sucesso!"
            }));
        }
Exemplo n.º 2
0
        public string DispatchCommand(string[] commandParameters)
        {
            var    cmd       = commandParameters[0].ToLower();
            var    cmdParams = commandParameters.Skip(1).ToArray();
            string result    = null;

            switch (cmd)
            {
            case "registeruser":
                result = RegisterUserCommand.Execute(cmdParams);
                break;

            case "addtown":
                result = AddTownCommand.Execute(cmdParams);
                break;

            case "modifyuser":
                result = ModifyUserCommand.Execute(cmdParams);
                break;

            case "deleteuser":
                result = DeleteUser.Execute(cmdParams);
                break;

            case "addtag":
                result = AddTagCommand.Execute(cmdParams);
                break;

            case "addfriend":
                result = AddFriendCommand.Execute(cmdParams);
                break;

            case "createalbum":
                result = CreateAlbumCommand.Execute(cmdParams);
                break;

            case "addtagto":
                result = AddTagToCommand.Execute(cmdParams);
                break;

            case "makefriends":
                result = AcceptFriendCommand.Execute(cmdParams);
                break;

            case "listfriends":
                result = PrintFriendsListCommand.Execute(cmdParams);
                break;

            case "sharealbum":
                result = ShareAlbumCommand.Execute(cmdParams);
                break;

            case "uploadpicture":
                result = UploadPictureCommand.Execute(cmdParams);
                break;

            default: throw new InvalidOperationException($"Command {cmd} not valid!");
            }
            return(result);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Add([FromBody] AddFriendCommand cmd)
        {
            cmd.CurrentUser = User.Identity.Name;
            await _mediator.Publish(cmd);

            return(Ok());
        }
        public async Task <IActionResult> Add([FromBody] AddFriendCommand command, CancellationToken cancellationToken)
        {
            var result = await Mediator.Send(command, cancellationToken);

            result.ThrowIfFailed();

            return(Ok());
        }
        public IActionResult AddNewFriend(AddFriendCommand friendToAdd, string name)
        {
            var    repo                   = new InmateRepository();
            string friendName             = friendToAdd.Name;
            var    friendCriminalInterest = friendToAdd.CriminalInterest;

            repo.AddNewFriend(friendName, name);
            return(Created($"api/inmates/{friendToAdd.Name}", friendToAdd));
        }
Exemplo n.º 6
0
        private string TryAddFirend(string command, string[] commandParams)
        {
            if (commandParams.Length != 2)
            {
                ThrowInvalidCommand(command);
            }

            var commandObj = new AddFriendCommand();

            return(commandObj.Execute(commandParams));
        }
Exemplo n.º 7
0
        public async void AddNonExistantFriend()
        {
            var command = new AddFriendCommand()
            {
                FriendUserId  = 911,
                CurrentUserId = 912
            };
            var handler = new AddFriendCommandHandler(Context);

            Assert.ThrowsAny <Exception>(() => handler.Handle(command, CancellationToken.None).Result);
        }
Exemplo n.º 8
0
        public async void AddJohnAndRobbAsFriends()
        {
            var body = new AddFriendCommand()
            {
                FriendUserId = 2
            };

            HttpResponseMessage response = await _client.PostObjectAsync(UsersUrl + "/1/friends", body);

            response.EnsureSuccessStatusCode();
        }
Exemplo n.º 9
0
        public async Task HandleAsync(AddFriendCommand message)
        {
            var originator = await this.domainRepository.GetByKeyAsync <Guid, User>(message.OriginatorId);

            originator.AddFriend(message.AcceptorId);
            await this.domainRepository.SaveAsync <Guid, User>(originator);

            var acceptor = await this.domainRepository.GetByKeyAsync <Guid, User>(message.AcceptorId);

            acceptor.AddFriend(message.OriginatorId);
            await this.domainRepository.SaveAsync <Guid, User>(acceptor);
        }
        public void ShouldReturnValidWhenNotExistNotifications()
        {
            var friend = new AddFriendCommand()
            {
                Name      = "Some Name",
                Latitude  = 0,
                Longitude = 0
            };

            friend.Validate();

            friend.Valid.Should().BeTrue();
        }
        public void ShouldCallAddFriendHandlerCorrectly()
        {
            var addFriendCommand = new AddFriendCommand()
            {
                Name = "Lindsey", Latitude = 321, Longitude = 987
            };
            var addFriendHandler = A.Fake <IAddFriendHandler>();

            this.friendsController.AddFriend(addFriendCommand, addFriendHandler);

            A.CallTo(()
                     => addFriendHandler
                     .Handler(A <AddFriendCommand> .That.Matches(f => f.Name == "Lindsey" && f.Latitude == 321 && f.Longitude == 987)))
            .MustHaveHappenedOnceExactly();
        }
Exemplo n.º 12
0
        public async Task HandleAsync(InvitationApprovedEvent message)
        {
            var invitation = await domainRepository.GetByKeyAsync <Guid, Invitation>(message.InvitationId);

            invitation.Transit(message);
            await this.domainRepository.SaveAsync <Guid, Invitation>(invitation);

            // Once the application get approved, send the add friend command.
            var command = new AddFriendCommand
            {
                AcceptorId   = message.ApproverId,
                OriginatorId = message.OriginatorId
            };

            this.commandSender.Publish(command);
        }
Exemplo n.º 13
0
        public async void AddMultipleFriendTest()
        {
            var command1 = new AddFriendCommand()
            {
                FriendUserId  = 1,
                CurrentUserId = 2
            };
            var command2 = new AddFriendCommand()
            {
                FriendUserId  = 1,
                CurrentUserId = 3
            };
            var handler    = new AddFriendCommandHandler(Context);
            var getHandler = new GetFriendsQueryHandler(Context, new ImageRepository());

            await handler.Handle(command1, CancellationToken.None);

            await handler.Handle(command2, CancellationToken.None);

            IEnumerable <UserModel> friends1 = await getHandler.Handle(new GetFriendsQuery()
            {
                UserId = 1
            }, CancellationToken.None);

            IEnumerable <UserModel> friends2 = await getHandler.Handle(new GetFriendsQuery()
            {
                UserId = 2
            }, CancellationToken.None);

            IEnumerable <UserModel> friends3 = await getHandler.Handle(new GetFriendsQuery()
            {
                UserId = 3
            }, CancellationToken.None);

            Assert.True(friends1.All(user => user.Id == 2 || user.Id == 3));
            Assert.Single(friends2, user => user.Id == 1);
            Assert.Single(friends3, user => user.Id == 1);
            Assert.Contains(Friendships, friendship => friendship.Friend1Id == 1 && friendship.Friend2Id == 2);
            Assert.Contains(Friendships, friendship => friendship.Friend1Id == 1 && friendship.Friend2Id == 3);
            Assert.NotEmpty(_jon.Friends);
            Assert.NotEmpty(_jon.FriendsOf);
            Assert.NotEmpty(_danny.Friends);
            Assert.NotEmpty(_danny.FriendsOf);
            Assert.NotEmpty(_ghost.Friends);
            Assert.NotEmpty(_ghost.FriendsOf);
        }
        public string DispatchCommand(string[] commandParameters)
        {
            string commandToExecute = commandParameters[0].ToLower();
            string result           = null;

            switch (commandToExecute)
            {
            case "registeruser":
                result = RegisterUserCommand.Execute(commandParameters);
                break;

            case "addtown":
                result = AddTownCommand.Execute(commandParameters);
                break;

            case "modifyuser":
                result = ModifyUserCommand.Execute(commandParameters);
                break;

            case "deleteuser":
                result = DeleteUser.Execute(commandParameters);
                break;

            case "addtag":
                result = AddTagCommand.Execute(commandParameters);
                break;

            case "addfriend":
                result = AddFriendCommand.Execute(commandParameters);
                break;

            case "createalbum":
                result = CreateAlbumCommand.Execute(commandParameters);
                break;

            case "exit":
                break;

            default:
                throw new InvalidOperationException($"Command {commandToExecute} not valid!");
            }

            return(result);
        }
        public void ShouldReturnNotificationWhenNameIsEmpty()
        {
            var expected = new List <Notification>()
            {
                new Notification("Name", "Nome não pode ser vazio ou nulo.")
            };

            var friend = new AddFriendCommand()
            {
                Name      = string.Empty,
                Latitude  = 0,
                Longitude = 0
            };

            friend.Validate();

            friend.Valid.Should().BeFalse();
            friend.Notifications.Should().BeEquivalentTo(expected);
        }
        public void ShouldReturnErrorMessageWhenCommandIsInvalid()
        {
            var addFriendHandler = new AddFriendHandler(this.friendRepository);

            var command = new AddFriendCommand()
            {
                Name      = null,
                Latitude  = 1234,
                Longitude = 4321
            };

            var result = addFriendHandler.Handler(command);

            result.IsSuccessful.Should().BeFalse();
            result.Messages.Should()
            .Contain(m =>
                     m.MessageType == MessageType.Validation &&
                     m.Property == "Name" &&
                     m.Description == "Nome não pode ser vazio ou nulo.");
        }
        public void ShouldReturnSuccessfulWhenNotExistsNotifications()
        {
            A.CallTo(() => this.friendRepository.LocationAlreadyExists(A <int> .Ignored, A <int> .Ignored)).Returns(false);
            A.CallTo(() => this.friendRepository.Add(A <Friend> .Ignored)).Returns(true);

            var addFriendHandler = new AddFriendHandler(this.friendRepository);

            var command = new AddFriendCommand()
            {
                Name      = "Some Name",
                Latitude  = 1234,
                Longitude = 4321
            };

            var result = addFriendHandler.Handler(command);

            result.IsSuccessful.Should().BeTrue();
            result.Messages.Should()
            .Contain(m =>
                     m.MessageType == MessageType.Information &&
                     m.Description == "Amigo cadastrado com sucesso!");
        }
        public void ShouldReturnErrorMessageWhenHasAnotherFriendInSameLocation()
        {
            A.CallTo(() => this.friendRepository.LocationAlreadyExists(A <int> .Ignored, A <int> .Ignored))
            .Returns(true);

            var addFriendHandler = new AddFriendHandler(this.friendRepository);

            var command = new AddFriendCommand()
            {
                Name      = "Some Name",
                Latitude  = 1234,
                Longitude = 4321
            };

            var result = addFriendHandler.Handler(command);

            result.IsSuccessful.Should().BeFalse();
            result.Messages.Should()
            .Contain(m =>
                     m.MessageType == MessageType.Validation &&
                     m.Property == "Location" &&
                     m.Description == "Já existe um amigo cadastrado nesta localização.");
        }
        public string DispatchCommand(string[] commandParameters)
        {
            string commandName = commandParameters[0];

            var    commandArg = commandParameters.Skip(1).ToArray();
            string result     = string.Empty;

            switch (commandName)
            {
            case "RegisterUser":
                var registerUser = new RegisterUserCommand();
                result = registerUser.Execute(commandArg);
                break;

            case "AddTown":
                var addTown = new AddTownCommand();
                result = addTown.Execute(commandArg);
                break;

            case "ModifyUser":
                var modifyUser = new ModifyUserCommand();
                result = modifyUser.Execute(commandArg);
                break;

            case "DeleteUser":
                var deleteUser = new DeleteUser();
                result = deleteUser.Execute(commandArg);
                break;

            case "AddTag":
                var tag = new AddTagCommand();
                result = tag.Execute(commandArg);
                break;

            case "CreateAlbum":
                var album = new CreateAlbumCommand();
                result = album.Execute(commandArg);
                break;

            case "AddTagTo":
                var tagTo = new AddTagToCommand();
                result = tagTo.Execute(commandArg);
                break;

            case "AddFriend":
                var addFriend = new AddFriendCommand();
                result = addFriend.Execute(commandArg);
                break;

            case "AcceptFriend":
                var acceptFriend = new AcceptFriendCommand();
                result = acceptFriend.Execute(commandArg);
                break;

            case "ListFriends":
                var listFriend = new PrintFriendsListCommand();
                result = listFriend.Execute(commandArg);
                break;

            case "ShareAlbum":
                var shareAlbum = new ShareAlbumCommand();
                result = shareAlbum.Execute(commandArg);
                break;

            case "UploadPicture":
                var uploadPicture = new UploadPictureCommand();
                result = uploadPicture.Execute(commandArg);
                break;

            case "Exit":
                ExitCommand.Execute();
                break;

            case "Login":
                var login = new LoginCommand();
                result = login.Execute(commandArg);
                break;

            case "Logout":
                var logout = new LogoutCommand();
                result = logout.Execute();
                break;

            default:
                throw new InvalidOperationException($"Command {commandName} not valid!");
            }

            return(result);
        }
Exemplo n.º 20
0
        public string DispatchCommand(string[] commandParameters)
        {
            string command = commandParameters[0].ToLower();
            string result  = default(string);

            switch (command)
            {
            case "registeruser":
                result = RegisterUserCommand.Execute(commandParameters);
                break;

            case "addtown":
                result = AddTownCommand.Execute(commandParameters);
                break;

            case "modifyuser":
                result = ModifyUserCommand.Execute(commandParameters);
                break;

            case "deleteuser":
                result = DeleteUser.Execute(commandParameters);
                break;

            case "addtag":
                result = AddTagCommand.Execute(commandParameters);
                break;

            case "createalbum":
                result = CreateAlbumCommand.Execute(commandParameters);
                break;

            case "makefriends":
                result = AddFriendCommand.Execute(commandParameters);
                break;

            case "addtagto":
                result = AddTagToCommand.Execute(commandParameters);
                break;

            case "acceptfriend":
                result = AcceptFriendCommand.Execute(commandParameters);
                break;

            case "listfriends":
                result = PrintFriendsListCommand.Execute(commandParameters);
                break;

            case "sharealbum":
                result = ShareAlbumCommand.Execute(commandParameters);
                break;

            case "uploadpicture":
                result = UploadPictureCommand.Execute(commandParameters);
                break;

            case "login":
                var authenticationService = new AuthenticationService();
                var userService           = new UserService();

                var login = new LoginCommand(authenticationService, userService);
                result = login.Execute(commandParameters);
                break;

            case "logout":
                authenticationService = new AuthenticationService();
                userService           = new UserService();

                var logOut = new LogoutCommand(authenticationService, userService);
                result = logOut.Execute();
                break;

            case "exit":
                result = ExitCommand.Execute();
                break;

            default:
                throw new InvalidOperationException($"Command {command} not valid!");
            }

            return(result);
        }
        public async Task <ActionResult> AddFriend(AddFriendCommand request)
        {
            await Mediator.Send(request);

            return(Ok());
        }
Exemplo n.º 22
0
        public string DispatchCommand(string[] commandParameters)
        {
            var commands = commandParameters.Select(x => x.ToLower()).ToArray();


            if (commands.Length == 5 && commands[0] == "registeruser")
            {
                return(RegisterUserCommand.Execute(commands));
            }

            else if (commands[0] == "login" && commands.Length == 3)
            {
                return(LoginCommand.Execute(commands));
            }

            if (commands.Length == 3 && commands[0] == "addtown")
            {
                return(AddTownCommand.Execute(commands));
            }

            else if (commands.Length == 4 && commands[0] == "modifyuser")
            {
                return(ModifyUserCommand.Execute(commands));
            }

            else if (commands.Length == 2 && commands[0] == "deleteuser")
            {
                return(DeleteUser.Execute(commands));
            }
            else if (commands.Length == 2 && commands[0] == "addtag")
            {
                return(AddTagCommand.Execute(commands));
            }

            else if (commands[0] == "createalbum" && commands.Length >= 5)
            {
                return(CreateAlbumCommand.Execute(commands));
            }

            else if (commands[0] == "addtagto" && commands.Length == 3)
            {
                return(AddTagToCommand.Execute(commands));
            }

            else if (commands[0] == "addfriend" && commands.Length == 3)
            {
                return(AddFriendCommand.Execute(commands));
            }

            else if (commands[0] == "acceptfriend" && commands.Length == 3)
            {
                return(AcceptFriendCommand.Execute(commands));
            }

            else if (commands[0] == "listfriends" && commands.Length == 2)
            {
                return(PrintFriendsListCommand.Execute(commands));
            }

            else if (commands[0] == "sharealbum" && commands.Length == 4)
            {
                return(ShareAlbumCommand.Execute(commands));
            }

            else if (commands[0] == "uploadpicture" && commands.Length == 4)
            {
                return(UploadPictureCommand.Execute(commands));
            }

            else if (commands[0] == "logout" && commands.Length == 1)
            {
                return(LogOutCommand.Execute(commands));
            }

            else if (commands[0] == "exit" && commands.Length == 1)
            {
                return(ExitCommand.Execute());
            }

            return($"Command not valid!");
        }
Exemplo n.º 23
0
        public string DispatchCommand(string[] commandParameters, Session session)
        {
            string command = commandParameters.First();

            string[] parameters      = commandParameters.Skip(1).ToArray();
            int      parametersCount = parameters.Length;

            string output = string.Empty;

            switch (command.ToLower())
            {
            case "login":
                ValidateCommandParametersCount(command, parameters.Length, 2, true);
                output = LoginCommand.Execute(parameters, session);
                break;

            case "logout":
                ValidateCommandParametersCount(command, parameters.Length, 0, true);
                output = LogoutCommand.Execute(session);
                break;

            case "registeruser":
                ValidateCommandParametersCount(command, parameters.Length, 4, true);
                output = RegisterUserCommand.Execute(parameters, session);
                break;

            case "addtown":
                ValidateCommandParametersCount(command, parameters.Length, 2, true);
                output = AddTownCommand.Execute(parameters, session);
                break;

            case "modifyuser":
                ValidateCommandParametersCount(command, parameters.Length, 3, true);
                output = ModifyUserCommand.Execute(parameters, session);
                break;

            case "deleteuser":
                ValidateCommandParametersCount(command, parameters.Length, 1, true);
                output = DeleteUser.Execute(parameters, session);
                break;

            case "addtag":
                ValidateCommandParametersCount(command, parameters.Length, 1, true);
                output = AddTagCommand.Execute(parameters, session);
                break;

            case "createalbum":
                ValidateCommandParametersCount(command, parameters.Length, 3, false);
                output = CreateAlbumCommand.Execute(parameters, session);
                break;

            case "addtagto":
                ValidateCommandParametersCount(command, parameters.Length, 2, true);
                output = AddTagToCommand.Execute(parameters, session);
                break;

            case "makefriends":
                ValidateCommandParametersCount(command, parameters.Length, 2, true);
                output = AddFriendCommand.Execute(parameters, session);
                break;

            case "acceptfriend":
                ValidateCommandParametersCount(command, parameters.Length, 2, true);
                output = AcceptFriendCommand.Execute(parameters, session);
                break;

            case "listfriends":
                ValidateCommandParametersCount(command, parameters.Length, 1, true);
                output = PrintFriendsListCommand.Execute(parameters, session);
                break;

            case "sharealbum":
                ValidateCommandParametersCount(command, parameters.Length, 3, true);
                output = ShareAlbumCommand.Execute(parameters, session);
                break;

            case "uploadpicture":
                ValidateCommandParametersCount(command, parameters.Length, 3, true);
                output = UploadPictureCommand.Execute(parameters, session);
                break;

            case "exit":
                ValidateCommandParametersCount(command, parameters.Length, 0, true);
                output = ExitCommand.Execute();
                break;

            default:
                throw new
                      InvalidOperationException($"Command {command} not valid!");
            }

            return(output);
        }
Exemplo n.º 24
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);
        }
 public IActionResult AddFriend([FromBody] AddFriendCommand addFriendCommand, [FromServices] IAddFriendHandler addFriendHandler)
 {
     return(DefineCorrectlyResult(addFriendHandler.Handler(addFriendCommand)));
 }
        public string DispatchCommand(string[] commandParameters, Session session)
        {
            string command = commandParameters[0].ToLower();

            string result = "";

            switch (command)
            {
            case "login":
                result = LogInCommand.Execute(commandParameters, session);
                break;

            case "logout":
                result = LogoutCommand.Execute(session);
                break;

            case "exit":
                result = ExitCommand.Execute();
                break;

            case "registeruser":
                result = RegisterUserCommand.Execute(commandParameters);
                break;

            case "uploadpicture":
                result = UploadPictureCommand.Execute(commandParameters);
                break;

            case "sharealbum":
                result = ShareAlbumCommand.Execute(commandParameters);
                break;

            case "listfriends":
                result = PrintFriendsListCommand.Execute(session);
                break;

            case "acceptfriend":
                result = AcceptFriendCommand.Execute(commandParameters, session);
                break;

            case "addfriend":
                result = AddFriendCommand.Execute(commandParameters, session);
                break;

            case "addtagto":
                result = AddTagToCommand.Execute(commandParameters);
                break;

            case "createalbum":
                result = CreateAlbumCommand.Execute(commandParameters, session);
                break;

            case "addtown":
                result = AddTownCommand.Execute(commandParameters);
                break;

            case "modifyuser":
                result = ModifyUserCommand.Execute(commandParameters, session);
                break;

            case "addtag":
                result = AddTagCommand.Execute(commandParameters);
                break;

            case "deleteuser":
                result = DeleteUser.Execute(session);
                break;

            default:
                throw new InvalidOperationException($"Command {command} not valid!");
            }
            return(result);
        }
Exemplo n.º 27
0
        public string DispatchCommand(string[] commandParameters)
        {
            var command = commandParameters[0];

            if (loggedInUserCommands.Contains(command) && Session.User == null)
            {
                throw new InvalidOperationException("Invalid credentials!");
            }

            var args = commandParameters.Skip(1).ToArray();

            var returnValue = "";

            switch (command)
            {
            case "Login":
                returnValue = LogInCommand.Execute(args);
                break;

            case "RegisterUser":
                returnValue = RegisterUserCommand.Execute(args);
                break;

            case "ListFriends":
                returnValue = PrintFriendsListCommand.Execute(args);
                break;

            case "Logout":
                returnValue = LogOutCommand.Execute(args);
                break;

            case "AddTown":
                returnValue = AddTownCommand.Execute(args);
                break;

            case "ModifyUser":
                returnValue = ModifyUserCommand.Execute(args);
                break;

            case "DeleteUser":
                returnValue = DeleteUser.Execute(args);
                break;

            case "AddTag":
                returnValue = AddTagCommand.Execute(args);
                break;

            case "CreateAlbum":
                returnValue = CreateAlbumCommand.Execute(args);
                break;

            case "AddTagTo":
                returnValue = AddTagToCommand.Execute(args);
                break;

            case "AddFriend":
                returnValue = AddFriendCommand.Execute(args);
                break;

            case "AcceptFriend":
                returnValue = AcceptFriendCommand.Execute(args);
                break;

            case "ShareAlbum":
                returnValue = ShareAlbumCommand.Execute(args);
                break;

            case "UploadPicture":
                returnValue = UploadPictureCommand.Execute(args);
                break;

            case "Exit":
                returnValue = ExitCommand.Execute();
                break;

            default:
                throw new InvalidOperationException($"Command {command} not valid!");
            }
            return(returnValue);
        }