Exemple #1
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());
         }
     }
 }
Exemple #2
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();
         }
     }
 }
Exemple #3
0
 public void UpdateUserToDatabase(User user)
 {
     using (ProjectDBContext dbContext = new ProjectDBContext())
     {
         dbContext.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         dbContext.SaveChanges();
     }
 }
Exemple #4
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();
            }
        }