protected override CommandResult Execute(ConsoleContext context, UsersAgruments arguments)
        {
            if (string.IsNullOrEmpty(arguments.Path))
            {
                return(new CommandResult($"Path{arguments.Path} jest pusty"));
            }

            var file    = new CsvReader <User>();
            var users   = file.LoadFile(arguments.Path);
            int success = 0;

            foreach (var user in users)
            {
                var result = WinApiConnector.RequestPost <User, Response <User> >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/User/SignUp", user);
                if (result.Result.IsSuccess)
                {
                    success++;
                }
                else
                {
                    log.Error(result.Result.Message);
                }
            }
            return(new CommandResult(success == users.Count ? "OK" : "Error! Sprawdź logi"));
        }
        protected override CommandResult Execute(ConsoleContext context, AnimalArguments arguments)
        {
            if (string.IsNullOrEmpty(arguments.Name))
            {
                return(new CommandResult("The name of animal is required, use param -n <NAME>"));
            }
            Task <ConnectorResult <Response <string> > > result = WinApiConnector.RequestPost <Animal, Response <string> >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/Configuration/AddAnimal",
                                                                                                                           new Animal()
            {
                Name = arguments.Name.ToLower()
            });
            ConnectorResult <Response <string> > connectorResult = result.Result;

            if (!connectorResult.IsSuccess)
            {
                return(new CommandResult(connectorResult.Message, false));
            }
            if (!connectorResult.Response.IsSuccess)
            {
                return(new CommandResult(connectorResult.Response.Code, false));
            }
            if (string.IsNullOrEmpty(connectorResult.Response.Payload))
            {
                return(new CommandResult("The payload of request is null or empty", false));
            }

            return(new CommandResult(connectorResult.Response.Payload, true));
        }
Exemple #3
0
        protected override CommandResult Execute(ConsoleContext context, RolesArguments arguments)
        {
            if (String.IsNullOrEmpty(arguments.Path))
            {
                System.Console.WriteLine($"Path {arguments.Path} is empty");
                return(new CommandResult());
            }

            var file         = new CsvReader <Role>();
            var listRoles    = file.LoadFile(arguments.Path);
            int successIndex = 0;

            foreach (var role in listRoles)
            {
                var result = WinApiConnector.RequestPost <Role, Response <Role> >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/Configuration/AddRole", role);
                if (result.Result.Response.IsSuccess)
                {
                    successIndex++;
                }
                else
                {
                    log.Error($"{result.Result.Message}");
                }
            }
            System.Console.WriteLine($"Dodano obiektów: {successIndex}");
            return(new CommandResult(successIndex == listRoles.Count ? "Ok": "Error. Check log file!"));
        }
        public HuntingClientResult Logout()
        {
            string path = "http://projecthunter.pl:80/Api/User/SignOut";
            Task <ConnectorResult <Guid> > postResult = WinApiConnector.RequestPost <Guid, Guid>(path, identifier);
            ConnectorResult <Guid>         result     = postResult.Result;

            if (!result.IsSuccess)
            {
                return(new HuntingClientResult(false, result.Message));
            }
            return(new HuntingClientResult(true, "You are sucessful logout."));
        }
        protected override CommandResult Execute(ConsoleContext context, RoleArgument arguments)
        {
            Role role = new Role()
            {
                Name = arguments.Name.ToLower()
            };
            Task <ConnectorResult <Response <IEnumerable <Role> > > > checkIfExist = WinApiConnector.RequestGet <Response <IEnumerable <Role> > >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/Configuration/GetRole/" +
                                                                                                                                                  $"{arguments.Name.ToLower()}");
            ConnectorResult <Response <IEnumerable <Role> > > preResult = checkIfExist.Result;

            if (!preResult.IsSuccess)
            {
                return(new CommandResult(preResult.Message, false));
            }
            if (!preResult.Response.IsSuccess)
            {
                return(new CommandResult(preResult.Response.Code, false));
            }
            if (preResult.Response.Payload.Any())
            {
                return(new CommandResult($"The Role {arguments.Name} exists in database"));
            }

            Task <ConnectorResult <Response <string> > > result          = WinApiConnector.RequestPost <Role, Response <string> >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/Configuration/AddRole", role);
            ConnectorResult <Response <string> >         connectorResult = result.Result;

            if (!connectorResult.IsSuccess)
            {
                return(new CommandResult(connectorResult.Message, false));
            }
            if (!connectorResult.Response.IsSuccess)
            {
                return(new CommandResult(connectorResult.Response.Code, false));
            }
            if (connectorResult.Response.Payload == null)
            {
                return(new CommandResult("The payload of reguest is null or empty", false));
            }
            return(new CommandResult($"The Role {arguments.Name} has been added"));
        }
Exemple #6
0
        protected override CommandResult Execute(ConsoleContext context, UserArguments arguments)
        {
            Task <ConnectorResult <Response <IEnumerable <Role> > > > roles           = WinApiConnector.RequestGet <Response <IEnumerable <Role> > >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/Configuration/GetAllRoles");
            ConnectorResult <Response <IEnumerable <Role> > >         connectorResult = roles.Result;

            if (!connectorResult.IsSuccess)
            {
                return(new CommandResult(connectorResult.Message, false));
            }

            if (!connectorResult.Response.IsSuccess)
            {
                return(new CommandResult(connectorResult.Response.Code, false));
            }

            if (!connectorResult.Response.Payload.Any())
            {
                return(new CommandResult("There are no roles for choice.", false));
            }

            Role[] roleArray = connectorResult.Response.Payload.ToArray();
            System.Console.WriteLine($"Wybierz role dla nowego użytkownika: (1 - {roleArray.Length})");

            int index = 1;

            foreach (Role item in roleArray)
            {
                System.Console.WriteLine($"{ index++ }. { item.Name.ToUpper() }");
            }

            int  chosenRoleIndex = 0;
            bool shouldWork      = true;

            do
            {
                System.Console.Write("Wybierz numer roli: ");
                string choice   = System.Console.ReadLine();
                bool   isParsed = int.TryParse(choice, out chosenRoleIndex);
                shouldWork = isParsed ? chosenRoleIndex > roleArray.Length : true;
            }while(shouldWork);

            var role = new Role()
            {
                Identifier = roleArray[chosenRoleIndex - 1].Identifier
            };

            var result = WinApiConnector.RequestPost <Model.User, Response <string> >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/User/SignUp",
                                                                                      new Model.User()
            {
                Login    = arguments.Login.ToLower(),
                Name     = arguments.Name.ToLower(),
                Password = arguments.Password,
                Surname  = arguments.Surname.ToLower(),
                Role     = role,
                Email    = arguments.Email.ToLower()
            });

            ConnectorResult <Response <string> > postResult = result.Result;

            if (!postResult.IsSuccess)
            {
                return(new CommandResult(postResult.Message, false));
            }

            if (!postResult.Response.IsSuccess)
            {
                return(new CommandResult(postResult.Response.Code, false));
            }

            if (string.IsNullOrEmpty(postResult.Response.Payload))
            {
                return(new CommandResult("The payload of user is empty.", false));
            }

            return(new CommandResult("The user has been added.", true));
        }
 public HuntingClientResult Login(Authentication authentication)
 {
     string path = "http://projecthunter.pl:80/Api/User/SignIn";
     Task <ConnectorResult <Guid> > postResult = WinApiConnector.RequestPost <Authentication, Guid>(path, authentication);
     ConnectorResult <Guid>         result     = postResult.Result;
 }
        protected override CommandResult Execute(ConsoleContext context, UserArgumentsExtension arguments)
        {
            IList <User> users      = new List <User>();
            User         deleteUser = new User();
            Guid         identifier = Guid.Empty;

            if (string.IsNullOrEmpty(arguments.Identifier) && string.IsNullOrEmpty(arguments.Login))
            {
                Task <ConnectorResult <Response <IEnumerable <User> > > > usersRequest = WinApiConnector.RequestGet <Response <IEnumerable <User> > >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/User/GetAll");
                ConnectorResult <Response <IEnumerable <User> > >         preResponse  = usersRequest.Result;

                if (!preResponse.IsSuccess)
                {
                    return(new CommandResult(preResponse.Message, false));
                }
                if (!preResponse.Response.IsSuccess)
                {
                    return(new CommandResult(preResponse.Response.Code, false));
                }
                if (!preResponse.Response.Payload.Any())
                {
                    return(new CommandResult("The payload od request is null or empty", false));
                }
                int index = 1;
                foreach (var ur in preResponse.Response.Payload)
                {
                    users.Add(ur);
                    System.Console.WriteLine($"{index++}. {ur.Login} - {ur.Identifier}");
                }

                System.Console.WriteLine($"Wybierz numer użytkownika do aktualizacji 1-{users.Count}");
                bool shouldWork = true;
                int  choisenOne = 0;
                do
                {
                    string readLine = System.Console.ReadLine();
                    bool   isParsed = int.TryParse(readLine, out choisenOne);
                    shouldWork = isParsed ? choisenOne > users.Count : true;
                }while(shouldWork);

                deleteUser.Identifier = users[choisenOne - 1].Identifier;
            }

            if (!string.IsNullOrEmpty(arguments.Identifier))
            {
                var tmp = Guid.TryParse(arguments.Identifier, out identifier);
                if (!tmp)
                {
                    return(new CommandResult("Cannot parse identifier from -i param", false));
                }

                deleteUser.Identifier = identifier;
            }
            if (!string.IsNullOrEmpty(arguments.Login) && string.IsNullOrEmpty(arguments.Identifier))
            {
                User tmpUser = new User()
                {
                    Login = arguments.Login
                };
                Task <ConnectorResult <Response <IEnumerable <User> > > > userByLogin = WinApiConnector.RequestPost <User, Response <IEnumerable <User> > >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/User/GetByLogin", tmpUser);
                ConnectorResult <Response <IEnumerable <User> > >         preResponse = userByLogin.Result;

                if (!preResponse.IsSuccess)
                {
                    return(new CommandResult(preResponse.Message, false));
                }
                if (!preResponse.Response.IsSuccess)
                {
                    return(new CommandResult(preResponse.Response.Code, false));
                }
                if (!preResponse.Response.Payload.Any())
                {
                    return(new CommandResult("The Payload of request is null or empty", false));
                }
                if (preResponse.Response.Payload.Count() != 1)
                {
                    return(new CommandResult("There is too many results", true));
                }

                deleteUser.Identifier = preResponse.Response.Payload.FirstOrDefault().Identifier;
            }

            var result = WinApiConnector.RequestDelete <Response <string> >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/User/Delete/" +
                                                                            $"{deleteUser.Identifier}");
            ConnectorResult <Response <string> > connectorResult = result.Result;

            if (!connectorResult.IsSuccess)
            {
                return(new CommandResult(connectorResult.Message, false));
            }
            if (!connectorResult.Response.IsSuccess)
            {
                return(new CommandResult(connectorResult.Response.Code, false));
            }
            if (string.IsNullOrEmpty(connectorResult.Response.Payload))
            {
                return(new CommandResult("The payload of response <DELETE USER > is null or empty ", false));
            }
            return(new CommandResult($"The User {deleteUser.Identifier} has been deleted", true));
        }
        protected override CommandResult Execute(ConsoleContext context, HuntingArguments arguments)
        {
            IList <User>           usersList       = new List <User>();
            IList <UserHunting>    users           = new List <UserHunting>();
            IList <Animal>         animals         = new List <Animal>();
            IList <Quarry>         quarries        = new List <Quarry>();
            IList <PartialHunting> partialHuntings = new List <PartialHunting>();
            User    leader  = new User();
            Hunting hunting = new Hunting();
            Task <ConnectorResult <Response <IEnumerable <User> > > > usersRequest = WinApiConnector.RequestGet <Response <IEnumerable <User> > >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/User/GetAll");
            ConnectorResult <Response <IEnumerable <User> > >         preResult    = usersRequest.Result;

            if (!preResult.IsSuccess)
            {
                return(new CommandResult(preResult.Message, false));
            }
            if (!preResult.Response.IsSuccess)
            {
                return(new CommandResult(preResult.Response.Code, false));
            }
            if (!preResult.Response.Payload.Any())
            {
                return(new CommandResult("The payload of response is null or empty", false));
            }

            foreach (var item in preResult.Response.Payload)
            {
                usersList.Add(item);
            }

            Task <ConnectorResult <Response <IEnumerable <Animal> > > > animalsList   = WinApiConnector.RequestGet <Response <IEnumerable <Animal> > >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/COnfiguration/GetAllAnimals");
            ConnectorResult <Response <IEnumerable <Animal> > >         animalsResult = animalsList.Result;

            if (!animalsResult.IsSuccess)
            {
                return(new CommandResult(animalsResult.Message, false));
            }
            if (!animalsResult.Response.IsSuccess)
            {
                return(new CommandResult(animalsResult.Response.Code, false));
            }
            if (!animalsResult.Response.Payload.Any())
            {
                return(new CommandResult("The payload of response is null or empty", false));
            }

            foreach (var item in animalsResult.Response.Payload)
            {
                animals.Add(item);
            }

            if (string.IsNullOrEmpty(arguments.Leader))
            {
                System.Console.WriteLine("Wybierz lidera");
                int index = 1;
                foreach (var item in usersList)
                {
                    System.Console.WriteLine($"{index++}. {item.Name}, {item.Surname}");
                }
                bool shouldWork = true;
                int  choisenOne = 0;

                do
                {
                    string choiceLeader = System.Console.ReadLine();
                    bool   isParsed     = int.TryParse(choiceLeader, out choisenOne);
                    shouldWork = isParsed ? choisenOne > usersList.Count() : true;
                }while(shouldWork);

                leader = usersList[choisenOne - 1];
            }
            foreach (var item in animals)
            {
                quarries.Add(new Quarry()
                {
                    Animal = item,
                    Amount = 3
                });
            }

            foreach (var item in usersList)
            {
                users.Add(new UserHunting()
                {
                    UserId = item.Identifier
                });
            }

            hunting.Leader   = leader;
            hunting.Quarries = quarries;
            hunting.Users    = users;

            for (int i = 0; i < arguments.PartialHunting; i++)
            {
                partialHuntings.Add(new PartialHunting()
                {
                    Number         = i + 1,
                    Status         = Status.Create,
                    PartialHunters = new List <PartialHuntersList>()
                });
            }

            hunting.PartialHuntings = partialHuntings;
            hunting.Description     = "Pierwsze";

            Task <ConnectorResult <Response <string> > > addResult       = WinApiConnector.RequestPost <Hunting, Response <string> >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/Hunting/AddHunting", hunting);
            ConnectorResult <Response <string> >         connectorResult = addResult.Result;

            if (!connectorResult.IsSuccess)
            {
                return(new CommandResult(connectorResult.Message, false));
            }
            if (!connectorResult.Response.IsSuccess)
            {
                return(new CommandResult(connectorResult.Response.Code, false));
            }
            if (string.IsNullOrEmpty(connectorResult.Response.Payload))
            {
                return(new CommandResult("The payload of response is null or empty", false));
            }
            return(new CommandResult("OK", true));
        }
Exemple #10
0
        protected override CommandResult Execute(ConsoleContext context, QuarryArguments arguments)
        {
            Animal animal = new Animal();

            if (string.IsNullOrEmpty(arguments.Animal))
            {
                Task <ConnectorResult <Response <IEnumerable <Animal> > > > animals   = WinApiConnector.RequestGet <Response <IEnumerable <Animal> > >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/Configuration/GetAllAnimals");
                ConnectorResult <Response <IEnumerable <Animal> > >         preResult = animals.Result;
                if (!preResult.IsSuccess)
                {
                    return(new CommandResult(preResult.Message, false));
                }
                if (!preResult.Response.IsSuccess)
                {
                    return(new CommandResult(preResult.Response.Code, false));
                }
                if (!preResult.Response.Payload.Any())
                {
                    return(new CommandResult("The payload of response is empty", false));
                }

                foreach (var item in preResult.Response.Payload)
                {
                    System.Console.WriteLine($"{item.Name.ToUpper()}");
                }
                System.Console.Write("Wpisz nazwę zwierzęcia: ");
                var readLine    = System.Console.ReadLine();
                var existAnimal = animals.Result.Response.Payload.Where(n => n.Name == readLine.ToLower()).SingleOrDefault();
                animal = existAnimal;
            }

            if (!string.IsNullOrEmpty(arguments.Animal))
            {
                Task <ConnectorResult <Response <IEnumerable <Animal> > > > existsAnimal = WinApiConnector.RequestGet <Response <IEnumerable <Animal> > >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/Configuration/GetAnimal/" +
                                                                                                                                                          $"{arguments.Animal.ToLower()}");
                ConnectorResult <Response <IEnumerable <Animal> > > connectorResult = existsAnimal.Result;
                if (!connectorResult.IsSuccess)
                {
                    return(new CommandResult(connectorResult.Message, false));
                }
                if (!connectorResult.Response.IsSuccess)
                {
                    return(new CommandResult(connectorResult.Response.Code, false));
                }
                if (!connectorResult.Response.Payload.Any())
                {
                    return(new CommandResult($"The Animal {arguments.Animal.ToUpper()} doesn't exists", false));
                }
                if (connectorResult.Response.Payload.Count() != 1)
                {
                    return(new CommandResult("Too many results", false));
                }

                animal = connectorResult.Response.Payload.FirstOrDefault();
            }

            Task <ConnectorResult <Response <string> > > result = WinApiConnector.RequestPost <Model.Quarry, Response <string> >($"{context.ConsoleSettings.ServerAddress}:{context.ConsoleSettings.Port}/Api/Hunting/AddQuarry",
                                                                                                                                 new Model.Quarry()
            {
                Animal = animal,
                Amount = arguments.Amount
            });
            ConnectorResult <Response <string> > postResult = result.Result;

            if (!postResult.IsSuccess)
            {
                return(new CommandResult(postResult.Message, false));
            }
            if (!postResult.Response.IsSuccess)
            {
                return(new CommandResult(postResult.Response.Code, false));
            }
            if (string.IsNullOrEmpty(postResult.Response.Payload))
            {
                return(new CommandResult("The payload of response is null or empty", false));
            }
            return(new CommandResult(postResult.Response.Payload, true));
        }