public ActionResult CompostDelete(CompostDeleteViewModel dvm) { if (ModelState.IsValid) { // first remove manure from all fields that had it applied if (!string.IsNullOrEmpty(dvm.warning)) { List <Field> flds = _ud.GetFields(); foreach (var fld in flds) { List <NutrientManure> mans = _ud.GetFieldNutrientsManures(fld.fieldName); foreach (var man in mans) { if (dvm.id.ToString() == man.manureId) { _ud.DeleteFieldNutrientsManure(fld.fieldName, man.id); } } } } // delete the actual manure _ud.DeleteFarmManure(dvm.id); string url = Url.Action("RefreshCompostList", "Manure"); return(Json(new { success = true, url = url, target = dvm.target })); } return(PartialView("CompostDelete", dvm)); }
public ActionResult CompostDelete(int id, string target) { CompostDeleteViewModel dvm = new CompostDeleteViewModel(); bool manureUsed = false; dvm.id = id; dvm.target = target; FarmManure nm = _ud.GetFarmManure(id); dvm.manureName = nm.name; // determine if the selected manure is currently being used on any of the fields List <Field> flds = _ud.GetFields(); foreach (var fld in flds) { List <NutrientManure> mans = _ud.GetFieldNutrientsManures(fld.fieldName); foreach (var man in mans) { if (id.ToString() == man.manureId) { manureUsed = true; } } } if (manureUsed) { dvm.warning = _sd.GetUserPrompt("manuredeletewarning"); } dvm.act = "Delete"; return(PartialView("CompostDelete", dvm)); }