Esempio n. 1
0
 public Check FindCheckByID(int id)
 {
     using (ProjectDBContext dbContext = new ProjectDBContext())
     {
         return(dbContext.Checks.ToList().Find(x => x.Id == id));
     }
 }
Esempio n. 2
0
 public List <User> GetAllUsers()
 {
     using (ProjectDBContext dBContext = new ProjectDBContext())
     {
         return(dBContext.Users.ToList());
     }
 }
Esempio n. 3
0
 public void GenerateToken(int userID, int level)
 {
     using (ProjectDBContext dbContext = new ProjectDBContext())
     {
         List <Token> tokensInDB    = dbContext.Tokens.ToList <Token>();
         Token        tokenToUpdate = tokensInDB.SingleOrDefault(x => x.UserID == userID);
         if (tokenToUpdate == null)
         {
             Token toAdd = new Token()
             {
                 UserID = userID, LevelOfAccess = level
             };
             dbContext.Tokens.Add(toAdd);
             dbContext.SaveChanges();
         }
         else
         {
             Token t = dbContext.Tokens.ToList().Find(x => x.UserID == userID);
             t.LevelOfAccess = level;
             dbContext.Tokens.Attach(t);
             dbContext.Entry(t).State = EntityState.Modified;
             dbContext.SaveChanges();
         }
     }
 }
Esempio n. 4
0
 public void ModifyCheck(Check check)
 {
     using (ProjectDBContext dbContext = new ProjectDBContext())
     {
         Check c = dbContext.Checks.ToList().Find(x => x.Id == check.Id);
         if (c == null)
         {
             c = new Check()
             {
                 Datetime = check.Datetime,
                 GateID   = check.GateID,
                 Token    = check.Token,
                 TokenId  = check.TokenId,
                 Type     = check.Type,
             };
             dbContext.Add(c);
             dbContext.SaveChanges();
             CommandHandler.Instance.UpdateCheckIDS(c.Id, FindLastCheckID());
         }
         else
         {
             c.Datetime = check.Datetime;
             dbContext.Checks.Attach(c);
             dbContext.Entry(c).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
             dbContext.SaveChanges();
             CommandHandler.Instance.UpdateCheckIDS(c.Id, FindLastCheckID());
         }
     }
 }
Esempio n. 5
0
 public List <Check> GetAllChecks()
 {
     using (ProjectDBContext dbContext = new ProjectDBContext())
     {
         return(dbContext.Checks.ToList());
     }
 }
Esempio n. 6
0
 public void UpdateUserToDatabase(User user)
 {
     using (ProjectDBContext dbContext = new ProjectDBContext())
     {
         dbContext.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Esempio n. 7
0
 public Token GetUsersToken(User user)
 {
     using (ProjectDBContext dbContext = new ProjectDBContext())
     {
         Token usersToken = dbContext.Tokens.ToList().Find(x => x.UserID == user.Id);
         return(usersToken);
     }
 }
Esempio n. 8
0
        public List <Gate> GetGates()
        {
            List <Gate> gates = new List <Gate>();

            using (ProjectDBContext dbContext = new ProjectDBContext())
            {
                foreach (Gate g in dbContext.Gates)
                {
                    gates.Add(g);
                }
            }


            return(gates);
        }
Esempio n. 9
0
        public void ChangeGate(string gateName, int levelOfAccess, Gate selectedGate)
        {
            using (ProjectDBContext dbContext = new ProjectDBContext())
            {
                Gate toChange = projectDBContext.Gates.ToList().Find(x => x.GateID == selectedGate.GateID);
                toChange.Name          = gateName;
                toChange.LevelOfAccess = levelOfAccess;
                toChange.Checks        = selectedGate.Checks;

                dbContext.Gates.Attach(toChange);
                var entry = dbContext.Entry(toChange);
                entry.State = EntityState.Modified;
                dbContext.SaveChanges();
            }
        }
Esempio n. 10
0
 public void DeleteToken(int userId)
 {
     using (ProjectDBContext dbContext = new ProjectDBContext())
     {
         Token toDelete = new Token();
         foreach (Token t in dbContext.Tokens)
         {
             if (t.UserID == userId)
             {
                 toDelete = t;
                 break;
             }
         }
         dbContext.Tokens.Remove(toDelete);
         dbContext.SaveChanges();
     }
 }
Esempio n. 11
0
 public void CloneCheck(Check check)
 {
     using (ProjectDBContext dbContext = new ProjectDBContext())
     {
         Check clone = new Check()
         {
             Datetime = check.Datetime,
             GateID   = check.GateID,
             Token    = check.Token,
             TokenId  = check.TokenId,
             Type     = check.Type
         };
         dbContext.Checks.Add(clone);
         dbContext.SaveChanges();
         Gate g = dbContext.Gates.ToList().Find(x => x.GateID == check.GateID);
         g.Checks.Add(clone);
         this.ChangeGate(g.Name, g.LevelOfAccess, g);
     }
 }
Esempio n. 12
0
 public void DeleteCheck(Check check)
 {
     using (ProjectDBContext dbContext = new ProjectDBContext())
     {
         Check toDelete = null;
         foreach (Check c in dbContext.Checks)
         {
             if (c.Id == check.Id)
             {
                 toDelete = c;
                 break;
             }
         }
         if (toDelete != null)
         {
             dbContext.Checks.Remove(toDelete);
             dbContext.SaveChanges();
         }
     }
 }