Example #1
0
        public ActionResult Create(Hipoteca hipoteca)
        {
            if (ModelState.IsValid)
            {
                db.Hipoteca.Add(hipoteca);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(hipoteca);
        }
Example #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);
        }