0
Hello, I am developing an application using C# MVC and EF5 and I have the following problem: I have a customer group management screen, in this group I can insert and remove customers, I use a relationship table between clients and groups called client_group_client (obviously it has relationship with the client_group table), when I add a customer to this group, I insert their information into a table on the screen:
The code of each of these lines goes something like this:
<button class="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 account and save, will insert a record in the bank, until then it is working, the problem is when I try to remove one of these records, the object passed to the comes only with active relations on the screen, I don’t know which one was removed so I could remove it from the bank. Does anyone have any idea how to do this?
controller Clientgroupcontroller:
[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);
}
You are sending to
Action
of exclusion for whichController
?– Leonel Sanches da Silva
Gypsy Morrison Mendez, edited the question, see if it helps
– AndrehOdon
Why call the controller
client_group
where you are excluding an associationclient_group_client
?– Leonel Sanches da Silva
@Gypsy, because the canvas (CRUD) is related to the client_group, within it I make group relationship with customers
– AndrehOdon
There is no need for this standardization. Each association has a
<form>
, right? I deduced this because you use one button for each. You can call anothercontroller
that excludes for you. It is even more correct from the point of view of the application design.– Leonel Sanches da Silva
@Gypsy, did not understand its placement, is all within the same <form>
– AndrehOdon
Got it. I think this is the tricky one. I’m going to suggest an answer.
– Leonel Sanches da Silva