コード例 #1
0
        public int CreateDocument(int projectID, string name, string data)
        {
            using (var unit = GetUnitOfWork())
            {
                checkCookieAndLogin();
                WebToPrintDocument document = new WebToPrintDocument()
                {
                    Name = name,
                    Data = data,
                    WebToPrintProject = unit.Scope.Repository <WebToPrintProject>().GetSingle(c => c.ProjectID == projectID)
                };
                if (document.WebToPrintProject == null)
                {
                    throw new Exception("No valid project found!");
                }
                if (unit.Scope.Repository <WebToPrintDocument>().GetAllAsQueryable(c => c.ProjectID == projectID && c.Name.ToLower() == name).Count() > 0)
                {
                    throw new Exception("Failed to create document: Duplicate name found!");
                }

                try
                {
                    unit.Scope.Repository <WebToPrintDocument>().Add(document);
                    unit.Save();
                }
                catch (SqlException e)
                {
                    throw new Exception("Unknown error occured while inserting new document into the database");
                }
                return(document.DocumentID);
            }
        }
コード例 #2
0
        public ActionResult EditDocument(int id)
        {
            WebToPrintDocument c = this.GetObject <WebToPrintDocument>(cc => cc.DocumentID == id);

            return(Json(new
            {
                success = true,
                data = new
                {
                    c.DocumentID,
                    c.ProjectID,
                    c.Name,
                    c.Data
                }
            }));
        }
コード例 #3
0
 public void SaveDocument(int documentID, string data)
 {
     checkCookieAndLogin();
     using (var unit = GetUnitOfWork())
     {
         ConcentratorPrincipal.Login("SYSTEM", "SYS");
         WebToPrintDocument document = unit.Scope.Repository <WebToPrintDocument>().GetSingle(c => c.DocumentID == documentID);
         if (document == null)
         {
             throw new Exception("Trying to save to a non-existing document!");
         }
         document.Data = data;
         try
         {
             unit.Save();
         }
         catch
         {
             throw new Exception("Unknown error occured while updating the document in the database");
         }
     }
 }