Ejemplo n.º 1
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    DResidente residenteACrear = new DResidente();
                    residenteACrear.DNI             = (String)collection["DNI"];
                    residenteACrear.Nombres         = (String)collection["Nombres"];
                    residenteACrear.ApellidoPaterno = (String)collection["ApellidoPaterno"];
                    residenteACrear.ApellidoMaterno = (String)collection["ApellidoMaterno"];
                    residenteACrear.Edad            = int.Parse(collection["Edad"]);
                    residenteACrear.Correo          = (String)collection["Correo"];
                    residenteACrear.Clave           = (String)collection["Clave"];
                    residenteACrear.Tipo            = (String)collection["Tipo"];

                    //RegistrarService.RegistrarResidente(residenteACrear);
                    SRResidente.ResidentesClient res = new SRResidente.ResidentesClient();
                    res.CrearResidente(residenteACrear);

                    return(RedirectToAction("Index"));
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(String.Empty, "Error al crear residente: " + e.Message);

                return(View());
            }
        }
        public DResidente Modificar(DResidente residenteAModificar)
        {
            DResidente residenteModificado = null;

            string sentencia = "update residente set apellidopaterno = @apellidopaterno, apellidomaterno =  @apellidomaterno, clave = @clave, correo = @correo, edad = @edad, nombres = @nombres, tipo = @tipo where dni = @dni";

            using (SqlConnection conexion = new SqlConnection(ConexionUtil.ObtenerCadena()))
            {
                conexion.Open();
                using (SqlCommand comando = new SqlCommand(sentencia, conexion))
                {
                    comando.Parameters.Add(new SqlParameter("@apellidopaterno", residenteAModificar.ApellidoPaterno));
                    comando.Parameters.Add(new SqlParameter("@apellidomaterno", residenteAModificar.ApellidoMaterno));
                    comando.Parameters.Add(new SqlParameter("@nombres", residenteAModificar.Nombres));
                    comando.Parameters.Add(new SqlParameter("@clave", residenteAModificar.Clave));
                    comando.Parameters.Add(new SqlParameter("@correo", residenteAModificar.Correo));
                    comando.Parameters.Add(new SqlParameter("@edad", residenteAModificar.Edad));
                    comando.Parameters.Add(new SqlParameter("@tipo", residenteAModificar.Tipo));
                    comando.Parameters.Add(new SqlParameter("@dni", residenteAModificar.DNI));
                    comando.ExecuteNonQuery();
                }
            }

            residenteModificado = Obtener(residenteAModificar.DNI);

            return(residenteModificado);
        }
        public DResidente Crear(DResidente residenteACrear)
        {
            DResidente residenteCreado = null;

            string sentencia = "INSERT INTO residente (dni, apellidopaterno, apellidomaterno, nombres, edad, correo, clave, tipo) VALUES (@dni,@apellidopaterno, @apellidomaterno, @nombres, @edad, @correo, @clave, @tipo)";

            using (SqlConnection conexion = new SqlConnection(ConexionUtil.ObtenerCadena()))
            {
                conexion.Open();
                using (SqlCommand comando = new SqlCommand(sentencia, conexion))
                {
                    comando.Parameters.Add(new SqlParameter("@dni", residenteACrear.DNI));
                    comando.Parameters.Add(new SqlParameter("@apellidopaterno", residenteACrear.ApellidoPaterno));
                    comando.Parameters.Add(new SqlParameter("@apellidomaterno", residenteACrear.ApellidoMaterno));
                    comando.Parameters.Add(new SqlParameter("@nombres", residenteACrear.Nombres));
                    comando.Parameters.Add(new SqlParameter("@edad", residenteACrear.Edad));
                    comando.Parameters.Add(new SqlParameter("@correo", residenteACrear.Correo));
                    comando.Parameters.Add(new SqlParameter("@clave", residenteACrear.Clave));
                    comando.Parameters.Add(new SqlParameter("@tipo", residenteACrear.Tipo));
                    comando.ExecuteNonQuery();
                }
            }

            residenteCreado = Obtener(residenteACrear.DNI);

            return(Obtener(residenteACrear.DNI));
        }
        public DResidente Obtener(string dni)
        {
            DResidente residenteExistente = null;

            string sentencia = "SELECT * FROM residente WHERE dni=@dni";

            using (SqlConnection conexion = new SqlConnection(ConexionUtil.ObtenerCadena()))
            {
                conexion.Open();

                using (SqlCommand comando = new SqlCommand(sentencia, conexion))
                {
                    comando.Parameters.Add(new SqlParameter("@dni", dni));
                    SqlDataReader resultado = comando.ExecuteReader();
                    if (resultado.Read())
                    {
                        residenteExistente                 = new DResidente();
                        residenteExistente.DNI             = (string)resultado["dni"];
                        residenteExistente.Nombres         = (string)resultado["nombres"];
                        residenteExistente.ApellidoPaterno = (string)resultado["apellidopaterno"];
                        residenteExistente.ApellidoMaterno = (string)resultado["apellidomaterno"];
                        residenteExistente.Edad            = (int)resultado["edad"];
                        residenteExistente.Correo          = (string)resultado["correo"];
                        residenteExistente.Clave           = (string)resultado["clave"];
                        residenteExistente.Tipo            = (string)resultado["tipo"];
                    }
                }
            }

            return(residenteExistente);
        }
Ejemplo n.º 5
0
        public ActionResult Edit(int NumVivienda, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                //Vivienda viviendaAModificar = RegistrarService.ObtenerVivienda(NumVivienda);
                SRVivienda.ViviendasClient res = new SRVivienda.ViviendasClient();
                DVivienda  viviendaAModificar  = res.ObtenerVivienda(NumVivienda);
                DResidente residente           = new DResidente();

                residente.DNI = (String)collection["Residente.DNI"];

                viviendaAModificar.Ubicacion = (String)collection["Ubicacion"];
                viviendaAModificar.Numero    = int.Parse(collection["Numero"]);
                viviendaAModificar.Metraje   = int.Parse(collection["Numero"]);
                viviendaAModificar.Tipo      = (String)collection["Tipo"];
                viviendaAModificar.Residente = residente;

                //RegistrarService.ModificarVivienda(viviendaAModificar);
                res.ModificarVivienda(viviendaAModificar);


                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ICollection <DResidente> ListarTodosLosResidentes()
        {
            ICollection <DResidente> listaresidente = new List <DResidente>();

            String sentencia = "SELECT * FROM RESIDENTE";

            using (SqlConnection conexion = new SqlConnection(ConexionUtil.ObtenerCadena()))
            {
                conexion.Open();
                using (SqlCommand comando = new SqlCommand(sentencia, conexion))
                {
                    SqlDataReader resultado = comando.ExecuteReader();
                    while (resultado.Read())
                    {
                        DResidente residenteExistente = new DResidente();
                        residenteExistente.DNI             = (String)resultado["dni"];
                        residenteExistente.ApellidoPaterno = (String)resultado["apellidopaterno"];
                        residenteExistente.ApellidoMaterno = (String)resultado["apellidomaterno"];
                        residenteExistente.Nombres         = (String)resultado["nombres"];
                        residenteExistente.Edad            = (int)resultado["edad"];
                        residenteExistente.Correo          = (String)resultado["correo"];
                        residenteExistente.Clave           = (String)resultado["clave"];
                        residenteExistente.Tipo            = (String)resultado["tipo"];
                        listaresidente.Add(residenteExistente);
                    }
                }
            }
            return(listaresidente);
        }
Ejemplo n.º 7
0
        public ActionResult Edit(String DNI, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                //Residente residenteAModificar = RegistrarService.ObtenerResidente(DNI);
                SRResidente.ResidentesClient res = new SRResidente.ResidentesClient();
                DResidente residenteAModificar   = res.ObtenerResidente(DNI);


                residenteAModificar.Nombres         = (String)collection["Nombres"];
                residenteAModificar.ApellidoPaterno = (String)collection["ApellidoPaterno"];
                residenteAModificar.ApellidoMaterno = (String)collection["ApellidoMaterno"];
                residenteAModificar.Edad            = int.Parse(collection["Edad"]);
                residenteAModificar.Correo          = (String)collection["Correo"];
                residenteAModificar.Clave           = (String)collection["Clave"];
                residenteAModificar.Tipo            = (String)collection["Tipo"];

                //RegistrarService.ModificarResidente(residenteAModificar);
                res.ModificarResidente(residenteAModificar);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 8
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    DVivienda  viviendaACrear = new DVivienda();
                    DResidente residente      = new DResidente();

                    residente.DNI = (String)collection["Residente"];

                    viviendaACrear.NumVivienda = int.Parse(collection["NumVivienda"]);
                    viviendaACrear.Ubicacion   = (String)collection["Ubicacion"];
                    viviendaACrear.Numero      = int.Parse(collection["Numero"]);
                    viviendaACrear.Metraje     = int.Parse(collection["Metraje"]);
                    viviendaACrear.Tipo        = (String)collection["Tipo"];
                    viviendaACrear.Residente   = residente;

                    //RegistrarService.RegistrarVivienda(viviendaACrear);
                    SRVivienda.ViviendasClient res = new SRVivienda.ViviendasClient();
                    res.CrearVivienda(viviendaACrear);

                    return(RedirectToAction("Index"));
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(String.Empty, "Error al crear vivienda: " + e.Message);

                return(View());
            }
        }
Ejemplo n.º 9
0
        public DResidente Obtener(string dni)
        {
            DResidente residenteExistente = null;
            string     sentencia          = "SELECT * FROM residente WHERE dni=@dni";

            using (SqlConnection conexion = new SqlConnection(ConexionUtil.ObtenerCadena()))
            {
                conexion.Open();
                using (SqlCommand comando = new SqlCommand(sentencia, conexion))
                {
                    comando.Parameters.Add(new SqlParameter("@dni", dni));
                    SqlDataReader resultado = comando.ExecuteReader();
                    if (resultado.Read())
                    {
                        residenteExistente                 = new DResidente();
                        residenteExistente.DNI             = (string)resultado["dni"];
                        residenteExistente.Nombres         = (string)resultado["nombres"];
                        residenteExistente.ApellidoPaterno = (string)resultado["apellidopaterno"];
                        residenteExistente.ApellidoMaterno = (string)resultado["apellidomaterno"];
                        residenteExistente.Edad            = (int)resultado["edad"];
                        residenteExistente.Correo          = (string)resultado["correo"];
                        //Se agregó campos para que se visualice en el WCF ya que no salia campos de la tabla RESIDENTE.
                    }
                }
            }
            return(residenteExistente);
        }
Ejemplo n.º 10
0
        // GET: /Residente/Edit/5
        public ActionResult Edit(String DNI)
        {
            //Residente modelo = RegistrarService.ObtenerResidente(DNI);
            SRResidente.ResidentesClient res = new SRResidente.ResidentesClient();
            DResidente modelo = res.ObtenerResidente(DNI);

            return(View(modelo));
        }
Ejemplo n.º 11
0
        // GET: /Residente/Details/5
        public ActionResult Details(String DNI)
        {
            //Residente modelo = RegistrarService.ObtenerResidente(DNI);
            SRResidente.ResidentesClient res = new SRResidente.ResidentesClient();
            DResidente modelo = res.ObtenerResidente(DNI);

            return(View(modelo)); //La vista se llama Details.aspx
        }
        public DVivienda ModificarVivienda(DVivienda dvivienda)
        {
            DResidente residenteExistente = ResidenteDAO.Obtener(dvivienda.Residente.DNI);

            DVivienda viviendaAModificar = new DVivienda();

            viviendaAModificar.NumVivienda = dvivienda.NumVivienda;
            viviendaAModificar.Ubicacion   = dvivienda.Ubicacion;
            viviendaAModificar.Numero      = dvivienda.Numero;
            viviendaAModificar.Metraje     = dvivienda.Metraje;
            viviendaAModificar.Tipo        = dvivienda.Tipo;
            viviendaAModificar.Residente   = residenteExistente;

            return(ViviendaDAO.Modificar(viviendaAModificar));
        }
Ejemplo n.º 13
0
        public DResidente ModificarResidente(DResidente dresidente)
        {
            DResidente residenteAModificar = new DResidente()
            {
                DNI             = dresidente.DNI,
                Nombres         = dresidente.Nombres,
                ApellidoPaterno = dresidente.ApellidoPaterno,
                ApellidoMaterno = dresidente.ApellidoMaterno,
                Edad            = dresidente.Edad,
                Correo          = dresidente.Correo,
                Clave           = dresidente.Clave,
                Tipo            = dresidente.Tipo
            };

            return(ResidenteDAO.Modificar(residenteAModificar));
        }
Ejemplo n.º 14
0
        public ActionResult Delete(String DNI, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                //Residente residenteAEliminar = RegistrarService.ObtenerResidente(DNI);
                //RegistrarService.EliminarResidente(residenteAEliminar);
                SRResidente.ResidentesClient res = new SRResidente.ResidentesClient();
                DResidente residenteAEliminar    = res.ObtenerResidente(DNI);
                res.EliminarResidente(residenteAEliminar.DNI);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public void Test04Eliminar()
        {
            // 1. Instancia el objeto a probar
            DVivienda  pruebaVivienda = new DVivienda();
            DResidente residente      = new DResidente();

            // 2. Instanciamos el objeto TO
            pruebaVivienda.NumVivienda = 3;

            // 3. Llamada al método del DAO a probar
            //Assert.DoesNotThrow(delegate
            //{
            viviendaDAO.Eliminar(pruebaVivienda);
            //});

            pruebaVivienda = viviendaDAO.Obtener(pruebaVivienda.NumVivienda);
            // 4. Implementar las validaciones
            Assert.IsNull(pruebaVivienda);
        }
        public void Test01Crear()
        {
            DResidente   residente    = new DResidente();
            ResidenteDAO residenteDAO = new ResidenteDAO();

            residente = residenteDAO.Obtener("40717626");

            DVivienda r = viviendaDAO.Crear(new DVivienda()
            {
                NumVivienda = 1,
                Ubicacion   = "San Borja",
                Numero      = 459,
                Metraje     = 200,
                Tipo        = "C",
                Residente   = residente
            });

            Assert.AreEqual(r.NumVivienda, 1);
        }
Ejemplo n.º 17
0
 //public DResidente ModificarResidente(string nombre, string edad, string codigo)
 public DResidente ModificarResidente(DResidente residenteAModificar)
 {
     return(objResidenteDAO.Modificar(residenteAModificar));
     //return objResidenteDAO.Modificar(nombre,edad, codigo);
 }
Ejemplo n.º 18
0
 public DResidente CrearResidente(DResidente residenteACrear)
 {
     return(objResidenteDAO.Crear(residenteACrear));
 }