public Check FindCheckByID(int id) { using (ProjectDBContext dbContext = new ProjectDBContext()) { return(dbContext.Checks.ToList().Find(x => x.Id == id)); } }
public List <User> GetAllUsers() { using (ProjectDBContext dBContext = new ProjectDBContext()) { return(dBContext.Users.ToList()); } }
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(); } } }
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()); } } }
public List <Check> GetAllChecks() { using (ProjectDBContext dbContext = new ProjectDBContext()) { return(dbContext.Checks.ToList()); } }
public void UpdateUserToDatabase(User user) { using (ProjectDBContext dbContext = new ProjectDBContext()) { dbContext.Entry(user).State = Microsoft.EntityFrameworkCore.EntityState.Modified; dbContext.SaveChanges(); } }
public Token GetUsersToken(User user) { using (ProjectDBContext dbContext = new ProjectDBContext()) { Token usersToken = dbContext.Tokens.ToList().Find(x => x.UserID == user.Id); return(usersToken); } }
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); }
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(); } }
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(); } }
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); } }
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(); } } }