Exemplo n.º 1
0
        Task <IEnumerable <EmployeeDto> > IEmployeeRepositoryAdmin.GetAllAsync(EmployeeGridSettings settings)
        {
            Guard.ArgumentIsNotNull(settings, nameof(settings));
            Guard.ArgumentIsNotNull(settings.PagingSettings, nameof(settings.PagingSettings));
            Guard.ArgumentIsNotNull(settings.SortingSettings, nameof(settings.SortingSettings));
            Guard.ArgumentIsNotNull(settings.EmployeeFilter, nameof(settings.EmployeeFilter));

            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("CurrentPage", settings.PagingSettings.CurrentPage);
            parameters.Add("ItemsPerPage", settings.PagingSettings.ItemsPerPage);
            parameters.Add("SortColumnName", settings.SortingSettings.SortColumnName);
            parameters.Add("IsDescending", settings.SortingSettings.IsDescending);

            parameters.Add("SearchKeyword", settings.SearchKeyword ?? string.Empty);
            parameters.Add("CountryFilter", settings.EmployeeFilter.Country ?? string.Empty);
            parameters.Add("CityFilter", settings.EmployeeFilter.City ?? string.Empty);

            if (settings.EmployeeFilter.Status == EmployeeStatus.NotDefined)
            {
                parameters.Add("StatusFilter", string.Empty);
            }
            else
            {
                parameters.Add("StatusFilter", settings.EmployeeFilter.Status);
            }

            return(QueryAsync <EmployeeDto>(StoredProcedures.Employee.GetAllAdmin, parameters));
        }
Exemplo n.º 2
0
        async Task <GrigData <Common.Models.Employee.Employee> > IEmployeeServiceAdmin.GetAllAsync(
            EmployeeGridSettings settings)
        {
            Guard.ArgumentIsNotNull(settings, nameof(settings));

            IEnumerable <EmployeeDto> dtoList = await _employeeRepositoryAdmin.GetAllAsync(settings);

            int totalCount = await _employeeRepositoryAdmin.GetTotalCountAsync(settings);

            IEnumerable <Common.Models.Employee.Employee> result = _mapper.Map <IEnumerable <EmployeeDto>, IEnumerable <Common.Models.Employee.Employee> >(dtoList);

            return(new GrigData <Common.Models.Employee.Employee>
            {
                Data = result,
                TotalCount = totalCount
            });
        }
Exemplo n.º 3
0
        Task <int> IEmployeeRepository.GetTotalCountAsync(EmployeeGridSettings settings)
        {
            Guard.ArgumentIsNotNull(settings, nameof(settings));
            Guard.ArgumentIsNotNull(settings.EmployeeFilter, nameof(settings.EmployeeFilter));

            DynamicParameters parameters = new DynamicParameters();

            parameters.Add("SearchKeyword", settings.SearchKeyword ?? string.Empty);
            parameters.Add("CountryFilter", settings.EmployeeFilter.Country ?? string.Empty);
            parameters.Add("CityFilter", settings.EmployeeFilter.City ?? string.Empty);

            if (settings.EmployeeFilter.Status == EmployeeStatus.NotDefined)
            {
                parameters.Add("StatusFilter", string.Empty);
            }
            else
            {
                parameters.Add("StatusFilter", settings.EmployeeFilter.Status);
            }

            return(QuerySingleOrDefaultAsync <int>(StoredProcedures.Employee.GetTotalCount, parameters));
        }
Exemplo n.º 4
0
        public async void Admin_GetAllAsync_EmptyFilters_AllEmployees()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                EmployeeGridSettings defaultGridSettings = BuildDefaultGridSettings();

                Employee employee1 = BuildMinValidEmployee();
                Employee employee2 = BuildMinValidEmployee();
                Employee employee3 = BuildMinValidEmployee();

                List <Employee> expected =
                    new List <Employee> {
                    employee1, employee2, employee3
                }.OrderBy(x => x.FullName).ToList();

                // Act
                Guid?id1 = await _employeeServiceAdmin.CreateAsync(employee1);

                employee1.EmployeeId = id1.Value;
                Guid?id2 = await _employeeServiceAdmin.CreateAsync(employee2);

                employee2.EmployeeId = id2.Value;
                Guid?id3 = await _employeeServiceAdmin.CreateAsync(employee3);

                employee3.EmployeeId = id3.Value;

                GrigData <Employee> employeesGrigData = await _employeeServiceAdmin.GetAllAsync(defaultGridSettings);

                // Assert
                Assert.AreEqual(3, employeesGrigData.TotalCount);
                Assert.AreEqual(serializer.Serialize(expected),
                                serializer.Serialize(employeesGrigData.Data.ToList()));
            }
        }
Exemplo n.º 5
0
        public async void Admin_GetAllAsync_SearchFiltersByAllFields_SearchedAndFilteredEmployees()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                EmployeeGridSettings defaultGridSettings = new EmployeeGridSettings
                {
                    PagingSettings = new PagingSettings
                    {
                        CurrentPage  = "1",
                        ItemsPerPage = "2"
                    },
                    SortingSettings = new SortingSettings
                    {
                        IsDescending   = false,
                        SortColumnName = "FullName"
                    },
                    EmployeeFilter = new EmployeeFilter
                    {
                        City    = "Kharkiv",
                        Country = "Ukraine",
                        Status  = EmployeeStatus.Hired
                    },
                    SearchKeyword = "employee"
                };

                Employee employee1 = BuildMinValidEmployee();
                employee1.FullName       = "employee 1";
                employee1.OfficeLocation = new OfficeLocation
                {
                    Country = "Ukraine",
                    City    = "Kharkiv"
                };
                employee1.Status = (int)EmployeeStatus.Hired;

                Employee employee2 = BuildMinValidEmployee();
                employee2.FullName       = "1";
                employee2.JobTitle       = "employee";
                employee2.OfficeLocation = new OfficeLocation
                {
                    Country = "Ukraine",
                    City    = "Kharkiv"
                };
                employee2.Status = (int)EmployeeStatus.Hired;

                Employee employee3 = BuildMinValidEmployee();
                employee3.FullName       = "2";
                employee3.JobTitle       = "3";
                employee3.DepartmentName = "employee";
                employee3.OfficeLocation = new OfficeLocation
                {
                    Country = "Ukraine",
                    City    = "Kharkiv"
                };
                employee3.Status = (int)EmployeeStatus.Hired;

                Employee employee4 = BuildMinValidEmployee();
                employee4.FullName       = "2";
                employee4.JobTitle       = "3";
                employee4.DepartmentName = "4";
                employee4.OfficeLocation = new OfficeLocation
                {
                    Country = "Ukraine",
                    City    = "Lviv"
                };
                employee4.Status = (int)EmployeeStatus.Hired;

                Employee employee5 = BuildMinValidEmployee();
                employee5.FullName       = "2";
                employee5.JobTitle       = "3";
                employee5.DepartmentName = "4";
                employee5.OfficeLocation = new OfficeLocation
                {
                    Country = "Ukraine",
                    City    = "Kharkiv"
                };
                employee5.Status = (int)EmployeeStatus.Dismissed;

                List <Employee> expected =
                    new List <Employee> {
                    employee1, employee2, employee3
                }.OrderBy(x => x.FullName).Take(2).ToList();

                // Act
                Guid?id1 = await _employeeServiceAdmin.CreateAsync(employee1);

                employee1.EmployeeId = id1.Value;
                Guid?id2 = await _employeeServiceAdmin.CreateAsync(employee2);

                employee2.EmployeeId = id2.Value;
                Guid?id3 = await _employeeServiceAdmin.CreateAsync(employee3);

                employee3.EmployeeId = id3.Value;
                Guid?id4 = await _employeeServiceAdmin.CreateAsync(employee4);

                employee4.EmployeeId = id4.Value;
                Guid?id5 = await _employeeServiceAdmin.CreateAsync(employee5);

                employee5.EmployeeId = id5.Value;

                GrigData <Employee> employeesGrigData = await _employeeServiceAdmin.GetAllAsync(defaultGridSettings);

                // Assert
                Assert.AreEqual(3, employeesGrigData.TotalCount);
                Assert.AreEqual(2, employeesGrigData.Data.Count());
                Assert.AreEqual(serializer.Serialize(expected),
                                serializer.Serialize(employeesGrigData.Data.ToList()));
            }
        }