public List <Check> SearchedChecks(string searchParam, DateTime selectedDate) { MyLogger.Instance().Log($"Search {searchParam} -- CALLED", "Service", "INFO"); ISearch search; try { lock (x) { if (searchParam == "ON") { search = new SearchOn(); } else if (searchParam == "BEFORE") { search = new SearchBefore(); } else if (searchParam == "AFTER") { search = new SearchAfter(); } else { return(GetChecks()); } return(search.SearchChecks(selectedDate)); } } catch { MyLogger.Instance().Log("Search command -- ERROR", "Service", "FATAL"); return(null); } }
public bool ValidateCheckChange(Check check) { MyLogger.Instance().Log("Validate Check -- CALLED", "Service", "INFO"); try { lock (x) { using (ProjectDBContext dBContext = new ProjectDBContext()) { Check toValidate = dBContext.Checks.ToList().Find(x => x.Id == check.Id); if (DateTime.Compare(check.Datetime, dBContext.Checks.ToList().Find(x => x.Id == check.Id).Datetime) != 0) { MyLogger.Instance().Log("Validate Check -- FAILED", "Service", "INFO"); return(false); } else { MyLogger.Instance().Log("Validate Check -- SUCCESS", "Service", "INFO"); return(true); } } } } catch { MyLogger.Instance().Log("Validate Check -- ERROR", "Service", "FATAL"); return(false); } }
public User Login(string username, string password) { MyLogger.Instance().Log("Login -- CALLED", "Service", "INFO"); try { lock (x) { List <User> users = database.GetAllUsers(); User retVal = users.SingleOrDefault(x => x.Username == username && x.Password == password); if (retVal == null) { MyLogger.Instance().Log("Login -- ERROR", "Service", "ERROR"); } else { MyLogger.Instance().Log("Login -- SUCCESS", "Service", "INFO"); } return(retVal); } } catch (Exception e) { MyLogger.Instance().Log("Login -- ERROR", "Service", "FATAL"); return(null); } }
public bool ValidateCheckDeletion(Check check) { MyLogger.Instance().Log("Validate Check's deletion -- CALLED", "Service", "INFO"); try { lock (x) { using (ProjectDBContext dBContext = new ProjectDBContext()) { Check toDelete = dBContext.Checks.ToList().Find(c => c.Id == check.Id); if (dBContext.Checks.ToList().Exists(x => x.Id == check.Id)) { MyLogger.Instance().Log("Validate Check's deletion -- SUCCESS", "Service", "INFO"); return(true); } else { MyLogger.Instance().Log("Validate Check's deletion -- FAIL", "Service", "ERROR"); return(false); } } } } catch { MyLogger.Instance().Log("Validate Check's deletion -- ERROR", "Service", "FATAL"); return(false); } }
public void OnAddGateExecute(object parameter) { if (!IsChange) { if (String.IsNullOrEmpty(GateName)) { ErrorLabel = "Enter gate's name!"; } else if (LevelOfAccess < 0) { ErrorLabel = "Level of access can't be lesser than 0"; } else if (String.IsNullOrEmpty(GateName) && String.IsNullOrEmpty(LevelOfAccess.ToString())) { ErrorLabel = "Fields can't be empty!"; } else { if (Channel.Instance.GateServiceProxy.AddGate(GateName, LevelOfAccess)) { MyLogger.Instance().Log("Add gate -- SUCCESS!", CurrentUser.Instance.Username, "INFO"); } else { MyLogger.Instance().Log("Add gate -- FAIL!", CurrentUser.Instance.Username, "ERROR"); } Window.Close(); } } else { if (String.IsNullOrEmpty(GateName)) { ErrorLabel = "Enter gate's name!"; } else if (LevelOfAccess < 0) { ErrorLabel = "Level of access can't be lesser than 0"; } else if (String.IsNullOrEmpty(GateName) && String.IsNullOrEmpty(LevelOfAccess.ToString())) { ErrorLabel = "Fields can't be empty!"; } else { if (Channel.Instance.GateServiceProxy.ChangeGate(GateName, LevelOfAccess, SelectedGate)) { MyLogger.Instance().Log("Change gate -- SUCCESS", CurrentUser.Instance.Username, "INFO"); } else { MyLogger.Instance().Log("Change gate -- FAIL!", CurrentUser.Instance.Username, "INFO"); } Window.Close(); } } }
public void OnAddUserExecute(object parameter) { ErrorName = ErrorLastname = ErrorUsername = ErrorPassword = ""; if (String.IsNullOrEmpty(NewUser.Name)) { ErrorName = "Name can't be empty"; } else if (String.IsNullOrEmpty(NewUser.LastName)) { ErrorLastname = "Last name can't be empty"; } else if (String.IsNullOrEmpty(NewUser.Username)) { ErrorUsername = "******"; } else if (String.IsNullOrEmpty(NewUser.Password)) { ErrorPassword = "******"; } else { if (ValidateCreatedUser(NewUser)) { MyLogger.Instance().Log("Created user VALIDATED!", CurrentUser.Instance.Username, "INFO"); if (Admin) { NewUser.Type = USER_TYPE.ADMIN; } else { NewUser.Type = USER_TYPE.USER; } if (Channel.Instance.UserProxy.AddUser(newUser)) { MyLogger.Instance().Log("Add user -- SUCCESS!", CurrentUser.Instance.Username, "INFO"); Window.Close(); } else { MyLogger.Instance().Log("Add user -- Error!", CurrentUser.Instance.Username, "INFO"); ErrorUsername = "******"; } } else { MyLogger.Instance().Log("Created user -- NOT VALIDATED!", CurrentUser.Instance.Username, "INFO"); ErrorUsername = "******"; } } }
public void OnIssueToken(object parameter) { if (GrantedLevel >= 0) { MyLogger.Instance().Log("Issue Token -- CALLED", CurrentUser.Instance.Username, "INFO"); Channel.Instance.TokenServiceProxy.GenerateToken(selectedUser.Id, GrantedLevel); Window.Close(); } else { ErrorLabel = "Level of access can't be lesser than 0"; } }
public bool ValidateUser(User user) { List <User> users = GetAllUsers(); if (users.SingleOrDefault(x => x.Username == user.Username) != null) { MyLogger.Instance().Log("Validate user -- SUCCESS!", "Service", "ERROR"); return(false); } else { MyLogger.Instance().Log("Validate user -- SUCCESS!", "Service", "INFO"); return(true); } }
/// <summary> /// /////////////////////////////////////////////////////////////////////////////////// /// </summary> /// <param name="check"></param> public void DeleteCheck(Check check) { MyLogger.Instance().Log("Delete Check -- CALLED", "Service", "INFO"); try { lock (x) { db.DeleteCheck(check); } } catch { MyLogger.Instance().Log("Delete Check -- ERROR", "Service", "FATAL"); } }
public void DeleteGate(Gate selectedGate) { MyLogger.Instance().Log("Delete Gate -- CALLED", "Service", "INFO"); try { lock (x) { db.DeleteGate(selectedGate); } } catch { MyLogger.Instance().Log("Delete Gate -- ERROR", "Service", "FATAL"); } }
public Check FindLastCheck() { MyLogger.Instance().Log("Find Last Check -- CALLED", "Service", "INFO"); try { lock (x) { return(db.FindLastCheck()); } } catch { MyLogger.Instance().Log("Find Last check -- ERROR", "Service", "FATAL"); return(null); } }
public int FindLastCheckID() { MyLogger.Instance().Log("Find Last Check's ID -- CALLED", "Service", "INFO"); try { lock (x) { return(db.FindLastCheckID()); } } catch { MyLogger.Instance().Log("Find Last Check's ID -- ERROR", "Service", "FATAL"); return(-1); } }
public void BanUser(string username, int gateID) { MyLogger.Instance().Log("Ban user -- CALLED", "Service", "INFO"); try { lock (x) { MyLogger.Instance().Log("Ban user -- SUCCESS", "Service", "INFO"); db.BanUser(username, gateID); } } catch { MyLogger.Instance().Log("Ban user -- FAIL", "Service", "FATAL"); } }
public void RecallToken(int userID) { MyLogger.Instance().Log("Recall Token -- CALLED", "Service", "INFO"); try { lock (x) { MyLogger.Instance().Log("Recall Token -- SUCCESS", "Service", "INFO"); db.DeleteToken(userID); } } catch { MyLogger.Instance().Log("Recall Token -- FAIL", "Service", "FATAL"); } }
public bool ValidateUser(User user) { MyLogger.Instance().Log("Validate user -- called", "Service", "INFO"); try { lock (x) { return(database.ValidateUser(user)); } } catch { MyLogger.Instance().Log("Validate user -- FAIL!", "Service", "FATAL"); return(false); } }
public List <Check> GetChecks() { //MyLogger.Instance().Log("Get Checks -- CALLED", "Service", "INFO"); try { lock (x) { return(db.GetAllChecks()); } } catch { MyLogger.Instance().Log("Get Checks -- ERROR", "Service", "FATAL"); return(new List <Check>()); } }
public Check FindCheckByID(int id) { MyLogger.Instance().Log("Find check by id -- CALLED", "Service", "INFO"); try { lock (x) { return(db.FindCheckByID(id)); } } catch { MyLogger.Instance().Log("Find check by id -- ERROR", "Service", "FATAL"); return(null); } }
public void GenerateToken(int userID, int level) { MyLogger.Instance().Log("Generate Token -- CALLED", "Service", "INFO"); try { lock (x) { MyLogger.Instance().Log("Generate Token -- SUCCESS", "Service", "INFO"); db.GenerateToken(userID, level); } } catch { MyLogger.Instance().Log("Generate Token -- ERROR", "Service", "FATAL"); } }
public void OnBanUserExecute(object parameter) { MyLogger.Instance().Log("Ban user -- CALLED", CurrentUser.Instance.Username, "INFO"); if (SelectedGate != null && SelectedUser != null) { Channel.Instance.GateServiceProxy.BanUser(SelectedUser.Username, SelectedGate.GateID); Window.Close(); } else if (SelectedUser == null) { ErrorLabel = "Select user first!"; } else if (SelectedGate == null) { ErrorLabel = "Select gate first!"; } }
public string IssueCheck(User user, Gate gate, CheckType type) { MyLogger.Instance().Log("Issue check -- CALLED", "Service", "INFO"); try { lock (x) { //MyLogger.Instance().Log("Issue check -- SUCCESS", "Service", "INFO"); return(cs.GenerateCheck(user, gate, type)); } } catch { MyLogger.Instance().Log("Issue check -- ERROR", "Service", "FATAL"); return("Exception cought! Contct your system administrator"); } }
public List <User> GetAllUsers() { //MyLogger.Instance().Log("Get all users -- CALLED", "Service", "INFO"); try { lock (x) { //MyLogger.Instance().Log("Get all users -- SUCCESS", "Service", "INFO"); return(database.GetAllUsers()); } } catch { MyLogger.Instance().Log("Get all users -- ERROR", "Service", "FATAL"); return(null); } }
public void OnLogin(object parameter) { UsernameError = PasswordError = ""; Password = (LoginGrid.FindName("PasswordBox") as PasswordBox).Password; MyLogger.Instance().Log("Login -- CALLED", "Login", "INFO"); if (String.IsNullOrWhiteSpace(Username)) { UsernameError = "You need to enter username."; } else { UsernameError = ""; } if (String.IsNullOrWhiteSpace(Password)) { PasswordError = "You need to enter password."; } else { PasswordError = ""; } if (!String.IsNullOrWhiteSpace(Username) && !String.IsNullOrWhiteSpace(Password)) { try { CurrentUser.Instance = Channel.Instance.UserProxy.Login(Username, Password); if (!String.IsNullOrWhiteSpace(CurrentUser.Instance.Username)) { MyLogger.Instance().Log("Login -- SUCCESS", "Login", "INFO"); // MyLogger.Instance().Log("Login -- SUCCESS", CurrentUser.Instance.Username, "INFO"); new MainWindow().Show(); Window.Close(); } else { MyLogger.Instance().Log("Login -- FAIL", "Login", "ERROR"); PasswordError = "Username and password doesn't match."; CurrentUser.Instance = null; } } catch { } } }
public bool DeleteUser(User user) { MyLogger.Instance().Log("Delete user -- CALLED", "Service", "INFO"); try { lock (x) { database.DeleteUserFromDatabase(user); MyLogger.Instance().Log("Delete user -- SUCCESS", "Service", "INFO"); return(true); } } catch (Exception e) { MyLogger.Instance().Log("Delete user -- ERROR!", "Service", "FATAL"); return(false); } }
public AddGateViewModel(bool isChange, Gate selectedGate) { if (isChange) { ButtonContent = "Change Gate: " + selectedGate.Name; GateName = selectedGate.Name; LevelOfAccess = selectedGate.LevelOfAccess; MyLogger.Instance().Log("Change gate -- CALLED", CurrentUser.Instance.Username, "INFO"); } else { ButtonContent = "Add new Gate"; MyLogger.Instance().Log("Add gate -- CALLED", CurrentUser.Instance.Username, "INFO"); } IsChange = isChange; SelectedGate = selectedGate; AddGateExecute = new MyICommand(OnAddGateExecute); }
public bool AddGate(string name, int levelOfAccess) { MyLogger.Instance().Log("Add Gate -- CALLED", "Service", "INFO"); try { lock (x) { db.AddGateToDataBase(new Gate() { Name = name, LevelOfAccess = levelOfAccess }); MyLogger.Instance().Log("Add Gate -- SUCCESS!", "Service", "INFO"); return(true); } } catch { MyLogger.Instance().Log("Add Gate -- FAIL!", "Service", "Error"); return(false); } }
public bool ChangeGate(string gateName, int levelOfAccess, Gate selectedGate) { MyLogger.Instance().Log("Change Gate -- CALLED", "Service", "INFO"); try { lock (x) { db.ChangeGate(gateName, levelOfAccess, selectedGate); MyLogger.Instance().Log("Change gate -- SUCCESS!", "Service", "INFO"); return(true); } } catch { MyLogger.Instance().Log("Change gate -- FAIL!", "Service", "ERROR"); return(false); } //throw new NotImplementedException(); }
public void OnChangeInfoExecute(object parameter) { ErrorName = ErrorLastname = ErrorUsername = ErrorPassword = ""; if (String.IsNullOrEmpty(NewUser.Name)) { ErrorName = "Name can't be empty"; } else if (String.IsNullOrEmpty(NewUser.LastName)) { ErrorLastname = "Last name can't be empty"; } else if (String.IsNullOrEmpty(NewUser.Username)) { ErrorUsername = "******"; } else if (String.IsNullOrEmpty(NewUser.Password)) { ErrorPassword = "******"; } else { if (Channel.Instance.UserProxy.ChangeInfo(newUser)) { MyLogger.Instance().Log("Change user -- SUCCESS!", CurrentUser.Instance.Username, "INFO"); CurrentUser.Instance.Name = newUser.Name; CurrentUser.Instance.LastName = newUser.LastName; CurrentUser.Instance.Username = newUser.Username; CurrentUser.Instance.Password = newUser.Password; Window.Close(); } else { MyLogger.Instance().Log("Change user -- FAIL!", CurrentUser.Instance.Username, "ERROR"); ErrorUsername = "******"; } } }
public bool ChangeInfo(User user) { MyLogger.Instance().Log("Change user -- CALLED", "Service", "INFO"); try { lock (x) { User userToUpdate = database.GetAllUsers().Find(x => x.Username == user.Username); userToUpdate.Name = user.Name; userToUpdate.LastName = user.LastName; userToUpdate.Password = user.Password; database.UpdateUserToDatabase(userToUpdate); MyLogger.Instance().Log("Change info -- SUCCESS!", "Service", "INFO"); return(true); } } catch (Exception e) { MyLogger.Instance().Log("Change info -- FAIL!", "Service", "FATAL"); return(false); } }
public void ModifyCheck(DateTime newDate, Check check) { MyLogger.Instance().Log("Modify Check -- CALLED", "Service", "INFO"); try { lock (x) { MyLogger.Instance().Log("Modify Check -- SUCCESS", "Service", "INFO"); Check toModify = db.GetAllChecks().Find(x => x.Id == check.Id); if (toModify == null) { toModify = check; } toModify.Datetime = newDate; db.ModifyCheck(toModify); } } catch { MyLogger.Instance().Log("Modify Check -- FAIL", "Service", "FATAL"); } }
public AddUserViewModel(bool changing) { IsChange = changing; if (changing) { NewUser = new User(CurrentUser.Instance); Title = "Change Info"; Visible = "Hidden"; Visible2 = "Visible"; MyLogger.Instance().Log("Change user -- CALLED", CurrentUser.Instance.Username, "INFO"); } else { Title = "Add User"; Visible = "Visible"; Visible2 = "Hidden"; MyLogger.Instance().Log("Add user -- CALLED", CurrentUser.Instance.Username, "INFO"); } AddUserCommand = new MyICommand(OnAddUserExecute); ChangeInfoCommand = new MyICommand(OnChangeInfoExecute); }