I’m guessing your system uses Entity Framework.
I’ll deduce your Model text:
public class Texto
{
[Key]
public int TextoId { get; set; }
public int UsuarioId { get; set; }
public int AdminId { get; set; }
[DataType(DataType.MultilineText)]
[Required]
public String Texto { get; set; }
public virtual Usuario Usuario { get; set; }
public virtual Usuario Admin { get; set; }
}
If the text needs approval, it is impossible for there to be no persistence in the process (or, as you say, no insertion). What you can do is enrich your Model so that this text does not appear face-first when inserted. That is to say:
public class Texto
{
[Key]
public int TextoId { get; set; }
public int UsuarioId { get; set; }
public int AdminId { get; set; }
[DataType(DataType.MultilineText)]
[Required]
public String Texto { get; set; }
public Boolean Aprovado { get; set; }
public DateTime? DataAprovacao { get; set; }
public virtual Usuario Usuario { get; set; }
public virtual Usuario Admin { get; set; }
}
Booleans in the Entity Framework are default false
, then inserting a new text, it is released as Aprovado = false;
.
Once done, just write a Action
for the administrator to approve the text. Something like this:
public ActionResult Aprovar(int id)
{
var texto = contexto.Textos.SingleOrDefault(t => t.TextoId == id);
if (UsuarioEhAdministrador) // Coloque aqui seu critério para verificar se usuário é Administrador
{
texto.Aprovado = true;
texto.DataAprovacao = DateTime.Now;
contexto.Entry(texto).State = EntityState.Modified;
contexto.SaveChanges();
return RedirectToAction("Index", "Textos");
}
}
And to not display unapproved texts, use:
var textos = contexto.Textos.Where(t => T.Aprovado).ToList();
did not understand your question exactly, but if your business rule says that to be published it needs to be OK (opa, it turns rs attribute) then at least you already need a field in your table called status and/or approved(yes/no) to validate this state anywhere in your system. And as you say, if you need an admin to approve, it should NOT be required (idadmin) at the time of insertion.
– wryel