コード例 #1
0
        public virtual void SetUp()
        {
            var options = new DbContextOptionsBuilder <EmployeeDetailsContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            context = new EmployeeDetailsContext(options);
            uow     = new EmployeeUnitOfWork(context);
            logger  = new Mock <ILogger <EmployeeController> >();
            mockUow = new Mock <IEmployeeUnitOfWork>();
            mockUow.Setup(m => m.EmployeeRepository).Returns(uow.EmployeeRepository);
            mockUow.Setup(m => m.TypeDiscountRulesRepository).Returns(uow.TypeDiscountRulesRepository);
            mockUow.Setup(m => m.TypePayrollDetailsRepository).Returns(uow.TypePayrollDetailsRepository);
            sut = new EmployeeController(logger.Object, mockUow.Object);

            uow.TypeDiscountRulesRepository.Add(new TypeDiscountRules()
            {
                discount_type_id = 1,
                discount_rule    = "A",
                discount         = 0.1M
            });
            uow.TypePayrollDetailsRepository.Add(new TypePayrollDetails()
            {
                payroll_type_id             = 1,
                yearly_paychecks            = 20,
                salary_per_paycheck         = 1000,
                employee_yearly_deductions  = 500,
                dependent_yearly_deductions = 200
            });
            uow.Save();
        }
コード例 #2
0
        /// <summary>
        /// Provides functionality for registering, authenticating, updating user and role management.
        /// </summary>
        public AccountService(IdentityUnitOfWork identityUnitOfWork, EmployeeUnitOfWork employeeUnitOfWork)
        {
            if (identityUnitOfWork == null)
            {
                throw new ArgumentNullException(nameof(identityUnitOfWork));
            }

            if (employeeUnitOfWork == null)
            {
                throw new ArgumentNullException(nameof(employeeUnitOfWork));
            }

            this.identityUnitOfWork = identityUnitOfWork;
            this.employeeUnitOfWork = employeeUnitOfWork;
        }
コード例 #3
0
 public void TestInit()
 {
     _employee = new Employee()
     {
         DateCreated = DateTime.Now,
         FirstName   = "Mitra",
         LastName    = "Ghorpade"
     };
     _options = new DbContextOptionsBuilder <EmployeeContext>()
                .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                .Options;
     _context      = new EmployeeContext(_options);
     _myUnitOfWork = new EmployeeUnitOfWork(_context);
     _myRepo       = new GenericRepository <Employee>(_context);
     _service      = new EmployeeRecordsService(_myRepo, _myUnitOfWork);
 }
コード例 #4
0
        /// <summary>
        /// Provides functionality to list employees, find employees by search criteria, update employee related data.
        /// </summary>
        public EmployeeService(DomainUnitOfWork domain, EmployeeUnitOfWork employee, IdentityUnitOfWork identity)
        {
            if (domain == null)
            {
                throw new ArgumentNullException(nameof(domain));
            }

            if (employee == null)
            {
                throw new ArgumentNullException(nameof(employee));
            }

            if (identity == null)
            {
                throw new ArgumentNullException(nameof(identity));
            }

            domainUnitOfWork   = domain;
            employeeUnitOfWork = employee;
            identityUnitOfWork = identity;
        }
コード例 #5
0
 public EmployeeInfoBusinessRule()
 {
     UnitOfWork = new EmployeeUnitOfWork();
 }
コード例 #6
0
        public async Task <HttpResponseMessage> GetEmployeeInfos(RequestFilterEmployee parameters)
        {
            if (parameters == null)
            {
                CreateResponse(ResultCode.ValidationError);
            }
            try
            {
                List <EmployeeInfoVM> result = null;
                int totalCount = 0;
                int _take      = DefaultValues.Take;
                int _skip      = DefaultValues.Skip;

                if (parameters.Take.HasValue)
                {
                    _take = (int)parameters.Take;
                }
                if (parameters.Skip.HasValue)
                {
                    _skip = (int)parameters.Skip;
                }

                using (var uow = new EmployeeUnitOfWork())
                {
                    var employeeQuery = uow.Repository <EmployeeInfo>().Queryable();

                    if (parameters.Filters != null)
                    {
                        if (!string.IsNullOrWhiteSpace(parameters.Filters.PersonalCode))
                        {
                            employeeQuery = employeeQuery.Where(e => e.PersonalCode.StartsWith(parameters.Filters.PersonalCode));
                        }

                        if (!string.IsNullOrWhiteSpace(parameters.Filters.FirstName))
                        {
                            employeeQuery = employeeQuery.Where(e => e.FirstName.StartsWith(parameters.Filters.FirstName.ToLower()));
                        }

                        if (!string.IsNullOrWhiteSpace(parameters.Filters.LastName))
                        {
                            employeeQuery = employeeQuery.Where(e => e.LastName.StartsWith(parameters.Filters.LastName.ToLower()));
                        }

                        if (!string.IsNullOrWhiteSpace(parameters.Filters.Email))
                        {
                            employeeQuery = employeeQuery.Where(e => e.Email.StartsWith(parameters.Filters.Email.ToLower()));
                        }

                        if (!string.IsNullOrWhiteSpace(parameters.Filters.PhoneNumber))
                        {
                            employeeQuery = employeeQuery.Where(e => e.PhoneNumber.StartsWith(parameters.Filters.PhoneNumber));
                        }

                        if (!string.IsNullOrWhiteSpace(parameters.Filters.City))
                        {
                            employeeQuery = employeeQuery.Where(e => e.City.ToLower().StartsWith(parameters.Filters.City.ToLower()));
                        }

                        if (!string.IsNullOrWhiteSpace(parameters.Filters.Company))
                        {
                            employeeQuery = employeeQuery.Where(e => e.Company.StartsWith(parameters.Filters.Company.ToLower()));
                        }
                    }
                    totalCount = await employeeQuery.CountAsync();

                    var employees = await employeeQuery.OrderBy(e => e.ID).Skip(_skip).Take(_take).ToListAsync();

                    result = employees.Select(e => new EmployeeInfoVM
                    {
                        ID           = e.ID,
                        PersonalCode = e.PersonalCode,
                        FirstName    = e.FirstName,
                        LastName     = e.LastName,
                        Email        = e.Email,
                        PhoneNumber  = e.PhoneNumber,
                        City         = e.City,
                        Company      = e.Company,
                        IsDeleted    = e.IsDeleted,
                    }).ToList();
                }
                return(Success(new ResponseEmployeeList
                {
                    Data = result,
                    Skip = _skip,
                    Take = _take,
                    TotalCount = totalCount,
                    Count = result != null ? result.Count : 0,
                }));
            }
            catch (Exception ex)
            {
                return(await HandleExceptionAsync(ex));
            }
        }