I have a page that may have access not allowed, open for reading or open for reading and writing. Although the page is completely closed, the owner of the page can choose some users of the system that can have access to it. These exceptions can receive write or write permissions and read, for that, I used a dictionary where the key will be the user that will have permission and the String will indicate what level of access it has on that page.
Problem: The dictionary does not seem to be able to be saved in the database, just in the Action that is being executed, so it is just the Post from the page editing screen.
Page Model:
public class Fluxo
{
[Key]
public int FluxoID { get; set; }
[Required(ErrorMessage = "Dê um nome a fluxo")]
[Display(Name = "Título")]
public String Nome { get; set; }
[Required]
[Display(Name = "Dono do fluxo")]
public virtual Usuario Dono { get; set; }
[Display(Name = "Topico")]
public String TopicoPertencente { get; set; }
[Required]
[Display(Name = "Visibilidade")]
public String Visibilidade { get; set; }
public virtual IDictionary<Usuario, String> Permitidos { get; set; }
public virtual IList<Informacao> Informacoes { get; set; }
public object[] UsuarioID { get; internal set; }
}
FluxController / Edit Excerpt:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "FluxoID,Nome,TopicoPertencente,Visibilidade,desassociar")] ViewModels.Fluxo vwfluxo)
{
if (ModelState.IsValid)
{
Fluxo fluxo = db.Fluxo.Include(f => f.Dono).Where(fl => fl.FluxoID.Equals(vwfluxo.FluxoID)).FirstOrDefault();
...
// Até essa parte, tudo vai bem, porém, a Action termina e o Dictionary se perde.
fluxo.Permitidos = Selecionados; //Selecionados foi um Dictionary montado para salvar os usuários selecionados, essa lista irá preencher os Permitidos do objeto.
db.Entry(fluxo).State = EntityState.Modified;
db.SaveChanges();
}
On exit Action, flow.Permitted is null. I do not know if something is missing to save successfully, I am a beginner in the language and it is quite possible that something like this happens, but my opinion is that it has some problem in trying to save a dictionary in the database, there is no attribute in db. seems to be related to this dictionary. Sorry if something is complicated to understand, first post.