Exemple #1
0
        public async Task SortByNumberAsync()
        {
            await _employeeRepository.AddAsync(new List <Employee> {
                EmployeeGenerator.Generate(age: 19),
                EmployeeGenerator.Generate(age: 9),
                EmployeeGenerator.Generate(age: 119),
                EmployeeGenerator.Generate(age: 20)
            }, o => o.ImmediateConsistency());

            var searchRepository = (ISearchableReadOnlyRepository <Employee>)_employeeRepository;
            var results          = await searchRepository.FindAsync(q => q.SortExpression("age"));

            var employees = results.Documents.ToArray();

            Assert.Equal(4, employees.Length);
            Assert.Equal(9, employees[0].Age);
            Assert.Equal(19, employees[1].Age);
            Assert.Equal(20, employees[2].Age);
            Assert.Equal(119, employees[3].Age);

            results = await searchRepository.FindAsync(q => q.SortExpression("-age"));

            employees = results.Documents.ToArray();
            Assert.Equal(4, employees.Length);
            Assert.Equal(119, employees[0].Age);
            Assert.Equal(20, employees[1].Age);
            Assert.Equal(19, employees[2].Age);
            Assert.Equal(9, employees[3].Age);
        }
        public async Task <Employee> CreateAsync(string name)
        {
            var employee = new Employee {
                Name = name
            };

            await employeeRepository.AddAsync(employee);

            await dataContext.SaveChangesAsync();

            return(employee);
        }
Exemple #3
0
        public async Task AddEmployeeAsync(EmployeeDto employeeDto)
        {
            var employee = new Employee(employeeDto.Id, employeeDto.NIP, employeeDto.FirstName, employeeDto.LastName,
                                        employeeDto.BirthDate, employeeDto.Position, employeeDto.Salary);

            await _employeeRepository.AddAsync(employee);
        }
Exemple #4
0
        public async Task <CreateEmployeeCommandResponse> Handle(CreateEmployeeCommand request, CancellationToken cancellationToken)
        {
            var createEmployeeCommandResponse = new CreateEmployeeCommandResponse();

            var validator        = new CreateEmployeeCommandValidator(_employeeRepository);
            var validationResult = await validator.ValidateAsync(request);

            if (validationResult.Errors.Count > 0)
            {
                createEmployeeCommandResponse.Success          = false;
                createEmployeeCommandResponse.ValidationErrors = new List <string>();
                foreach (var error in validationResult.Errors)
                {
                    createEmployeeCommandResponse.ValidationErrors.Add(error.ErrorMessage);
                }
            }
            if (createEmployeeCommandResponse.Success)
            {
                var employee = _mapper.Map <Employee>(request);
                employee = await _employeeRepository.AddAsync(employee);

                createEmployeeCommandResponse.Employee = _mapper.Map <CreateEmployeeDto>(employee);
            }

            return(createEmployeeCommandResponse);
        }
Exemple #5
0
        public async Task <EmployeeResponse> SaveAsync(Employee employee)
        {
            try
            {
                /*
                 * Notice here we have to check if the activity ID is valid before adding the employee, to avoid errors.
                 * You can create a method into the ActivityService class to return the activity and inject the service here if you prefer, but
                 * it doesn't matter given the API scope.
                 */
                var existingActivity = await _activityRepository.FindByIdAsync(employee.ActivityId);

                if (existingActivity == null)
                {
                    return(new EmployeeResponse("Invalid activity."));
                }

                await _employeeRepository.AddAsync(employee);

                return(new EmployeeResponse(employee));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new EmployeeResponse($"An error occurred when saving the employee: {ex.Message}"));
            }
        }
        public async Task <Unit> Handle(AddEmployeeCommand request, CancellationToken cancellationToken)
        {
            var employee = new Employee(request.FirstName, request.LastName, request.Salary);
            await _employeeRepository.AddAsync(employee);

            return(Unit.Value);
        }
        public async Task <ActionResult <EmployeeDto> > AddForDepartment
            (int departmentId, EmployeeAddOrUpdateDto employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var employeeEntity = new Employee
            {
                DepartmentId = departmentId,
                Name         = employee.Name,
                BirthDate    = employee.BirthDate,
                Gender       = employee.Gender,
                No           = employee.No,
                PictureUrl   = employee.PictureUrl
            };
            var x = await _employeeRepository.AddAsync(employeeEntity);

            var dto = new EmployeeDto
            {
                Id           = x.Id,
                DepartmentId = x.DepartmentId,
                Name         = x.Name,
                BirthDate    = x.BirthDate,
                Gender       = x.Gender,
                No           = x.No,
                PictureUrl   = x.PictureUrl
            };

            return(dto);
        }
Exemple #8
0
        public async Task <Employee> AddAsync(Employee entity)
        {
            var createdEntity = await _EmployeeRepository.AddAsync(entity);

            //  await _BaseRepository.Sav();
            return(createdEntity);
        }
Exemple #9
0
        public async Task <IActionResult> Create(EmployeeCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var employee = new Employee()
                {
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    Phone       = model.Phone,
                    Email       = model.Email,
                    Position    = model.Position,
                    JobType     = model.JobType,
                    Unit        = model.Unit,
                    Street      = model.Street,
                    Town        = model.Town,
                    StateCode   = model.StateCode,
                    Postcode    = model.Postcode,
                    DateCreated = DateTime.Now
                };

                await repository.AddAsync(employee);

                await unitOfWork.CompleteAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
Exemple #10
0
        public async Task <EmployeeResponse> SaveAsync(Employee employee)
        {
            try
            {
                foreach (var assignment in employee.EmployeeAssignments)
                {
                    var existingAssignment = await _employeeAssignmentRepository.FindByIdAsync(assignment.Id);

                    if (existingAssignment == null)
                    {
                        return(new EmployeeResponse("Invalid EmployeeAssignment"));
                    }
                }

                await _employeeRepository.AddAsync(employee);

                await _unitOfWork.CompleteAsync();

                return(new EmployeeResponse(employee));
            }
            catch (Exception ex)
            {
                return(new EmployeeResponse($"An error occurred when saving the employee: {ex.Message}"));
            }
        }
Exemple #11
0
        public async Task <EmployeeViewModel> AddEmployeeAsync(EmployeeViewModel newEmployeeViewModel, CancellationToken ct = default(CancellationToken))
        {
            var employee = new Employee
            {
                LastName   = newEmployeeViewModel.LastName,
                FirstName  = newEmployeeViewModel.FirstName,
                Title      = newEmployeeViewModel.Title,
                ReportsTo  = newEmployeeViewModel.ReportsTo,
                BirthDate  = newEmployeeViewModel.BirthDate,
                HireDate   = newEmployeeViewModel.HireDate,
                Address    = newEmployeeViewModel.Address,
                City       = newEmployeeViewModel.City,
                State      = newEmployeeViewModel.State,
                Country    = newEmployeeViewModel.Country,
                PostalCode = newEmployeeViewModel.PostalCode,
                Phone      = newEmployeeViewModel.Phone,
                Fax        = newEmployeeViewModel.Fax,
                Email      = newEmployeeViewModel.Email
            };

            employee = await _employeeRepository.AddAsync(employee, ct);

            newEmployeeViewModel.EmployeeId = employee.EmployeeId;
            return(newEmployeeViewModel);
        }
Exemple #12
0
        public async Task CanAdd()
        {
            var employee = new Employee
            {
                EmployeeId   = 999,
                FirstName    = "Test",
                LastName     = "Tester",
                BirthDate    = new DateTime(2001, 12, 16),
                CompanyId    = 1,
                DepartmentId = 1,
                Created      = DateTime.UtcNow,
                Modified     = DateTime.UtcNow
            };
            var newEmployee = await _employeeRepository.AddAsync(employee).ConfigureAwait(false);

            Assert.Equal("Tester", newEmployee.LastName);
        }
Exemple #13
0
        public async Task <int> Handle(CreateEmployeeCommand request, CancellationToken cancellationToken)
        {
            var employee = _mapper.Map <Employee>(request);

            employee = await _employeeRepositoy.AddAsync(employee);

            return(employee.Id);
        }
Exemple #14
0
        private async Task CreatedEmployeeIntoDataAsync(Domain.Entities.People entity)
        {
            int peopleId = await GetPeopleIdByDocumentAsync(entity.Document);

            if (peopleId > 0)
            {
                await _employeeRepository.AddAsync(entity.Employee.MapToDto(peopleId));
            }
        }
        public async Task <CreateEmployeeViewModel> CreateAsync(CreateEmployeeViewModel model)
        {
            var employee = mapper.Map(model);

            await employeeRepository.AddAsync(employee);

            await dataContext.SaveChangeAsync();

            return(model);
        }
Exemple #16
0
        public async Task <IActionResult> CreatePOST()
        {
            if (ModelState.IsValid)
            {
                await _empRepo.AddAsync(Employee); // from binding property (not put at parameter)

                return(RedirectToAction(nameof(Index)));
            }
            return(View(Employee));
        }
Exemple #17
0
        public async Task <ActionResult> Post([FromBody] Employee value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var item = await _employeeService.AddAsync(value);

            return(CreatedAtAction("Get", new { id = item.Id }, item));
        }
Exemple #18
0
        public async Task <IActionResult> CreatePOST()
        {
            if (ModelState.IsValid)
            {
                await _empRepo.AddAsync(Employee);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(Employee));
        }
Exemple #19
0
        public async Task <Employee> AddAsync(Employee employee)
        {
            employee.Salary = GetDefaultSalary(employee);
            SetDiscounts(employee);

            var domain = _mapper.Map <Domain.Models.Employee>(employee);

            var result = await _employeeRepository.AddAsync(domain);

            return(_mapper.Map <Employee>(result));
        }
Exemple #20
0
        public async Task <ActionResult> AddEmployeeAsync(int id, Employee employee)
        {
            if (!ModelState.IsValid || !id.Equals(employee.Id))
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            await _employeeRepo.AddAsync(employee);

            return(CreatedAtAction(nameof(GetEmployeeByIdAsync), new { id }, employee));
        }
 public async Task<SaveEmployeeResponse> SaveAsync(Employee employee)
 {
   try
   {
     await _employeeRepository.AddAsync(employee);
     return new SaveEmployeeResponse(employee);
   }
   catch (Exception ex)
   {
     return new SaveEmployeeResponse($"An error occurred when saving the category: {ex.Message}");
   }
 }
        public async Task <Employee> CreateEmployeeAsync(Employee employee)
        {
            var emp = await _employeeRepository.FindFirstAsync(x => x.Email == employee.Email);

            if (emp != null)
            {
                throw new OperationCanceledException();
            }
            var addedEmployee = await _employeeRepository.AddAsync(employee);

            return(addedEmployee);
        }
 public async Task <HttpResponseMessage> AddAsync([FromBody] EmployeeDTO employee)
 {
     if (!ModelState.IsValid)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
     }
     return(Request.CreateResponse(HttpStatusCode.OK, new
     {
         Sccessful = true,
         Result = await _repository.AddAsync(_mapper.MapToEntity(employee))
     }));
 }
        public async Task Register(string employeeNumber, string password)
        {
            var user = await _employeeRepository.GetAsync(employeeNumber);

            if (user != null)
            {
                throw new Exception($"User with login: '******' already exists");
            }

            user = new Employee();
            user.AddNewEmployee(employeeNumber, password);
            await _employeeRepository.AddAsync(user);
        }
Exemple #25
0
        public async Task <ActionResult <Employee> > PostEmployee([FromForm] Employee employee)
        {
            await _employee.AddAsync(employee);

            try
            {
                await _employee.CommitAsync();
            }
            catch (Exception)
            {
                return(BadRequest(new { errors = "При добавлении произошла ошибка" }));
            }
            return(StatusCode(201, new { message = "Сотрудник добавлен" }));
        }
Exemple #26
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            // Set iniital current workload to 0
            Employee.CurrentWorkload = 0;

            Employee = await _employeeRepository.AddAsync(Employee);

            return(RedirectToPage("../Manager/menuManager"));
        }
        public async Task <IActionResult> Create(Employee employee)
        {
            if (employee == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                Employee newEmployee = await _employeeRepository.AddAsync(employee);

                return(RedirectToAction("details", new { id = newEmployee.Id }));
            }
            return(View());
        }
Exemple #28
0
        public async Task <IActionResult> CreateAsync([FromBody] Employee employee)
        {
            Logger.LogDebug("CreateAsync");
            if (employee == null)
            {
                return(BadRequest(new BadRequestError("The employee is null")));
            }
            await EmployeeRepository.AddAsync(employee);

            return(CreatedAtRoute("GetEmployeeById", new
            {
                Controller = "Employees",
                id = employee.EmployeeId
            }, employee));
        }
Exemple #29
0
        public async Task <EmployeeResponse> SaveAsync(Employee employee)
        {
            try
            {
                await _employeeRepository.AddAsync(employee);

                await _unitOfWork.CompleteAsync();

                return(new EmployeeResponse(employee));
            }
            catch (Exception ex)
            {
                return(new EmployeeResponse($"An error occurred when saving the employee: {ex.Message}"));
            }
        }
Exemple #30
0
        public async Task <SaveEmployeeResponse> SaveAsync(Employee employee)
        {
            try
            {
                await _employeeRepository.AddAsync(employee);

                //await _unitOfWork.CompleteAsync();

                return(new SaveEmployeeResponse(employee));
            }
            catch (Exception ex)
            {
                // log
                return(new SaveEmployeeResponse($"Ërror ocurred when saving category: {ex.Message}"));
            }
        }