I have the following situation, in my Models folder, I have:
public class HomeViewModel
{
public HomeViewModel()
{
// apenas para garantir que NUNCA seja nulo! Facilica código na view
PreviewImages = new List<Generico.Dominio.TB_IMAGEN_PERFIL>();
InitialPreviewConfigImages = new List<Generico.Dominio.TB_IMAGEN_PERFIL>();
User = new Generico.Dominio.TB_USUARIO();
}
//imagem do perfil do usuário
public List<Generico.Dominio.TB_IMAGEN_PERFIL> PreviewImages { get; set; }
public List<Generico.Dominio.TB_IMAGEN_PERFIL> InitialPreviewConfigImages { get; set; }
public Generico.Dominio.TB_USUARIO User { get; set; }
}
I want to bring the registration option along with the image gallery option: In my view today I have a normal register:
@Generic.domain.TB_USUARY
// registration data in the view
// Photo gallery data in View
In the controller I have:
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
public ActionResult ConsultaCadastroUsuarioCompleto(int id)
{
try
{
var tbuscar = new UsuarioAplicacao();
TB_USUARIO tbtabela = tbuscar.ListarPoId(id);
var model = new HomeViewModel
{
User = tbtabela,
PreviewImages = new List<Generico.Dominio.TB_IMAGEN_PERFIL> {
new Generico.Dominio.TB_IMAGEN_PERFIL { Id = 1, Url = Url.Content("~/Content/img/galeriaimagens/sl1.jpg") },
new Generico.Dominio.TB_IMAGEN_PERFIL { Id = 2, Url = Url.Content("~/Content/img/galeriaimagens/sl2.jpg") },
new Generico.Dominio.TB_IMAGEN_PERFIL { Id = 3, Url = Url.Content("~/Content/img/galeriaimagens/sl3.jpg") },
new Generico.Dominio.TB_IMAGEN_PERFIL { Id = 4, Url = Url.Content("~/Content/img/galeriaimagens/sl4.jpg") },
},
// size será preenchido depois (mas se vier do banco de dados, PREENCHA aqui para evitar perda de performance
InitialPreviewConfigImages = new List<Generico.Dominio.TB_IMAGEN_PERFIL> {
new Generico.Dominio.TB_IMAGEN_PERFIL { Id = 1, Url = Url.Content("~/Content/img/galeriaimagens/sl1.jpg"), Name = "Food-1.jpg" },
new Generico.Dominio.TB_IMAGEN_PERFIL { Id = 2, Url = Url.Content("~/Content/img/galeriaimagens/sl2.jpg"), Name = "Food-2.jpg" },
new Generico.Dominio.TB_IMAGEN_PERFIL { Id = 3, Url = Url.Content("~/Content/img/galeriaimagens/sl3.jpg"), Name = "Food-3.jpg" },
new Generico.Dominio.TB_IMAGEN_PERFIL { Id = 4, Url = Url.Content("~/Content/img/galeriaimagens/sl4.jpg"), Name = "Food-4.jpg" },
}
};
FindFileSizes(model.InitialPreviewConfigImages);
return View(model);
}
catch (Exception)
{
TempData["Erro"] = "Erro ao Alterar Registro.";
return RedirectToAction("Index", "CadastroCompletoUsuario");
}
}
private void FindFileSizes(List<TB_IMAGEN_PERFIL> imgs)
{
foreach (var img in imgs)
{
// é preciso converter o caminho relativo da URL em um caminho físico no servidor
var serverPath = Server.MapPath(img.Url);
if (System.IO.File.Exists(serverPath))
{
img.Size = new System.IO.FileInfo(serverPath).Length;
}
}
}
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
In UserApplication (); has a method that makes a query bringing the data of 1 user.
In the View I have
@model Project.WebSite.Models.HomeViewModel
I can not access the table anymore, how would it look?