public EmployeeModel GetEmbloyeeById(uint employeeId)
 {
     using (var db = DbManager.CreateInstance())
     {
         EmployeeRepository rep = new EmployeeRepository();
         var employee = rep.GetEmployeeById(db, employeeId);
         return employee;
     }
 }
 private void LoadAllEmployees(bool isActive)
 {
     using (var db = DbManager.CreateInstance())
     {
         EmployeeRepository rep = new EmployeeRepository();
         this.Employees = rep.LoadAllEmployees(db, isActive);
     }
 }
Beispiel #3
0
        public CheckResult DeleteEmployee(EmployeeModel focusedEmployee)
        {
            CheckResult check = CheckResult.Default;
            using (var db = DbManager.CreateInstance())
            {
                try
                {
                    EmployeeRepository rep = new EmployeeRepository();
                    rep.DeleteEmployee(db, focusedEmployee);
                    db.SaveChanges();
                    this.Employees.Remove(focusedEmployee);
                }
                catch (NullReferenceException nREx)
                {
                    //TODO Log
                    check.Details.Add(new CheckResultDetail(CheckResultDetail.ErrorType.Error, "", nREx.Message));
                    return check;
                }
                catch (DataStoreException)
                {
                    check.Details.Add(
                        new CheckResultDetail(
                            CheckResultDetail.ErrorType.Error,
                            "InvalidDeletion",
                            Messages.CannotDeleteLinkedItem));
                    return check;
                }
                catch (Exception)
                {
                    //TODO Log
                    check.Details.Add(
                        new CheckResultDetail(
                            CheckResultDetail.ErrorType.Error,
                            "InvalidDeletion",
                            "Deletion failed!"));
                    return check;
                }

                return check;
            }
        }
Beispiel #4
0
        public CheckResult SaveAccount()
        {
            CheckResult result = CheckResult.Default;
            uint employeeId = this.CurrentEmployee.Id;
            using (var db = DbManager.CreateInstance())
            {
                try
                {
                    if (this.CurentEmployeeIsDirty())
                    {
                        EmployeeValidator employeeValidator = new EmployeeValidator();
                        var checkEmployee = employeeValidator.ValidateEmployee(db, this.CurrentEmployee);

                        if (!checkEmployee.Success)
                        {
                            result.Details.AddRange(checkEmployee.Details);
                        }
                        else
                        {
                            EmployeeRepository employeeRepository = new EmployeeRepository();
                            employeeRepository.SaveEmployee(db, this.CurrentEmployee);
                            this.CurrentUser.EmployeeId = this.CurrentEmployee.Id;
                        }
                    }

                    if (this.CurentUserIsDirty())
                    {
                        UserValidator userValidator = new UserValidator();
                        var checkUser = userValidator.ValidateUser(db, this.CurrentUser);
                        if (!checkUser.Success)
                        {
                            result.Details.AddRange(checkUser.Details);
                        }
                        else
                        {
                            checkUser = userValidator.ValidateIfUserExistInDatabase(db, this.CurrentUser);
                            if (!checkUser.Success)
                            {
                                result.Details.AddRange(checkUser.Details);
                            }
                            else
                            {
                                UserRepository userRepository = new UserRepository();
                                userRepository.SaveUser(db, this.CurrentUser);
                            }
                        }
                    }

                    if (!result.Success)
                    {
                        this.CurrentEmployee.Id = employeeId;
                        db.ClearChanges();
                        return result;
                    }

                    db.SaveChanges();

                    this.CurrentUser.AcceptChanges();
                    this.CurrentEmployee.AcceptChanges();
                }
                catch (Exception ex)
                {
                    //TODO Log
                    this.CurrentEmployee.Id = employeeId;
                    db.ClearChanges();
                    result.Details.Add(new CheckResultDetail(CheckResultDetail.ErrorType.Error, "MessageBox", "Save failed!\n" + ex.Message));
                    return result;
                }
            }


            return result;
        }
Beispiel #5
0
        public CheckResult SaveEmployee()
        {
            CheckResult result = CheckResult.Default;
            using (var db = DbManager.CreateInstance())
            {
                try
                {
                    EmployeeValidator validator = new EmployeeValidator();
                    result = validator.ValidateEmployee(db, this.CurrentEmployee);
                    if (!result.Success)
                    {
                        return result;
                    }

                    EmployeeRepository rep = new EmployeeRepository();
                    rep.SaveEmployee(db, this.CurrentEmployee);
                    db.SaveChanges();
                    this.CurrentEmployee.AcceptChanges();

                    return result;
                }
                catch (Exception ex)
                {
                    db.ClearChanges();
                    result.Details.Add(new CheckResultDetail(CheckResultDetail.ErrorType.Error, "MessageBox", "Save failed!\n" + ex.Message));
                    return result;
                }
            }
        }