private void ValidateDocument(Document document)
        {
            long companyid = Convert.ToInt32(HttpContext.Current.Session["CompanyID"]);
            long documentid = document.DocumentID;
            string dName = document.Name;

            bool oneDocument = documentRepository.IsDocumentExists(companyid, documentid, dName);

            if (oneDocument == true)
            {
                throw new DuplicateDocumentException(String.Format("Document Name {0} already exists. Please try another one.", dName));
            }
            else if (document.FilePath == String.Empty)
            {
                throw new DuplicateDocumentException(String.Format("File Upload is Required , Please Select File and Upload it."));
            }
        }
 public long InsertOrUpdateDocument(Document document)
 {
     try
     {
         context.Entry(document).State = document.DocumentID == 0 ? EntityState.Added : EntityState.Modified;
         SaveChanges();
         return document.DocumentID;
     }
     catch (Exception ex) { throw ex; }
 }
 public long UpdateDocument(Document document)
 {
     ValidateDocument(document);
     try
     {
         return documentRepository.InsertOrUpdateDocument(document);
     }
     catch (Exception e)
     {
         throw e;
     }
 }