Пример #1
0
 public BindingList<ProjectCategoryModel> LoadProjectCategories(SmartCRMEntitiesModel db)
 {
     var pocoCategories = db.ConstProjectCategories;
     var categories = new BindingList<ProjectCategoryModel>();
     MapHelper.Map(pocoCategories, categories);
     return categories;
 }
Пример #2
0
        //TODO
        public CheckResult ValidateEmployee(SmartCRMEntitiesModel context, EmployeeModel model)
        {
            CheckResult result = CheckResult.Default;

            if (string.IsNullOrWhiteSpace(model.FirstName))
            {
                result.Details.Add(new CheckResultDetail(CheckResultDetail.ErrorType.Error, StaticReflection.GetMemberName<EmployeeModel>(x => x.FirstName), "Enter First Name!"));
            }

            if (string.IsNullOrWhiteSpace(model.LastName))
            {
                result.Details.Add(new CheckResultDetail(CheckResultDetail.ErrorType.Error, StaticReflection.GetMemberName<EmployeeModel>(x => x.LastName), "Enter Last Name!"));
            }

            //if (model.Username.Length < MinimumUsernameLength)
            //{
            //    result.Details.Add(new CheckResultDetail(CheckResultDetail.ErrorType.Error, StaticReflection.GetMemberName<UserModel>(x => x.Username), "Minimum required length of the Username is 3 symbols!"));
            //}

            //if (model.Password.Length < MinimumPasswordLength)
            //{
            //    result.Details.Add(new CheckResultDetail(CheckResultDetail.ErrorType.Error, StaticReflection.GetMemberName<UserModel>(x => x.Password), "Minimum required length of the Password is 6 symbols!"));
            //}

            return result;
        }
Пример #3
0
        public BindingList<ProjectModel> LoadProjects(SmartCRMEntitiesModel db)
        {
            List<Project> pocoProjects = db.Projects.ToList();
            var projects = new BindingList<ProjectModel>();
            foreach (var poco in pocoProjects)
            {
                ProjectModel model = ProjectModel.Create();
                MapHelper.Map(poco, model);
                foreach (var emp in poco.Employees)
                {
                    EmployeeModel empModel = EmployeeModel.Create();
                    //MapHelper.Map(emp, empModel);
                    //empModel.AcceptChanges();
                    empModel.FirstName = emp.FirstName;
                    empModel.SecondName = emp.SecondName;
                    empModel.LastName = emp.LastName;
                    model.Employees.Add(empModel);
                }
                model.AcceptChanges();
                projects.Add(model);

            }

            return projects;
        }
Пример #4
0
 private void InsertAccount(SmartCRMEntitiesModel db, UserModel userModel, EmployeeModel employeeModel)
 {
     User pocoUser = new User();
     MapHelper.Map(userModel, pocoUser);
     Employee pocoEmployee = new Employee();
     MapHelper.Map(employeeModel, pocoEmployee);
     pocoUser.Employee = pocoEmployee;
     db.Add(pocoUser);
 }
Пример #5
0
        private void InsertEmployee(SmartCRMEntitiesModel db, EmployeeModel employeeModel)
        {
            Employee pocoEmployee = new Employee();
            MapHelper.Map(employeeModel, pocoEmployee);

            db.Add(pocoEmployee);
            db.FlushChanges();
            employeeModel.Id = pocoEmployee.Id;
        }
Пример #6
0
        private void UpdateEmployee(SmartCRMEntitiesModel db, EmployeeModel employeeModel)
        {
            var pocoEmployee = db.Employees.FirstOrDefault(x => x.Id.Equals(employeeModel.Id));
            if (pocoEmployee == null)
            {
                throw new NullReferenceException("Missing employee!");
            }

            MapHelper.Map(employeeModel, pocoEmployee);
        }
Пример #7
0
 private static void CheckIfExistUser(UserModel model, SmartCRMEntitiesModel db, CheckResult result)
 {
     UserRepository repository = new UserRepository();
     var user = repository.GetUserByModel(db, model);
     if (user == null)
     {
         result.Details.Add(
             new CheckResultDetail(CheckResultDetail.ErrorType.Error, "NoUser", "The username or password is incorect!"));
     }
 }
Пример #8
0
        public CheckResult ValidateIfUserExistInDatabase(SmartCRMEntitiesModel context, UserModel model)
        {
            CheckResult result = CheckResult.Default;
            var userInDb = context.Users.FirstOrDefault(user => user.Username == model.Username && user.UserId != model.UserId);
            if (userInDb != null)
            {
                result.Details.Add(new CheckResultDetail(CheckResultDetail.ErrorType.Error, StaticReflection.GetMemberName<UserModel>(x => x.Username), "This username already exist! Please select another one."));
            }

            return result;
        }
Пример #9
0
        private void UpdateAccount(SmartCRMEntitiesModel db, UserModel userModel, EmployeeModel employeeModel)
        {
            var pocoUser = db.Users.FirstOrDefault(x => x.UserId.Equals(userModel.UserId));
            if (pocoUser == null)
            {
                throw new NullReferenceException("Missing user!");
            }

            MapHelper.Map(userModel, pocoUser);
            MapHelper.Map(employeeModel, pocoUser.Employee);
        }
Пример #10
0
 public void SaveAccount(SmartCRMEntitiesModel db, UserModel userModel, EmployeeModel employeeModel)
 {
     if (userModel.IsNew)
     {
         this.InsertAccount(db, userModel, employeeModel);
     }
     else
     {
         this.UpdateAccount(db, userModel, employeeModel);
     }
 }
Пример #11
0
 public void SaveEmployee(SmartCRMEntitiesModel db, EmployeeModel employeeModel)
 {
     if (employeeModel.Id == 0)
     {
         this.InsertEmployee(db, employeeModel);
     }
     else
     {
         this.UpdateEmployee(db, employeeModel);
     }
 }
Пример #12
0
        public EmployeeModel GetEmployeeById(SmartCRMEntitiesModel db, uint employeeId)
        {
            Employee employee = db.Employees.FirstOrDefault(x => x.Id == employeeId);
            if (employee == null)
            {
                return null;
            }

            EmployeeModel model = EmployeeModel.Create();
            MapHelper.Map(employee, model);
            return model;
        }
Пример #13
0
        public UserModel GetUserByModel(SmartCRMEntitiesModel db, UserModel model)
        {
            User user = db.Users.FirstOrDefault(x => x.Username == model.Username && x.Password == model.Password && x.IsEnabled);

            if (user != null)
            {
                UserModel userModel = UserModel.Create();
                MapHelper.Map(user, userModel);
                return userModel;
            }

            return null;
        }
Пример #14
0
        public CheckResult ValidateCreateEditUser(UserModel model, SmartCRMEntitiesModel context)
        {
            CheckResult result = CheckResult.Default;

            if (model.Username.Length < 3)
            {
                result.Details.Add(new CheckResultDetail(CheckResultDetail.ErrorType.Error, "Username", "The username must be at least 3 symbols!"));
            }

            CheckIfExistUser(model, context, result);

            return result;
        }
Пример #15
0
        public BindingList<UserModel> LoadAllUsers(SmartCRMEntitiesModel db, bool isActive)
        {
            List<User> pocoUsers;
            if (isActive)
            {
                pocoUsers = db.Users.Where(x => x.IsEnabled).ToList();
            }
            else
            {
                pocoUsers = db.Users.ToList();
            }

            var modelUsers = new BindingList<UserModel>();
            foreach (var poco in pocoUsers)
            {
                UserModel model = UserModel.Create();
                MapHelper.Map(poco, model);
                model.AcceptChanges();
                modelUsers.Add(model);
            }

            return modelUsers;
        }
Пример #16
0
        public CheckResult ValidateLogin(UserModel model, SmartCRMEntitiesModel context)
        {
            CheckResult result = CheckResult.Default;

            if (string.IsNullOrWhiteSpace(model.Username))
            {
                result.Details.Add(new CheckResultDetail(CheckResultDetail.ErrorType.Error, StaticReflection.GetMemberName<UserModel>(x => x.Username), "Enter username!"));
            }

            if (string.IsNullOrWhiteSpace(model.Password))
            {
                result.Details.Add(new CheckResultDetail(CheckResultDetail.ErrorType.Error, StaticReflection.GetMemberName<UserModel>(x => x.Password), "Enter password!"));
            }

            if (!result.Success)
            {
                return result;
            }

            CheckIfExistUser(model, context, result);

            return result;
        }
Пример #17
0
        public BindingList<EmployeeModel> LoadAllEmployees(SmartCRMEntitiesModel db, bool isActive)
        {
            List<Employee> pocoEmployees;
            if (isActive)
            {
                pocoEmployees = db.Employees.Where(x => !x.IsDeleted).ToList();
            }
            else
            {
                pocoEmployees = db.Employees.ToList();
            }

            var modelEmployees = new BindingList<EmployeeModel>();
            foreach (var poco in pocoEmployees)
            {
                EmployeeModel model = EmployeeModel.Create();
                MapHelper.Map(poco, model);
                model.AcceptChanges();
                modelEmployees.Add(model);
            }

            return modelEmployees;
        }
Пример #18
0
        public void DeleteUser(SmartCRMEntitiesModel db, UserModel userModel)
        {
            User pocoUser = db.Users.FirstOrDefault(x => x.UserId == userModel.UserId);
            if (pocoUser == null)
            {
                throw new NullReferenceException("Missing user in database!");
            }

            db.Delete(pocoUser);
        }
Пример #19
0
        public void DeleteEmployee(SmartCRMEntitiesModel db, EmployeeModel employeeModel)
        {
            Employee pocoEmployee = db.Employees.FirstOrDefault(x => x.Id == employeeModel.Id);
            if (pocoEmployee == null)
            {
                throw new NullReferenceException("Missing employee in database!");
            }

            db.Delete(pocoEmployee);
        }
Пример #20
0
 public void SaveUser(SmartCRMEntitiesModel db, UserModel userModel)
 {
     if (userModel.UserId == 0)
     {
         this.InsertUser(db, userModel);
     }
     else
     {
         this.UpdateUser(db, userModel);
     }
 }
Пример #21
0
 private void InsertUser(SmartCRMEntitiesModel db, UserModel userModel)
 {
     User pocoUser = new User();
     Mapper.Map(userModel, pocoUser);
     db.Add(pocoUser);
 }
Пример #22
0
        public UserModel GetUserByEmployeeId(SmartCRMEntitiesModel db, uint employeeId)
        {
            User pocoUser = db.Users.FirstOrDefault(x => x.EmployeeId == employeeId);
            if (pocoUser == null)
            {
                return null;
            }

            UserModel model = UserModel.Create();
            Mapper.Map(pocoUser, model);
            return model;
        }