Esempio n. 1
0
        public IActionResult GetPerson(int id)
        {
            var person = personDAL.GetPersonById(id);

            if (person == null)
            {
                return(NotFound());
            }

            return(Ok(person));
        }
Esempio n. 2
0
        public Person GetPersonById(int personID)
        {
            try
            {
                PersonDAL repository = new PersonDAL();
                Person    person     = new Person();

                return(person = repository.GetPersonById(personID));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        public void PersonDALMenu()
        {
            while (true)
            {
                System.Console.WriteLine("Welcome in Role");
                System.Console.WriteLine("c - Create");
                System.Console.WriteLine("r - read one");
                System.Console.WriteLine("rall - read all");
                System.Console.WriteLine("u - update");
                System.Console.WriteLine("d - delete");
                System.Console.WriteLine("else - exit");

                string a = System.Console.ReadLine();



                switch (a)
                {
                case "c":
                    System.Console.WriteLine("Input Person :");
                    person = dal.CreatePerson(new PersonDTO {
                        FirstName = System.Console.ReadLine()
                    });
                    System.Console.WriteLine("You add the: Id - " + person.PersonId + " Name - " + person.FirstName);
                    System.Console.WriteLine("Press any key");
                    System.Console.WriteLine("");
                    System.Console.WriteLine("");
                    System.Console.ReadKey();
                    break;

                case "r":
                    System.Console.Write("Choose Id: ");
                    person = dal.GetPersonById(System.Convert.ToInt32(System.Console.ReadLine()));
                    System.Console.WriteLine("You read the: Id - " + person.PersonId + " Name - " + person.FirstName);
                    System.Console.WriteLine("Press any key");
                    System.Console.WriteLine("");
                    System.Console.WriteLine("");
                    System.Console.ReadKey();
                    break;

                case "rall":
                    List <PersonDTO> categories = dal.GetAllPerson();
                    for (int i = 0; i < person.Count; i++)
                    {
                        System.Console.WriteLine("Id - " + person[i].RoleId + " Name - " + person[i].FirstName);
                    }
                    System.Console.WriteLine("Press any key");
                    System.Console.WriteLine("");
                    System.Console.WriteLine("");
                    System.Console.ReadKey();
                    break;

                case "u":
                    System.Console.WriteLine("Update Name:");
                    person = dal.UpdatePerson(new PersonDTO {
                        FirstName = System.Console.ReadLine()
                    });
                    System.Console.WriteLine("You add the: Id - " + person.PersonId + " Name - " + person.FirstName);
                    System.Console.WriteLine("Press any key");
                    System.Console.WriteLine("");
                    System.Console.WriteLine("");
                    System.Console.ReadKey();
                    break;

                case "d":
                    System.Console.WriteLine("Choose Id:");
                    dal.DeletePerson(System.Convert.ToInt32(System.Console.ReadLine()));
                    System.Console.WriteLine("Delete successful");
                    System.Console.WriteLine("Press any key");
                    System.Console.WriteLine("");
                    System.Console.WriteLine("");
                    System.Console.ReadKey();
                    break;

                case "else":
                    break;
                }
            }
        }
 // PERSON METHODS
 public Person GetPerson(int personID)
 {
     return(PersonDAL.GetPersonById(personID));
 }