示例#1
0
        public ActionResult obtenerFoto(int id)
        {
            Hipoteca       hipoteca = db.Hipoteca.FirstOrDefault(p => p.HipotecaId == id);
            FotosPropiedad plano    = hipoteca.FotosPropiedad.FirstOrDefault(p => p.Tipo == 1);

            return(File(plano.File, plano.FileName));
        }
示例#2
0
        public ActionResult Create(ViewHipoteca hipoteca)
        {
            if (ModelState.IsValid)
            {
                Hipoteca nuevaHipoteca = new Hipoteca();
                nuevaHipoteca.Persona = new Persona();

                nuevaHipoteca.Persona.Nombre         = hipoteca.Nombre;
                nuevaHipoteca.Persona.Apellido       = hipoteca.Apellido;
                nuevaHipoteca.Persona.Identificacion = hipoteca.Identificacion;
                nuevaHipoteca.Persona.Email          = hipoteca.Email;
                nuevaHipoteca.Persona.Telefono       = hipoteca.Telefono;
                nuevaHipoteca.NumeroPlano            = hipoteca.NumeroPlano;
                nuevaHipoteca.Provincia             = hipoteca.Provincia;
                nuevaHipoteca.Distrito              = hipoteca.Distrito;
                nuevaHipoteca.Canton                = hipoteca.Canton;
                nuevaHipoteca.GravamenesAnotaciones = hipoteca.GravamenesAnotaciones;
                nuevaHipoteca.TipoPropiedad         = hipoteca.TipoPropiedad;
                nuevaHipoteca.Estado                = (Estado)Enum.Parse(typeof(Estado), "Pendiente");

                FotosPropiedad FotosModel = new FotosPropiedad();
                FotosModel.hipoteca = nuevaHipoteca;

                //agregar el plano

                byte[] uploadFile = new byte[hipoteca.Plano.InputStream.Length];
                hipoteca.Plano.InputStream.Read(uploadFile, 0, uploadFile.Length);

                FotosModel.FileName = hipoteca.Plano.FileName;
                FotosModel.File     = uploadFile;

                db.FotosPropiedad.Add(FotosModel);
                db.SaveChanges();

                //agregar varias fotos
                foreach (var item in hipoteca.Fotos)
                {
                    uploadFile = new byte[item.InputStream.Length];
                    item.InputStream.Read(uploadFile, 0, uploadFile.Length);

                    FotosModel.FileName = item.FileName;
                    FotosModel.File     = uploadFile;

                    db.FotosPropiedad.Add(FotosModel);
                    db.SaveChanges();
                }
                //nuevaHipoteca.FotosPropiedad = null;
                //db.Hipoteca.Add(nuevaHipoteca);
                db.SaveChanges();
                RedirectToAction("Index", "Home");
            }

            return(View(hipoteca));
        }