public void InsertFormToFormResource(Form formModel, BlobModel blobModel) { int newFileID = InsertBlobToFileLocationStorage(blobModel, "Form"); FormsResource formResource = new FormsResource() { FileID = newFileID, FormID = formModel.FormID }; dbObject.FormsResources.Add(formResource); dbObject.SaveChanges(); }
/* * Removes a selected a file from an uploaded downloadable form. And deletes from the database. * */ public ActionResult RemoveFormBlob(string fileName, int?fileID) { try { if (User.IsInRole("Administrator")) { if (fileName == null || fileID == null) { return(RedirectToAction("DownloadableForms")); } else { if (websiteActions.DeleteFormFile(fileName)) { FormsResource formResource = websiteActions.GetFormResourceByFileID((int)fileID); websiteActions.DeleteFromFormResource(formResource); FileLocationStorage fileLocationStorage = websiteActions.GetFileLocationStorageByFileID((int)fileID); websiteActions.DeleteFromFileLocationStorage(fileLocationStorage); return(RedirectToAction("Forms", "Admin")); } TempData["errorMessage"] = "There was an error in the server. Please try again."; return(RedirectToAction("Forms", "Admin")); } } else { TempData["errorMessage"] = "Sorry you do not have access."; return(RedirectToAction("DownloadableForms", "WebsiteContent")); } } catch (Exception e) { TempData["errorMessage"] = "There was an error in deleting the form"; return(RedirectToAction("DownloadableForms", "WebsiteContent")); } }
/* * Deletes the whole downloadable form from the database including the file. * */ public ActionResult DeleteForm(int?formID) { try { if (User.IsInRole("Administrator")) { if (formID == null) { return(RedirectToAction("DownloadableForms", "WebsiteContent")); } else { Form form = websiteActions.GetFormByID((int)formID); FormsResource formResource = form.FormsResources.Where(model => model.FormID == formID).FirstOrDefault(); FileLocationStorage fileLocationStorage = websiteActions.GetFileLocationStorageByFileID(formResource.FileID); if (websiteActions.DeleteFormFile(fileLocationStorage.FileName)) { websiteActions.DeleteFromFormResource(formResource); websiteActions.DeleteFromFileLocationStorage(fileLocationStorage); websiteActions.DeleteFromForms(form); } return(RedirectToAction("Forms", "Admin")); } } else { TempData["errorMessage"] = "Sorry you do not have access."; return(RedirectToAction("DownloadableForm", "WebsiteContent")); } } catch (Exception e) { TempData["errorMessage"] = "There was an error in deleting the form."; return(RedirectToAction("DownloadableForms", "WebsiteContent")); } }
public void DeleteFromFormResource(FormsResource formResource) { dbObject.FormsResources.Remove(formResource); dbObject.SaveChanges(); }