private int InsertBlobToFileLocationStorage(BlobModel blobModel, string type)
        {
            FileLocationStorage locStorage = new FileLocationStorage()
            {
                DateAdded    = DateTime.Now,
                FileLocation = blobModel.FileURI,
                FileName     = blobModel.FileName,
                Type         = type.ToUpper()
            };

            dbObject.FileLocationStorages.Add(locStorage);
            dbObject.SaveChanges();

            return(locStorage.FileID);
        }
        /*
         * Deletes the selected the image of an announcement and deletes it from database and the azure blob storage.
         * */
        public ActionResult RemoveAnnouncementBlob(string file, int?fileID)
        {
            try
            {
                if (User.IsInRole("Administrator"))
                {
                    if (file == null || fileID == null)
                    {
                        return(RedirectToAction("Announcement", "WebsiteContent"));
                    }
                    else
                    {
                        if (websiteActions.DeleteAnnouncementFile(file)) //para kung hindi nabura yung image, hindi na buburahin sa database
                        {
                            AnnouncementResource announcementResource = websiteActions.GetAnnouncementResourceByFileID((int)fileID);
                            websiteActions.DeleteFromAnnouncementResources(announcementResource);

                            FileLocationStorage fileLocationStorage = websiteActions.GetFileLocationStorageByFileID((int)fileID);
                            websiteActions.DeleteFromFileLocationStorage(fileLocationStorage);
                            return(RedirectToAction("Announcements", "Admin"));
                        }
                        else
                        {
                            TempData["errorMessage"] = "There was an error in the server. Please try again";
                            return(RedirectToAction("Announcement", "WebsiteContent"));
                        }
                        //actions2.DeleteAnnouncementFile(file);
                    }
                }
                else
                {
                    TempData["errorMessage"] = "Sorry you do not have access.";
                    return(RedirectToAction("Announcement", "WebsiteContent"));
                }
            }
            catch (Exception e)
            {
                TempData["errorMessage"] = "There was an error in removing the photo you have selected.";
                return(RedirectToAction("Announcement", "WebsiteContent"));
            }
        }
Пример #3
0
        /*
         * Deletes the selected uploaded requiremensts from the database and azure blob storage.
         * */
        public ActionResult DeleteRequestBlob(string fileName, int?fileID)
        {
            try
            {
                if (User.IsInRole("Student"))
                {
                    if (fileName == null || fileID == null)
                    {
                        return(RedirectToAction("RequestStatus"));
                    }
                    else
                    {
                        if (studentActions.DeleteRequestBlob(fileName))
                        {
                            RequestResource requestResource = studentActions.GetRequestResourceByFileID((int)fileID);
                            studentActions.DeleteFromRequestResource(requestResource);

                            FileLocationStorage fileLocationStorage = studentActions.GetFileLocationStorageByFileID((int)fileID);
                            studentActions.DeleteFromFileLocationStorage(fileLocationStorage);

                            return(RedirectToAction("EditRequest", new { requestID = requestResource.RequestID }));
                        }
                        TempData["errorMessage"] = "There was an error in the server. Please try again.";
                        return(RedirectToAction("RequestStatus"));
                    }
                }
                else
                {
                    TempData["errorMessage"] = "Sorry you do not have access.";
                    return(RedirectToAction("Announcement", "WebsiteContent"));
                }
            }
            catch (Exception e)
            {
                TempData["errorMessage"] = "There was an error in deletings. Please try again, thank you!";
                return(RedirectToAction("RequestStatus"));
            }
        }
        /*
         * 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 DeleteFromFileLocationStorage(FileLocationStorage fileLocationStorage)
 {
     dbObject.FileLocationStorages.Remove(fileLocationStorage);
     dbObject.SaveChanges();
 }