예제 #1
0
        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);
            }
        }
예제 #2
0
 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);
     }
 }
예제 #3
0
 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);
     }
 }
예제 #4
0
 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);
     }
 }
예제 #5
0
 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();
         }
     }
 }
예제 #6
0
        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 = "******";
                }
            }
        }
예제 #7
0
 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";
     }
 }
예제 #8
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);
            }
        }
예제 #9
0
 /// <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");
     }
 }
예제 #10
0
 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");
     }
 }
예제 #11
0
 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);
     }
 }
예제 #12
0
 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);
     }
 }
예제 #13
0
 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");
     }
 }
예제 #14
0
 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");
     }
 }
예제 #15
0
 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);
     }
 }
예제 #16
0
 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>());
     }
 }
예제 #17
0
 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);
     }
 }
예제 #18
0
 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");
     }
 }
예제 #19
0
 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!";
     }
 }
예제 #20
0
 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");
     }
 }
예제 #21
0
 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);
     }
 }
예제 #22
0
        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
                {
                }
            }
        }
예제 #23
0
 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);
     }
 }
예제 #24
0
        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);
        }
예제 #25
0
 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);
     }
 }
예제 #26
0
        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();
        }
예제 #27
0
        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 = "******";
                }
            }
        }
예제 #28
0
 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);
     }
 }
예제 #29
0
 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");
     }
 }
예제 #30
0
        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);
        }