public async Task Should_Not_Create_New_Employee_Without_FirstName()
 {
     await Assert.ThrowsAsync <AbpValidationException>(async() =>
     {
         var fakeEmployee       = getFakeCreateEmployeeInput();
         fakeEmployee.FirstName = null;
         await _employeeAppService.Create(fakeEmployee);
     });
 }
        public ActionResult Create(EmployeeCreateModel employeeCreateModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(employeeCreateModel));
            }
            var dto = mapper.Map <CreateEmployeeDTO>(employeeCreateModel);

            dto.UserName = User.Identity.Name;
            employeeAppService.Create(dto);
            return(RedirectToAction(ControllerStrings.IndexMethod, ControllerStrings.Employee));
        }
Beispiel #3
0
        public IHttpActionResult CreateEmployee(EmployeeModel employeeModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var employeeDto = Mapper.Map <EmployeeDto>(employeeModel);

                _employeeAppService.Create(employeeDto, AuthHelper.GetCurrentUserId());

                return(Ok("Employee Created"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> Post([FromBody] CreateEmployeeCommand command)
        {
            var result = _service.Create(command);

            return(await Response(result, result.Notifications));
        }
Beispiel #5
0
        public IHttpActionResult Register(AdminAreaUserViewModel viewModel)
        {
            try
            {
                //need to chop up the different parts of the view model to map to the correct
                // bits of the relevant DTOs
                long currentUserId = AuthHelper.GetCurrentUserId();
                long userId        = 0;
                long?employeeId    = null;

                // USER DTO
                if (viewModel.UserModel != null)
                {
                    var userDto = Mapper.Map <UserDto>(viewModel.UserModel);

                    // check if the login and email have already been used
                    if (_accountAppService.CheckIfLoginExists(userDto.Login))
                    {
                        return(BadRequest("Login already taken"));
                    }

                    if (_accountAppService.CheckIfEmailExists(userDto.Email))
                    {
                        return(BadRequest("Email already taken"));
                    }

                    if (userDto.ExternalTimeSystemId != null)
                    {
                        if (_accountAppService.CheckIfExternalTimeSystemIdExists((int)userDto.ExternalTimeSystemId))
                        {
                            return(BadRequest("ZK Time System ID already taken"));
                        }
                    }

                    userId = _accountAppService.RegisterUserAccount(userDto, currentUserId);
                }


                // EMPLOYEE DTO
                if (viewModel.EmployeeModel != null)
                {
                    var employeeDto = Mapper.Map <EmployeeDto>(viewModel.EmployeeModel);
                    employeeDto.UserId = userId;
                    //TEMP
                    employeeDto.StartDate = new DateTime(1900, 1, 1, 0, 0, 0);
                    employeeDto.LeaveDate = new DateTime(1900, 1, 1, 0, 0, 0);

                    // save and return new id
                    employeeId = _employeeAppService.Create(employeeDto, currentUserId);
                }


                // CONTRACT DTOs
                if (viewModel.ContractModel != null)
                {
                    var contractDto = Mapper.Map <ContractDto>(viewModel.ContractModel);
                    contractDto.EmployeeId = employeeId;
                    //TEMP
                    contractDto.StartDate = new DateTime(1900, 1, 1, 0, 0, 0);
                    contractDto.EndDate   = new DateTime(1900, 1, 1, 0, 0, 0);

                    _contractAppService.Create(contractDto, currentUserId);
                }


                // SITE ACCESS
                if (viewModel.SiteAccessModels.Any())
                {
                    var sitePersonnelLookupDtos = new List <SitePersonnelLookupDto>();
                    foreach (var siteAccessModel in viewModel.SiteAccessModels)
                    {
                        siteAccessModel.EmployeeId = employeeId;

                        var sitePersonnelLookupDto = Mapper.Map <SitePersonnelLookupDto>(siteAccessModel);
                        sitePersonnelLookupDtos.Add(sitePersonnelLookupDto);
                    }

                    // send off to be saved
                    foreach (var sitePersonnelLookupDto in sitePersonnelLookupDtos)
                    {
                        _sitePersonnelLookupAppService.Create(sitePersonnelLookupDto, currentUserId);
                    }
                }

                return(Ok("User Registered"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Beispiel #6
0
 public Task <EmployeeDto> Create(CreateOrUpdateEmployeeDto input)
 {
     return(_employeeAppService.Create(input));
 }
        public async Task <IActionResult> Create(CreateEmployeeInput input)
        {
            await _employeeAppService.Create(input);

            return(Ok());
        }