Exemplo n.º 1
0
        public static void ChangeDocument(int id, string name, int docType)
        {
            Document doc = databaseContext.Documents.Where(a => a.id == id).First();

            databaseContext.Entry(doc).State = System.Data.Entity.EntityState.Modified;
            if (name != doc.Name)
            {
                doc.Name = name;
            }
            else
            {
                databaseContext.Entry(doc).Property(x => x.Name).IsModified = false;
            }

            if (doc.DocType != docType)
            {
                doc.DocType = docType;
            }
            else
            {
                databaseContext.Entry(doc).Property(x => x.DocType).IsModified = false;
            }
            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();
        }
Exemplo n.º 2
0
        public static void ChangePoint(int id, string name, int category)
        {
            Point point = databaseContext.Points.Where(a => a.id == id).First();

            databaseContext.Entry(point).State = System.Data.Entity.EntityState.Modified;
            if (point.Name != name)
            {
                point.Name = name;
            }
            else
            {
                databaseContext.Entry(point).Property(x => x.Name).IsModified = false;
            }
            if (point.CategoryID != category)
            {
                point.CategoryID = category;
            }
            else
            {
                databaseContext.Entry(point).Property(x => x.CategoryID).IsModified = false;
            }

            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();
            GetPointsList(true);
        }
Exemplo n.º 3
0
        public static void DeletePointDocConnection(int id)
        {
            PointDocConnection connection = databaseContext.PointDocConnections.Where(a => a.id == id).First();

            databaseContext.Entry(connection).State = System.Data.Entity.EntityState.Deleted;
            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();
        }
Exemplo n.º 4
0
        //==============POINT DOC CONNECTION==============
        public static void CreatePointDocConnection(int pointID, int docID)
        {
            PointDocConnection connection = new PointDocConnection(pointID, docID);

            databaseContext.PointDocConnections.Add(connection);
            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();
        }
Exemplo n.º 5
0
        public static void DeletePoint(int id)
        {
            Point point = databaseContext.Points.OrderByDescending(a => a.id).First();

            databaseContext.Entry(point).State = System.Data.Entity.EntityState.Deleted;
            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();
            GetPointsList(true);
        }
Exemplo n.º 6
0
        public static void DeletePointType(int id)
        {
            PointType type = databaseContext.PointTypes.Where(a => a.id == id).First();

            databaseContext.Entry(type).State = System.Data.Entity.EntityState.Deleted;
            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();
            GetPointTypes(true);
        }
Exemplo n.º 7
0
        //==============DOC TYPE==============
        public static void CreateNewDocType(string name)
        {
            DocumentType type = new DocumentType(name);

            databaseContext.DocumentTypes.Add(type);
            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();

            GetDocumentTypes(true);
        }
Exemplo n.º 8
0
        public static void ChangeDocType(int id, string name)
        {
            DocumentType type = databaseContext.DocumentTypes.Where(a => a.id == id).First();

            databaseContext.Entry(type).State = System.Data.Entity.EntityState.Modified;
            type.Name = name;

            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();
            GetDocumentTypes(true);
        }
Exemplo n.º 9
0
        public static void RestoreDocumentHistory(int id, DateTime newTime)
        {
            string          userName = System.Environment.UserName;
            DocumentHistory history  = databaseContext.DocumentHistories.Where(a => a.id == id).FirstOrDefault();

            DocumentHistory restoredHistory = new DocumentHistory(history.DocumentID, history.DocumentBinary, newTime, userName, history.UserName);

            databaseContext.DocumentHistories.Add(restoredHistory);
            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();
        }
Exemplo n.º 10
0
        public static void CreateDocumentHistrory(int id, string filePath, DateTime newTime)
        {
            byte[]          file     = File.ReadAllBytes(filePath);
            string          userName = System.Environment.UserName;
            string          fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
            DocumentHistory entry    = new DocumentHistory(id, file, newTime, userName, fileName);

            databaseContext.DocumentHistories.Add(entry);
            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();
        }
Exemplo n.º 11
0
        public static void DeleteDocument(int id)
        {
            List <PointDocConnection> connections = databaseContext.PointDocConnections.Where(a => a.DocumentID == id).ToList();

            for (int i = 0; i < connections.Count; i++)
            {
                databaseContext.Entry(connections[i]).State = System.Data.Entity.EntityState.Deleted;
            }

            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();
        }
Exemplo n.º 12
0
        //==============DOCUMENT==============
        public static void CreateDocument(string filePath, int type, string name)
        {
            Document doc = new Document(name, type);

            databaseContext.Documents.Add(doc);
            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();

            int latstDocID = GetLatestDocument();

            CreateDocumentHistrory(latstDocID, filePath);
        }
Exemplo n.º 13
0
        public static void DeleteDocumentHistory(HashSet <int> ids)
        {
            List <DocumentHistory> documentHistories = databaseContext.DocumentHistories.Where(a => ids.Contains(a.id)).ToList();

            for (int i = 0; i < documentHistories.Count; i++)
            {
                databaseContext.Entry(documentHistories[i]).State = System.Data.Entity.EntityState.Deleted;
            }

            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();
        }
Exemplo n.º 14
0
        //==============POINT==============
        public static void CreatePoint(string name, int category)
        {
            Point     point = new Point(name, category);
            PointType t     = databaseContext.PointTypes.Where(a => a.id == category).First();

            //point.PointType = t;

            databaseContext.Points.Add(point);
            databaseContext.SaveChanges();
            databaseContext = new PointDocumentationEntities();

            GetPointsList(true);
        }
Exemplo n.º 15
0
 public static void ChangeDocPointConnection(int docID, HashSet <int> pointsID)
 {
     foreach (var pointID in pointsID)
     {
         PointDocConnection connection = databaseContext.PointDocConnections.Where(a => a.DocumentID == docID && a.PointID == pointID).FirstOrDefault();
         if (connection == null)
         {
             connection = new PointDocConnection(pointID, docID);
             databaseContext.PointDocConnections.Add(connection);
         }
         else
         {
             databaseContext.Entry(connection).State = System.Data.Entity.EntityState.Deleted;
         }
     }
     databaseContext.SaveChanges();
     databaseContext = new PointDocumentationEntities();
 }
Exemplo n.º 16
0
        public static void Initialize()
        {
            if (isTested && canConnect && databaseContext == null)
            {
                databaseContext = new PointDocumentationEntities();
                userRole        = new UserRole();
                string userName = System.Environment.UserDomainName + "\\" + System.Environment.UserName;
                for (int j = 0; j < tables.Count; j++)
                {
                    var allPermissions = GetPermissions(userName, tables[j]);
                    userRole.AddPermissions(tables[j], allPermissions);
                    //List<string>

                    /*for (int i = 0; i < allPermissions.Count; i++)
                     * {
                     * var results = GetPermission(userName,tables[j], allPermissions[i]);
                     * }*/
                }

#if DEBUG
                FillTable();
#endif
            }
        }