Esempio n. 1
0
        // GET: api/Departments/5
        public HttpResponseMessage Get(int id)
        {
            Department          oDepartment = null;
            HttpResponseMessage respuesta;

            try
            {
                DepartmentListBL handler = new DepartmentListBL();
                oDepartment = handler.getDepartmentById(id);
            }
            catch (Exception e)
            {
                //Conexión con las otras capas fallida
                //No se envía la información de la excepción e para evitar exponer al público detalles técnicos
                throw new HttpResponseException(HttpStatusCode.ServiceUnavailable);
            }
            finally
            {
                if (oDepartment == null)
                {
                    //Según el estándar http, NO se debe incluir contenido
                    //en las respuestas http de no content
                    respuesta = Request.CreateResponse(HttpStatusCode.NoContent);
                }
                else
                {
                    respuesta = Request.CreateResponse(HttpStatusCode.OK, oDepartment);
                }
            }

            return(respuesta);
        }
Esempio n. 2
0
        // GET: api/Departments
        public HttpResponseMessage Get()
        {
            List <Department>   lista = null;
            HttpResponseMessage respuesta;

            try
            {
                DepartmentListBL handler = new DepartmentListBL();
                lista = handler.getDepartmentList();
            }
            catch (HttpResponseException e)
            {
                //Conexión con las otras capas fallida
                throw new HttpResponseException(HttpStatusCode.ServiceUnavailable);
            }
            finally
            {
                if (lista == null)
                {
                    //Según el estándar http, NO se debe incluir contenido
                    //en las respuestas http de no content
                    respuesta = Request.CreateResponse(HttpStatusCode.NoContent);
                }
                else
                {
                    respuesta = Request.CreateResponse(HttpStatusCode.OK, lista);
                }
            }

            return(respuesta);
        }
Esempio n. 3
0
        //This parameter is going to be provided by the ActionLink's third parameter in Edit's view
        public ActionResult Edit(int id)
        {
            //This commented code is the code that should be used with model PersonDepartmentList, which is, in the first place
            //how this is supposed to be designed

            /* //Finding the person clicked
             * PersonListBL PersonList = new PersonListBL();
             * Person Person = PersonList.getPersonById(id);
             *
             * //Retrieving a list of departments
             * DepartmentListBL DepartmentList = new DepartmentListBL();
             * List<Department> list = DepartmentList.getDepartmentList();
             *
             * //Building our model with the clicked Person's data and the department list
             * PersonDepartmentList finalResult = new PersonDepartmentList(Person, list);*/

            //CODE USED WITH PersonDepartmentName MODEL
            //Finding the person clicked
            PersonListBL PersonList = new PersonListBL();
            Person       Person     = PersonList.getPersonById(id);

            DepartmentListBL list = new DepartmentListBL();
            //Building our model with the clicked Person's data. Person's field DepartmentID is translated into its corresponding department name
            PersonDepartmentName finalResult = new PersonDepartmentName(Person, list.getDepartmentById(Person.DepartmentID).Name);

            return(View(finalResult));
        }
Esempio n. 4
0
        public ActionResult Details(int id)
        {
            //Finding the person clicked
            PersonListBL PersonList = new PersonListBL();
            Person       Person     = PersonList.getPersonById(id);

            DepartmentListBL DepartmentList = new DepartmentListBL();
            Department       department     = DepartmentList.getDepartmentById(Person.DepartmentID);

            PersonDepartmentName finalResult = new PersonDepartmentName(Person, department.Name);

            return(View(finalResult));
        }
Esempio n. 5
0
        public ActionResult Delete(int id)
        {
            //CODE USED WITH PersonDepartmentName MODEL
            //Finding the person clicked
            PersonListBL PersonList = new PersonListBL();
            Person       Person     = PersonList.getPersonById(id);

            DepartmentListBL list = new DepartmentListBL();
            //Building our model with the clicked Person's data. Person's field DepartmentID is translated into its corresponding department name
            PersonDepartmentName finalResult = new PersonDepartmentName(Person, list.getDepartmentById(Person.DepartmentID).Name);

            return(View(finalResult));
        }
Esempio n. 6
0
        // GET: api/PersonasDepartmentName/5
        public HttpResponseMessage Get(int id)
        {
            PersonDepartmentName oPersonaNombre = null;
            HttpResponseMessage  respuesta;

            try
            {
                PersonListBL     personListHandler     = new PersonListBL();
                DepartmentListBL departmentListHandler = new DepartmentListBL();

                //Obtenemos la persona solicitada sin el nombre de departamento
                //y la usamos para instanciar un objeto PersonDepartmentName,
                //junto con el nombre de departamento que le corresponde a la id de departamento

                Person oPersonaSinNombre = personListHandler.getPersonById(id);

                //Obtenemos la lista de personas sin el nombre de departamento
                //y en cada iteración del bucle, usamos cada una de las personas para
                //instanciar un nuevo objeto PersonDepartmentName y añadirlo a la lista
                //que vamos a devolver

                oPersonaNombre = new PersonDepartmentName(oPersonaSinNombre,
                                                          //Obteniendo el nombre de departamento a partir de la id
                                                          departmentListHandler.getDepartmentById(oPersonaSinNombre.DepartmentID).Name);
            }
            catch (HttpResponseException e)
            {
                //Conexión con las otras capas fallida
                throw new HttpResponseException(HttpStatusCode.ServiceUnavailable);
            }
            finally
            {
                if (oPersonaNombre == null)
                {
                    //Según el estándar http, NO se debe incluir contenido
                    //en las respuestas http de no content
                    respuesta = Request.CreateResponse(HttpStatusCode.NoContent);
                }
                else
                {
                    respuesta = Request.CreateResponse(HttpStatusCode.OK, oPersonaNombre);
                }
            }

            return(respuesta);
        }
Esempio n. 7
0
        // GET: Person
        public ActionResult List()
        {
            PersonDepartmentNameList list = new PersonDepartmentNameList();

            //Bringing the list of all Person records in the database and storing them
            PersonListBL PersonListBL = new PersonListBL();

            DepartmentListBL DepartmentListBL = new DepartmentListBL();

            //Adding to the PersonDepartmentNameList a new PersonDepartmentName object in each iteration
            //Its constructor takes a Person, and a department name


            foreach (Person p in PersonListBL.getPersonList())
            {
                list.List.Add(new PersonDepartmentName(p, DepartmentListBL.getDepartmentById(p.DepartmentID).Name));
            }

            return(View(list.List));
        }
Esempio n. 8
0
        // GET: api/PersonasDepartmentName
        public HttpResponseMessage Get()
        {
            List <PersonDepartmentName> lista = new List <PersonDepartmentName>();
            HttpResponseMessage         respuesta;

            try
            {
                PersonListBL     personListHandler     = new PersonListBL();
                DepartmentListBL departmentListHandler = new DepartmentListBL();

                //Obtenemos la lista de personas sin el nombre de departamento
                //y en cada iteración del bucle, usamos cada una de las personas para
                //instanciar un nuevo objeto PersonDepartmentName y añadirlo a la lista
                //que vamos a devolver

                foreach (Person p in personListHandler.getPersonList())
                {
                    lista.Add(new PersonDepartmentName(p, departmentListHandler.getDepartmentById(p.DepartmentID).Name));
                }
            }
            catch (HttpResponseException e)
            {
                //Conexión con las otras capas fallida
                throw new HttpResponseException(HttpStatusCode.ServiceUnavailable);
            }
            finally
            {
                if (lista == null)
                {
                    //Según el estándar http, NO se debe incluir contenido
                    //en las respuestas http de no content
                    respuesta = Request.CreateResponse(HttpStatusCode.NoContent);
                }
                else
                {
                    respuesta = Request.CreateResponse(HttpStatusCode.OK, lista);
                }
            }

            return(respuesta);
        }