public async Task <EmployeeModel> GetByEmployeeIdWithDetailAsync(string employeeId)
        {
            var spec      = new EmployeeSpecification(x => x.EmployeeId == employeeId);
            var employees = await _employeeRepository.GetSingleAsync(spec);

            return(_mapper.Map <Employee, EmployeeModel>(employees));
        }
        public async Task AddAsync_WhenAddOneEmployee_ThenTotalCountShouldBeOne()
        {
            // Arrange
            var employee = _fixture.Create <Employee>();
            var spec     = new EmployeeSpecification();

            // Act
            await _repository.AddAsync(employee);

            var result = await _repository.GetBySpecificationAsync(spec);

            // Assert
            result.Should().HaveCount(1);
        }
        public async Task AddAsync_WhenAddOneEmployee_ThenGottenEmployeEqualAdded()
        {
            // Arrange
            var employee = _fixture.Create <Employee>();
            var spec     = new EmployeeSpecification();

            // Act
            await _repository.AddAsync(employee);

            var result = await _repository.GetBySpecificationAsync(spec);

            // Assert
            result.First().Should().BeEquivalentTo(employee, options =>
                                                   options.Excluding(o => o.Id));
        }
Example #4
0
 public Employee[] GetEmployees(EmployeeSpecification spec)
 {
     using (ISession session = DataContext.GetTransactedSession())
     {
         ICriteria criteria = session.CreateCriteria(typeof(Employee));
         criteria.SetCacheable(true);
         if (spec.CanFulfill)
         {
             criteria.CreateAlias("Roles", "role");
             criteria.SetFetchMode("Roles", FetchMode.Select);
         }
         IList <Employee> list      = criteria.List <Employee>();
         Employee[]       employees = new List <Employee>(list).ToArray();
         Array.Sort(employees);
         return(employees);
     }
 }
        // GET: Employee
        public ActionResult Index(Guid?roleId = null)
        {
            var criteria = new EmployeeCriteria {
                RoleId = roleId ?? Guid.Empty
            };
            var specification = new EmployeeSpecification(criteria);
            var employees     = _employeeReposiory.Find(specification);

            List <EmployeeVM> listofEmployeeVM = new List <EmployeeVM>();

            foreach (var employee in employees)
            {
                listofEmployeeVM.Add(EmployeeVM.GetDTO(employee));
            }

            return(View(listofEmployeeVM));
        }
        public async Task <List <EmployeeModel> > GetAsync(EmployeeFilter filter)
        {
            var spec = new EmployeeSpecification(x => (!filter.DepartmentId.HasValue || x.EmployeeState.JobFunction.Section.DepartmentId == filter.DepartmentId) &&
                                                 (string.IsNullOrEmpty(filter.EmployeeName) || (x.FirstName.Contains(filter.EmployeeName) || x.FirstNameThai.Contains(filter.EmployeeName))) &&
                                                 (string.IsNullOrEmpty(filter.EmployeeId) || x.EmployeeId == filter.EmployeeId) &&
                                                 (string.IsNullOrEmpty(filter.EmployeeGroup) || x.EmployeeType == filter.EmployeeGroup) &&
                                                 (!filter.SectionId.HasValue || x.EmployeeState.JobFunction.SectionId == filter.SectionId) &&
                                                 (!filter.FunctionId.HasValue || x.EmployeeState.JobFunctionId == filter.FunctionId) &&
                                                 (!filter.ShiftId.HasValue || x.EmployeeState.ShiftId == filter.ShiftId) &&
                                                 (!filter.LevelId.HasValue || x.EmployeeState.LevelId == filter.LevelId) &&
                                                 (!filter.PositionId.HasValue || x.EmployeeState.PositionId == filter.PositionId) &&
                                                 (!filter.AvailableFlag.HasValue || x.AvailableFlag == filter.AvailableFlag));

            var employees = await _employeeRepository.GetAsync(spec);

            return(_mapper.Map <List <Employee>, List <EmployeeModel> >(employees));
        }
        public async Task UpdateAsync_WhenUpdateSalarySum_ThenSalarySumIsUpdated()
        {
            // Arrange
            var spec     = new EmployeeSpecification();
            var employee = _fixture.Create <Employee>();
            await _repository.AddAsync(employee);

            // Act
            employee.SalarySum = 50000;
            await _repository.UpdateAsync(employee);

            var result = await _repository.GetBySpecificationAsync(spec);

            // Assert
            result.First().Should().BeEquivalentTo(employee, options =>
                                                   options.Excluding(o => o.Id));
        }
        public async Task DeleteAsync_WhenAddandDeleteEmployee_ThenTotalCountShouldBeZero()
        {
            // Arrange
            var employee = _fixture.Create <Employee>();
            var spec     = new EmployeeSpecification();

            // Act
            await _repository.AddAsync(employee);

            var result = await _repository.GetBySpecificationAsync(spec);

            await _repository.DeleteAsync(result.First());

            result = await _repository.GetBySpecificationAsync(spec);

            // Assert
            result.Should().HaveCount(0);
        }
Example #9
0
        public static IEnumerable <SelectListItem> GetOptions(string selected)
        {
            var result = new List <SelectListItem>();

            var empSpec = new EmployeeSpecification();

            foreach (Employee employee in _repository.GetEmployees(empSpec))
            {
                result.Add(new SelectListItem
                {
                    Text     = employee.GetFullName(),
                    Value    = employee.UserName,
                    Selected = (employee.UserName == selected)
                });
            }
            _repository.GetEmployees(empSpec);

            return(result);
        }
Example #10
0
        public ActionResult Login(LoginVM loginVM)
        {
            if (ModelState.IsValid)
            {
                var employeeCriteria = new EmployeeCriteria {
                    EmailId = loginVM.Username, Password = loginVM.Password
                };
                var employeeSpecification = new EmployeeSpecification(employeeCriteria);
                var employee = _employeeRepository.Find(employeeSpecification).FirstOrDefault();

                if (employee == null)
                {
                    ModelState.AddModelError("", "Invalid Username and Password");
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(loginVM.Username, loginVM.RememberMe);
                    if (loginVM.RememberMe)
                    {
                        Response.Cookies["Username"].Value   = loginVM.Username;
                        Response.Cookies["Password"].Value   = loginVM.Password;
                        Response.Cookies["Username"].Expires = DateTime.UtcNow.AddMonths(12);
                        Response.Cookies["Password"].Expires = DateTime.UtcNow.AddMonths(12);
                    }
                    else
                    {
                        Response.Cookies["Username"].Expires = DateTime.UtcNow.AddMinutes(-1);
                        Response.Cookies["Password"].Expires = DateTime.UtcNow.AddMinutes(-1);
                    }

                    var criteria = new MenuRoleMapCriteria {
                        RoleId = employee.Role.Id, IsActive = true
                    };
                    var specification = new MenuRoleMapSpecification(criteria);
                    var menus         = _menuRoleMapRepository.Find(specification).OrderBy(x => x.Menu.Order).ToList();

                    List <MenuVM> listOfMenu = new List <MenuVM>();

                    foreach (var menu in menus)
                    {
                        if (menu.Menu.IsParent)
                        {
                            var submenus = menus.Where(x => x.Menu.MainMenu != null && x.Menu.MainMenu.Id.Equals(menu.Menu.Id)).Select(x => x.Menu).ToList();
                            if (submenus.Count() != 0)
                            {
                                var mainMenuVM = MenuVM.GetDTO(menu.Menu);
                                foreach (var submenu in submenus)
                                {
                                    mainMenuVM.SubMenuList.Add(MenuVM.GetDTO(submenu));
                                }
                                listOfMenu.Add(mainMenuVM);
                            }
                        }
                        else if (!menu.Menu.IsParent && menu.Menu.MainMenu == null)
                        {
                            listOfMenu.Add(MenuVM.GetDTO(menu.Menu));
                        }
                        else
                        {
                            continue;
                        }
                    }
                    Session["MenuMaster"] = listOfMenu;
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(loginVM));
        }