public ActionResult Create(Inmueble e) { repositorio.Agregar(e); if (e.ImageFile != null) { string wwwPath = environment.WebRootPath; string path = Path.Combine(wwwPath, "propiedades"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } //Path.GetFileName(u.AvatarFile.FileName);//este nombre se puede repetir string fileName = "propiedad_" + e.Id + Path.GetExtension(e.ImageFile.FileName); string pathCompleto = Path.Combine(path, fileName); e.Imagen = Path.Combine("/propiedades", fileName); using (FileStream stream = new FileStream(pathCompleto, FileMode.Create)) { e.ImageFile.CopyTo(stream); } repositorio.Editar(e); } return(RedirectToAction(nameof(Index))); }