public ActionResult CancelImport(Guid id) { var import = _db.Imports.SingleOrDefault(f => f.Id == id); if (import == null) { //import might be already cancelled. throw new Exception("Imoprt data not found. Most probably it is already cancelled."); } Service service = getservicebyimportid(id); var subreport = GetSubReportByImportId(id); _db.ExecuteStoreCommand("delete from [dbo].[ImportClientReports] where importid={0}", id); _db.ExecuteStoreCommand("delete from [dbo].[Imports] where id={0}", id); if (service.ReportingMethodId == (int)CC.Data.Service.ReportingMethods.SoupKitchens) { return(RedirectToAction("Calendar", "SubReports", new { Id = subreport.Id })); } return(RedirectToAction("Details", "SubReports", new { id = import.TargetId })); }