Ejemplo n.º 1
0
        public async void CreateAlbumTest()
        {
            var genreId  = RandomId.NewId();
            var objGenre = new Genre(genreId, "genre test");

            objGenre.AddCashbackConfig(new Domain.Models.Cashback(null, genreId, System.DayOfWeek.Monday, 10));
            await DbContext.Genres.AddAsync(objGenre);

            await DbContext.SaveChangesAsync();

            var id  = RandomId.NewId();
            var cmd = new CreateAlbumCommand()
            {
                Id        = id,
                Name      = "Test Genre 1",
                GenreId   = genreId,
                SpotifyId = null
            };

            var result = await CommandsHandler.Handle(cmd);

            var obj = await DbContext.Albums.Where(w => w.Id == id).FirstOrDefaultAsync();

            Assert.NotNull(result);
            Assert.NotNull(obj);
            Assert.Equal(ErrorCode.None, result.ErrorCode);
            Assert.Equal(id, obj.Id);
            Assert.True(result.Rows > 0);
        }
        public async Task <IActionResult> CreateAlbum(int groupId, [FromBody] JsCreateAlbum albumInfo)
        {
            var command  = new CreateAlbumCommand(groupId, _mapper.Map <AlbumInfo>(albumInfo));
            var response = await _mediator.Send(command);

            return(_presenter.ToActionResult(response));
        }
Ejemplo n.º 3
0
        public ICommandResult Handle(CreateAlbumCommand command)
        {
            var categoryQuery = _categoryRepository.GetById(command.CategoryId);
            var genderQuery   = _genderRepository.GetById(command.GenderId);

            Gender   gender   = new Gender(genderQuery.Id, genderQuery.Title, genderQuery.Description);
            Category category = new Category(categoryQuery.Id, categoryQuery.Title, categoryQuery.Description);
            Album    album    = new Album(command.Title, gender, category, command.Image);

            AddNotifications(album.Notifications);

            if (Invalid)
            {
                return(new CommandResult(false, MessagesUtil.FormFail, Notifications));
            }

            bool result = _repository.Create(album);

            if (!result)
            {
                return(new CommandResult(false, MessagesUtil.CreateError, Notifications));
            }

            return(new CommandResult(true, MessagesUtil.CreatedSuccess));
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        private string TryCreateAlbum(string command, string[] commandParams)
        {
            if (commandParams.Length < 4)
            {
                ThrowInvalidCommand(command);
            }

            var commandObj = new CreateAlbumCommand();

            return(commandObj.Execute(commandParams));
        }
Ejemplo n.º 6
0
        public async Task <AlbumModel> CreateAlbum(AlbumModel album)
        {
            var command = new CreateAlbumCommand
            {
                AlbumId    = 0,
                AlbumName  = album.Name,
                ArtistName = album.Artists.FirstOrDefault()?.Name,
                Type       = (int)album.Type,
                Stock      = album.Inventory.Stock,
            };

            var result = await _mediator.Send(command);

            album.Id = result;
            return(album);
        }
        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);
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> PostCreateAlbum([FromForm] CreateAlbumCommand command)
        {
            var response = await Mediator.Send(command);

            return(Json(new { Id = response }));
        }
Ejemplo n.º 9
0
        public string DispatchCommand(string[] commandParameters)
        {
            string commandName = commandParameters[0];

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

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

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

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

            case "DeleteUser":
                DeleteUserCommand deleteUser = new DeleteUserCommand();
                result = deleteUser.Execute(commandParameters);
                break;

            case "AddTag":
                AddTagCommand addTag = new AddTagCommand();
                result = addTag.Execute(commandParameters);
                break;

            case "CreateAlbum":
                CreateAlbumCommand createAlbum = new CreateAlbumCommand();
                result = createAlbum.Execute(commandParameters);
                break;

            case "AddTagTo":
                AddTagToCommand addTagTo = new AddTagToCommand();
                result = addTagTo.Execute(commandParameters);
                break;

            case "MakeFriends":
                MakeFriendsCommand makeFriend = new MakeFriendsCommand();
                result = makeFriend.Execute(commandParameters);
                break;

            case "ListFriends":
                PrintFriendsListCommand listFriends = new PrintFriendsListCommand();
                result = listFriends.Execute(commandParameters);
                break;

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

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

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

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

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

            default:
                Console.WriteLine($"Command {commandName} not valid!");
                break;
            }

            return(result);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
 public ICommandResult Create([FromBody] CreateAlbumCommand command)
 {
     return(_handler.Handle(command));
 }
Ejemplo n.º 13
0
        public async Task <CommandResult> ExecuteAsync(CashbackCommandsHandler handler)
        {
            if (handler.DbContext.Albums.Count() > 0)
            {
                return(await Task.FromResult(new CommandResult(ErrorCode.None)));
            }

            var genres = handler.DbContext.Genres;

            if (genres == null || genres.Count() == 0)
            {
                await handler.Handle(new PopulateGenresCommand());
            }

            if (string.IsNullOrEmpty(AccessToken))
            {
                Authorize();
            }

            IList <AlbumViewModel> result = new List <AlbumViewModel>();

            HttpClient httpClient = new HttpClient();
            var        rows       = 0;

            HttpResponseMessage response = null;

            foreach (var genre in genres)
            {
                var baseUrl = "search?query={genre}&type=album&market=BR&offset=0&limit=50";
                httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", AccessToken);
                response = await httpClient.GetAsync("https://api.spotify.com/v1/" + baseUrl.Replace("{genre}", genre.Name.ToLower()));

                if (response.IsSuccessStatusCode)
                {
                    var json = JsonConvert.DeserializeAnonymousType(await response.Content.ReadAsStringAsync(),
                                                                    new
                    {
                        albums = new
                        {
                            href  = string.Empty,
                            items = new[]
                            {
                                new {
                                    id   = string.Empty,
                                    name = string.Empty
                                }
                            }
                        }
                    });

                    foreach (var item in json.albums.items)
                    {
                        result.Add(new AlbumViewModel()
                        {
                            Name    = item.name,
                            GenreId = genre.Id,
                            Id      = item.id
                        });
                    }
                }
            }

            foreach (var item in result)
            {
                var id  = RandomId.NewId();
                var cmd = new CreateAlbumCommand()
                {
                    Id        = id,
                    SpotifyId = item.Id,
                    GenreId   = item.GenreId,
                    Name      = item.Name
                };

                var rs = await handler.Handle(cmd);

                rows += rs.Rows;
            }

            return(await Task.FromResult(new CommandResult(rows, ErrorCode.None)));
        }
Ejemplo n.º 14
0
 public Task <AlbumList> Post([FromBody] CreateAlbumCommand command)
 {
     return(Mediator.Send(command));
 }
Ejemplo n.º 15
0
        public string DispatchCommand(string[] commandParameters)
        {
            string commandName = commandParameters[0];

            commandParameters = commandParameters.Skip(1).ToArray(); // skipping commandName

            string result = string.Empty;

            UserService    userService    = new UserService();
            TownService    townService    = new TownService();
            TagService     tagService     = new TagService();
            AlbumService   albumService   = new AlbumService();
            PictureService pictureService = new PictureService();

            switch (commandName)
            {
            // 1. Photo Share System
            case "RegisterUser":
                ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 4);
                RegisterUserCommand registerUser = new RegisterUserCommand(userService);
                result = registerUser.Execute(commandParameters);
                break;

            case "AddTown":
                ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 2);
                AddTownCommand addTown = new AddTownCommand(townService);
                result = addTown.Execute(commandParameters);
                break;

            case "ModifyUser":
                ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 3);
                ModifyUserCommand modifyUser = new ModifyUserCommand(userService, townService);
                result = modifyUser.Execute(commandParameters);
                break;

            case "DeleteUser":
                ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 1);
                DeleteUserCommand deleteUser = new DeleteUserCommand(userService);
                result = deleteUser.Execute(commandParameters);
                break;

            case "AddTag":
                ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 1);
                AddTagCommand addTag = new AddTagCommand(tagService);
                result = addTag.Execute(commandParameters);
                break;

            case "CreateAlbum":
                ValidateInput.CheckMinInputArgsCount(commandName, commandParameters.Count(), 4);
                CreateAlbumCommand createAlbum = new CreateAlbumCommand(userService, albumService, tagService);
                result = createAlbum.Execute(commandParameters);
                break;

            case "AddTagTo":
                ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 2);
                AddTagToCommand addTagTo = new AddTagToCommand(albumService, tagService);
                result = addTagTo.Execute(commandParameters);
                break;

            case "MakeFriends":
                ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 2);
                MakeFriendsCommand makeFriends = new MakeFriendsCommand(userService);
                result = makeFriends.Execute(commandParameters);
                break;

            case "ListFriends":
                ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 1);
                ListFriendsCommand listFriends = new ListFriendsCommand(userService);
                result = listFriends.Execute(commandParameters);
                break;

            case "ShareAlbum":
                ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 3);
                ShareAlbumCommand shareAlbum = new ShareAlbumCommand(userService, albumService);
                result = shareAlbum.Execute(commandParameters);
                break;

            case "UploadPicture":
                ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 3);
                UploadPictureCommand uploadPicture = new UploadPictureCommand(albumService, pictureService);
                result = uploadPicture.Execute(commandParameters);
                break;

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

            // 2. Extend Photo Share System
            case "Login":
                ValidateInput.CheckExactInputArgsCount(commandName, commandParameters.Count(), 2);
                LoginCommand login = new LoginCommand(userService);
                result = login.Execute(commandParameters);
                break;

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

            // 1. Photo Share System
            default:
                throw new InvalidOperationException($"Command <{commandName}> not valid!");
            }

            return(result);
        }
Ejemplo n.º 16
0
        public string DispatchCommand(string[] commandParameters)
        {
            string commandName = commandParameters[0];

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

            switch (commandName)
            {
            case "RegisterUser":
                if (commandParameters.Count() != 4)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                RegisterUserCommand registerUser = new RegisterUserCommand(new UserService());
                result = registerUser.Execute(commandParameters);
                break;

            case "AddTown":
                if (commandParameters.Count() != 2)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                AddTownCommand addTown = new AddTownCommand(new TownService());
                result = addTown.Execute(commandParameters);
                break;

            case "ModifyUser":
                if (commandParameters.Count() != 3)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                ModifyUserCommand modifyUser = new ModifyUserCommand(new UserService(), new TownService());
                result = modifyUser.Execute(commandParameters);
                break;

            case "DeleteUser":
                if (commandParameters.Count() != 1)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                DeleteUserCommand deleteUser = new DeleteUserCommand(new UserService());
                result = deleteUser.Execute(commandParameters);
                break;

            case "AddTag":
                if (commandParameters.Count() != 1)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                AddTagCommand addTag = new AddTagCommand(new TagService());
                result = addTag.Execute(commandParameters);
                break;

            case "CreateAlbum":
                if (commandParameters.Count() < 4)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                CreateAlbumCommand createAlbum = new CreateAlbumCommand(new AlbumService(), new UserService(), new TagService());
                result = createAlbum.Execute(commandParameters);
                break;

            case "AddTagTo":
                if (commandParameters.Count() != 2)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                AddTagToCommand addTagTo = new AddTagToCommand(new TagService(), new AlbumService());
                result = addTagTo.Execute(commandParameters);
                break;

            case "MakeFriends":
                if (commandParameters.Count() != 2)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                MakeFriendsCommand makeFriends = new MakeFriendsCommand(new UserService());
                result = makeFriends.Execute(commandParameters);
                break;

            case "ListFriends":
                if (commandParameters.Count() != 1)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                PrintFriendsListCommand printFriends = new PrintFriendsListCommand(new UserService());
                result = printFriends.Execute(commandParameters);
                break;

            case "ShareAlbum":
                if (commandParameters.Count() != 3)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                ShareAlbumCommand shareAlbum = new ShareAlbumCommand(new UserService(), new AlbumService());
                result = shareAlbum.Execute(commandParameters);
                break;

            case "UploadPicture":
                if (commandParameters.Count() != 3)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                UploadPictureCommand uploadPicture = new UploadPictureCommand(new AlbumService(), new PictureService());
                result = uploadPicture.Execute(commandParameters);
                break;

            case "Login":
                if (commandParameters.Count() != 2)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                LoginCommand loginCommand = new LoginCommand(new AuthenticationService(), new UserService());
                result = loginCommand.Execute(commandParameters);
                break;

            case "Logout":
                if (commandParameters.Count() > 0)
                {
                    throw new InvalidOperationException($"Command {commandName} not valid!");
                }
                LogoutCommand logoutCommand = new LogoutCommand(new AuthenticationService(), new UserService());
                result = logoutCommand.Execute();
                break;

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

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

            return(result);
        }
Ejemplo n.º 17
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!");
        }
Ejemplo n.º 18
0
 public async Task <ActionResult <AlbumDto> > CreateAlbum(CreateAlbumCommand command)
 => Ok(await _mediator.Send(command));
Ejemplo n.º 19
0
        public async Task <ActionResult <ResponseWrapper> > CreateAlbumAsync([FromBody] CreateAlbumCommand command)
        {
            var result = await _mediator.Send(command);

            return(Ok(ResponseWrapper.CreateOkResponseWrapper(result)));
        }
Ejemplo n.º 20
0
        public string DispatchCommand(string[] commandParameters)
        {
            PictureService pictureService = new PictureService();
            AlbumService   albumService   = new AlbumService();
            UserService    userService    = new UserService();
            TownService    townService    = new TownService();
            TagService     tagService     = new TagService();

            string commandName = commandParameters[0];

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

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

            case "AddTown":
                AddTownCommand addTown = new AddTownCommand(townService);
                result = addTown.Execute(commandParameters);
                break;

            case "ModifyUser":
                ModifyUserCommand modifyUser = new ModifyUserCommand(userService, townService);
                result = modifyUser.Execute(commandParameters);
                break;

            case "DeleteUser":
                DeleteUserCommand deleteUser = new DeleteUserCommand(userService);
                result = deleteUser.Execute(commandParameters);
                break;

            case "AddTag":
                AddTagCommand addTag = new AddTagCommand(tagService);
                result = addTag.Execute(commandParameters);
                break;

            case "CreateAlbum":
                CreateAlbumCommand createAlbum = new CreateAlbumCommand(albumService, userService, tagService);
                result = createAlbum.Execute(commandParameters);
                break;

            case "AddTagTo":
                AddTagToCommand addTagTo = new AddTagToCommand(albumService, tagService);
                result = addTagTo.Execute(commandParameters);
                break;

            case "MakeFriends":
                MakeFriendsCommand makeFriends = new MakeFriendsCommand(userService);
                result = makeFriends.Execute(commandParameters);
                break;

            case "ListFriends":
                ListFriendsCommand listFriends = new ListFriendsCommand(userService);
                result = listFriends.Execute(commandParameters);
                break;

            case "ShareAlbum":
                ShareAlbumCommand shareAlbum = new ShareAlbumCommand(albumService, userService);
                result = shareAlbum.Execute(commandParameters);
                break;

            case "UploadPicture":
                UploadPictureCommand uploadPicture = new UploadPictureCommand(albumService, pictureService);
                result = uploadPicture.Execute(commandParameters);
                break;

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

            case "Login":
                LoginUserCommand loginUser = new LoginUserCommand();
                result = loginUser.Execute(commandParameters);
                break;

            case "Logout":
                LogoutUserCommand logoutUser = new LogoutUserCommand();
                result = logoutUser.Execute(commandParameters);
                break;

            default:
                result = $"Command {commandName} not valid!";
                break;
            }

            return(result);
        }
        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);
        }
Ejemplo n.º 22
0
        public string DispatchCommand(string[] commandParameters)
        {
            var userService     = new UserService();
            var townService     = new TownService();
            var tagService      = new TagService();
            var albumService    = new AlbumService();
            var pictureService  = new PictureService();
            var securityService = new SecurityService();

            string command = commandParameters[0];

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

            switch (command)
            {
            case "RegisterUser":
                var registerUser = new RegisterUserCommand(userService);
                result = registerUser.Execute(commandParameters);
                break;

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

            case "ModifyUser":
                var modifyUser = new ModifyUserCommand(userService, townService);
                result = modifyUser.Execute(commandParameters);
                break;

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

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

            case "AddTag":
                var addTag = new AddTagCommand(tagService);
                result = addTag.Execute(commandParameters);
                break;

            case "CreateAlbum":
                var createAlbum = new CreateAlbumCommand(albumService, userService, tagService);
                result = createAlbum.Execute(commandParameters);
                break;

            case "AddTagTo":
                var addTagTo = new AddTagToCommand(tagService, albumService);
                result = addTagTo.Execute(commandParameters);
                break;

            case "MakeFriends":
                var makeFriends = new MakeFriendsCommand(userService);
                result = makeFriends.Execute(commandParameters);
                break;

            case "ListFriends":
                var listFriends = new ListFriendsCommand(userService);
                result = listFriends.Execute(commandParameters);
                break;

            case "ShareAlbum":
                var shareAlbum = new ShareAlbumCommand(albumService, userService);
                result = shareAlbum.Execute(commandParameters);
                break;

            case "UploadPicture":
                var uploadPicture = new UploadPictureCommand(pictureService, albumService);
                result = uploadPicture.Execute(commandParameters);
                break;

            case "Login":
                var loginCommand = new LoginCommand(securityService);
                result = loginCommand.Execute(commandParameters);
                break;

            case "Logout":
                var logoutCommand = new LogoutCommand(securityService);
                result = logoutCommand.Execute();
                break;
            }
            return(result);
        }
Ejemplo n.º 23
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 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);
        }
Ejemplo n.º 25
0
        public string DispatchCommand(string[] commandParameters)
        {
            string result;

            switch (commandParameters[0])
            {
            case "RegisterUser":        ////
                if (commandParameters.Length != 5)
                {
                    goto default;
                }
                AccessAsLoggedOut();
                Commands.RegisterUserCommand registerUser = new RegisterUserCommand();
                result = registerUser.Execute(commandParameters.Skip(1).ToArray());
                break;

            case "AddTown":        ////
                if (commandParameters.Length != 3)
                {
                    goto default;
                }
                AccessAsLoggedIn(commandParameters);
                Commands.AddTownCommand addTown = new AddTownCommand();
                result = addTown.Execute(commandParameters.Skip(1).ToArray());
                break;

            case "ModifyUser":        ////
                if (commandParameters.Length != 3)
                {
                    goto default;
                }
                AccessAsLoggedIn(commandParameters);
                Commands.ModifyUserCommand modifyUser = new ModifyUserCommand();
                result = modifyUser.Execute(commandParameters.Skip(1).ToArray());
                break;

            case "DeleteUser":        ////
                if (commandParameters.Length != 1)
                {
                    goto default;
                }
                AccessAsLoggedIn(commandParameters);
                Commands.DeleteUserCommand deleteUser = new DeleteUserCommand();
                result = deleteUser.Execute();
                break;

            case "AddTag":        ////
                if (commandParameters.Length != 2)
                {
                    goto default;
                }
                AccessAsLoggedIn(commandParameters);
                Commands.AddTagCommand addTag = new AddTagCommand();
                result = addTag.Execute(commandParameters.Skip(1).ToArray());
                break;

            case "CreateAlbum":        ////
                if (commandParameters.Length < 2)
                {
                    goto default;
                }
                AccessAsLoggedIn(commandParameters);
                Commands.CreateAlbumCommand createAlbum = new CreateAlbumCommand();
                result = createAlbum.Execute(commandParameters.Skip(1).ToArray());
                break;

            case "AddTagTo":        ////
                if (commandParameters.Length != 3)
                {
                    goto default;
                }
                AccessAsLoggedIn(commandParameters);
                Commands.AddTagToCommand addTagTo = new AddTagToCommand();
                result = addTagTo.Execute(commandParameters.Skip(1).ToArray());
                break;

            case "MakeFriends":        ////
                if (commandParameters.Length != 2)
                {
                    goto default;
                }
                AccessAsLoggedIn(commandParameters);
                Commands.MakeFriendsCommand makeFriends = new MakeFriendsCommand();
                result = makeFriends.Execute(commandParameters.Skip(1).ToArray());
                break;

            case "ListFriends":        ////
                if (commandParameters.Length != 2)
                {
                    goto default;
                }
                // both users can
                Commands.PrintFriendsListCommand printFriends = new PrintFriendsListCommand();
                result = printFriends.Execute(commandParameters.Skip(1).ToArray());
                break;

            case "ShareAlbum":        ////
                if (commandParameters.Length != 3)
                {
                    goto default;
                }
                AccessAsLoggedIn(commandParameters);
                Commands.ShareAlbumCommand shareAlbum = new ShareAlbumCommand();
                result = shareAlbum.Execute(commandParameters.Skip(1).ToArray());
                break;

            case "UploadPicture":        ////
                if (commandParameters.Length != 4)
                {
                    goto default;
                }
                AccessAsLoggedIn(commandParameters);
                Commands.UploadPictureCommand uppCommand = new UploadPictureCommand();
                result = uppCommand.Execute(commandParameters.Skip(1).ToArray());
                break;

            case "Exit":        ////
                if (commandParameters.Length != 1)
                {
                    goto default;
                }
                // both users can
                Commands.ExitCommand exit = new ExitCommand();
                result = exit.Execute();
                break;

            case "Login":        ////
                if (commandParameters.Length != 3)
                {
                    goto default;
                }
                AccessAsLoggedOut();
                Commands.LoginCommand login = new LoginCommand();
                result = login.Execute(commandParameters.Skip(1).ToArray());
                break;

            case "Logout":        ///
                if (commandParameters.Length != 1)
                {
                    goto default;
                }
                AccessAsLoggedIn(commandParameters);
                Commands.LogoutCommand logout = new LogoutCommand();
                result = logout.Execute();
                break;

            default:
                throw new InvalidOperationException($"Command {commandParameters[0]} not valid!");
            }

            return(result);
        }