Using ASP MVC with active record.
Ive got 2 tables with records that sometimes are related and sometimes aren't. The relation is defined by the user. 1 table has projects, the other has devices. Projects can be created and deleted, devices cannot. When a user deletes a project, all relations between that project and the devices should be removed, but the devices should remain.
How do I do this?
my delete action currently looks like this:
public ActionResult Delete(int id, FormCollection collection)
{
if (!Project.Exists(id)) return RedirectToAction("Index/1", "Error");
try
{
Project project = Project.Find(id);
if (project.User.Id != SessionVariables.AuthenticatedUser.Id) return RedirectToAction("Index/1", "Error");
project.DeleteAndFlush();
return RedirectToAction("Index", "Project");
}
catch(Exception e)
{
return RedirectToAction("Index", "Error");
}
}