Hello, I'm developing an application using C # MVC and EF5 and I have the following problem: I have a client group management screen, in this group I can insert and remove clients, I use a relationship table between clients and groups called client_group_client (obviously it has relation to the client_group table), when I add a client to this group , I enter your information in a table on the screen:
Thecodeforeachoftheselinesissomethinglikethis:
<buttonclass="btn_remove">Remover</button> <input name="client_group_client[0].id_client" type="hidden" value="3">
<input name="client_group_client[0].id" type="hidden" value="3">
<input name="client_group_client[0].status" type="hidden" value="1">
<input name="client_group_client[0].datetime_inclusion" type="hidden" value="15/07/2014 10:06:24">
Cliente 3
If I insert a new client and save it, it will insert a record in the database, until it is working, the problem is when I try to remove one of those records, the object passed to it only comes with the active relations on the screen, I I do not know which one was removed to remove from the bank. Anyone have any ideas how to do this?
ClientGroupController controller:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(client_group client_group, string actionSubmit, string urlReferrer)
{
repository.BeforeUpdate(client_group);
if (!repository.Save())
{
setFlash("danger", repository.GetHtmlErrors());
return View("~/Views/Person/ClientGroup/Edit.cshtml", client_group);
}
setFlash("success", I18n.T("Alert","RegisterSaveSucess"));
if (actionSubmit == "saveAndBack")
return Redirect(urlReferrer);
else
return View("~/Views/Person/ClientGroup/Edit.cshtml", client_group);
}
Repository class (created by me to process data before / after modifying):
public override bool BeforeUpdate(client_group obj)
{
foreach (client_group_client register in obj.client_group_client)
{
register.id_client_group = obj.id;
if (register.datetime_inclusion == null)
{
register.datetime_inclusion = DateTime.Now;
register.status = client_group_client.ACTIVE;
dbContext.Entry(register).State = EntityState.Added;
}
else
{
dbContext.Entry(register).State = EntityState.Modified;
}
}
return base.BeforeUpdate(obj);
}