I'm assuming that your system uses Entity Framework.
I'll deduce your Model from texts:
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-to-face when inserted. That is:
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
, so by inserting new text, it is cast as Aprovado = false;
.
Once this is done, you only need to type Action
to 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();