public ActionResult AddDocument(Document m_Document, HttpPostedFileBase fileUpload)
        {
            ViewBag.ParentId = m_Document.ParentId;
            ViewBag.myContentGroups = Utility.ContentGroups();

            if (fileUpload != null && fileUpload.ContentLength > 0)
            {
                if (!Utility.mimeTypeAllowed(fileUpload.ContentType))
                {
                    ModelState.AddModelError("Name", "This document type is not allowed");
                }
            }
            else
            {
                ModelState.AddModelError("Name", "Please chose a file to upload");
            }

            if (ModelState.IsValid)
            {
               DocumentRepository.Create(m_Document, fileUpload);
               return RedirectToAction("Index", "Document", new { id = m_Document.ParentId });
            }
            else
            {
                return View("AddDocument", m_Document);
            }
        }
        public ActionResult AddDocument(int id = 0)
        {
            ViewBag.ParentId = id;
            ViewBag.myContentGroups = Utility.ContentGroups();

            Document m_Document = new Document();
            return View("AddDocument", m_Document);
        }
Example #3
0
        public static void Create(Document m_Document)
        {
            SqlConnection conn = DB.DbConnect();
            conn.Open();

            string queryString = "INSERT INTO CMS_Documents(name, parentId, fileType, contentGroup) VALUES(@name, @parentId, @fileType, @contentGroup)";
            SqlCommand insertDoc = new SqlCommand(queryString, conn);
            insertDoc.Parameters.AddWithValue("name", m_Document.Name);
            insertDoc.Parameters.AddWithValue("parentId", m_Document.ParentId);
            insertDoc.Parameters.AddWithValue("fileType", m_Document.FileType);
            insertDoc.Parameters.AddWithValue("contentGroup", m_Document.ContentGroup);

            insertDoc.ExecuteNonQuery();

            conn.Close();
        }
        public void Create(Document m_Document, HttpPostedFileBase fileUpload)
        {
            string fileExt = fileUpload.FileName.Split('.').Last();
            m_Document.FileType = fileExt;

            DBDocument.Create(m_Document);

            string path = "";

            if (m_Document.ParentId != 0)
            {
                path = DBFolder.FolderPath(m_Document.ParentId);
                path += "\\" + m_Document.Name;
            }
            else
            {
                path = m_Document.Name;
            }

            fileUpload.SaveAs(ConfigurationManager.AppSettings["Documents"] + "\\" + path + "." + fileExt);
        }
Example #5
0
        public static Document RetrieveOne(int id)
        {
            SqlConnection conn = DB.DbConnect();
            conn.Open();

            string queryString = "SELECT * FROM CMS_Documents where id = @id AND pageWorkFlowState != 4";
            SqlCommand getDocument = new SqlCommand(queryString, conn);
            getDocument.Parameters.AddWithValue("id", id);
            SqlDataReader documentReader = getDocument.ExecuteReader();

            Document m_Document = new Document();

            if (documentReader.Read())
            {
                m_Document.Id = documentReader.GetInt32(0);
                m_Document.Name = documentReader.GetString(1);
                m_Document.ParentId = documentReader.GetInt32(2);
                m_Document.FileType = documentReader.GetString(3);
                m_Document.ContentGroup = documentReader.GetInt32(4);
            }

            conn.Close();

            return m_Document;
        }
Example #6
0
        public static void Update(Document m_Document)
        {
            SqlConnection conn = DB.DbConnect();
            conn.Open();

            string queryString = "UPDATE CMS_Documents SET name = @name, parentId = @parentId, fileType = @fileType, contentGroup = @contentGroup WHERE id = @id";
            SqlCommand updateDocument = new SqlCommand(queryString, conn);
            updateDocument.Parameters.AddWithValue("name", m_Document.Name);
            updateDocument.Parameters.AddWithValue("parentId", m_Document.ParentId);
            updateDocument.Parameters.AddWithValue("fileType", m_Document.FileType);
            updateDocument.Parameters.AddWithValue("contentGroup", m_Document.ContentGroup);
            updateDocument.Parameters.AddWithValue("id", m_Document.Id);

            updateDocument.ExecuteNonQuery();

            conn.Close();
        }
Example #7
0
        public static List<Document> RetriveAll(int id)
        {
            SqlConnection conn = DB.DbConnect();
            conn.Open();

            string queryString = "SELECT * FROM CMS_Documents where parentId = @parentId AND pageWorkFlowState != 4";
            SqlCommand getDocuments = new SqlCommand(queryString, conn);
            getDocuments.Parameters.AddWithValue("parentId", id);
            SqlDataReader documentsReader = getDocuments.ExecuteReader();

            List<Document> m_Documents = new List<Document>();

            while (documentsReader.Read())
            {
                Document tempDoc = new Document();

                tempDoc.Id = documentsReader.GetInt32(0);
                tempDoc.Name = documentsReader.GetString(1);
                tempDoc.ParentId = documentsReader.GetInt32(2);
                tempDoc.FileType = documentsReader.GetString(3);
                tempDoc.ContentGroup = documentsReader.GetInt32(4);

                m_Documents.Add(tempDoc);
            }

            conn.Close();

            return m_Documents;
        }
 public Document RetrieveOne(int id)
 {
     Document m_Document = new Document();
     return m_Document;
 }
        public void Update(Document m_Document, string OldName, HttpPostedFileBase fileUpload)
        {
            DBDocument.Update(m_Document);
            string path = "";

            if (OldName != m_Document.Name)
            {
                if (m_Document.ParentId != 0)
                {
                    path = DBFolder.FolderPath(m_Document.ParentId);
                }

                string oldPath = ConfigurationManager.AppSettings["Documents"] + "\\" + path + "\\" + OldName + "." + m_Document.FileType;
                string newPath = ConfigurationManager.AppSettings["Documents"] + "\\" + path + "\\" + m_Document.Name + "." + m_Document.FileType;

                File.Move(oldPath, newPath);
            }
            if (fileUpload != null && fileUpload.ContentLength > 0)
            {
                if (m_Document.ParentId != 0)
                {
                    path = DBFolder.FolderPath(m_Document.ParentId);
                    path += "\\" + m_Document.Name;
                }

                File.Delete(ConfigurationManager.AppSettings["Documents"] + "\\" + path);
                fileUpload.SaveAs(ConfigurationManager.AppSettings["Documents"] + "\\" + path);
            }
        }