示例#1
0
        public async Task <ResponseMessagesDto> DeleteApplicant(ApplicantDto applicantDto)
        {
            try
            {
                await _applicantRepository.Delete(new Applicant()
                {
                    Id = applicantDto.Id
                });

                return(new ResponseMessagesDto()
                {
                    Id = applicantDto.Id,
                    SuccessMessage = "Successfully Deleted",
                    Success = true,
                    Error = false
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ResponseMessagesDto()
                {
                    Id = 0,
                    FailureMessage = "Failed To Delete",
                    Success = false,
                    Error = true,
                    ExceptionMessage = e.InnerException != null ? e.InnerException.Message : e.Message
                });
            }
        }
示例#2
0
        public IHttpActionResult RegistrationDriver(ApplicantDto userdto)
        {
            AuthBL repos = new AuthBL();

            if (ModelState.IsValid == false)
            {
                return(BadRequest());
            }



            IdentityResult result = repos.CreateDriver(userdto);

            if (result.Succeeded)
            {
                using (HttpClient httpClient = new HttpClient())
                {
                    Dictionary <string, string> tokenDetails = null;

                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri("http://localhost:4700/");
                    var login = new Dictionary <string, string>
                    {
                        { "grant_type", "password" },
                        { "username", userdto.Email },
                        { "password", userdto.Password },
                    };
                    var response = client.PostAsync("Token", new FormUrlEncodedContent(login)).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        tokenDetails = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Content.ReadAsStringAsync().Result);
                        if (tokenDetails != null && tokenDetails.Any())
                        {
                            var          tokenNo = tokenDetails.FirstOrDefault().Value;
                            IdentityUser user    = repos.Find(userdto.Email, userdto.Password);

                            AdminController applicantobj = new AdminController();
                            NewApplicant    applicant    = applicantobj.getApplicant(userdto.NationalID);
                            Driver          driver       = new Driver
                            {
                                UserID        = user.Id,
                                NationalID    = applicant.NationalID,
                                Rate          = 0,
                                numberOfTrips = 0,
                                AvgRate       = 0.0,
                            };
                            applicant.Status = NewApplicantstatus.Accepted;
                            context.Entry(applicant).State = EntityState.Modified;
                            context.SaveChanges();

                            context.Drivers.Add(driver);
                            context.SaveChanges();
                            return(Ok());
                        }
                    }
                }
            }

            return(BadRequest());
        }
        public async Task <ActionResult <Applicant> > PostApplicant(ApplicantDto applicantDto)
        {
            var applicant = _mapper.Map <Applicant>(applicantDto);
            await _applicantService.CreateApplicant(applicant);

            return(CreatedAtAction("PostApplicant", new { id = applicant.Id }, applicant));
        }
示例#4
0
        public async Task <IActionResult> PutApplicant(ApplicantDto applicant)
        {
            await _applicantRepository.Update(_objectMapper.Map <Applicant>(applicant));


            return(NoContent());
        }
示例#5
0
        public async Task <ActionResult <ApplicantDto> > PostApplicant(ApplicantDto applicant)
        {
            var entity = _objectMapper.Map <Applicant>(applicant);
            await _applicantRepository.Insert(entity);

            return(CreatedAtAction("GetApplicant", new { id = applicant.ID }, _objectMapper.Map <Applicant>(entity)));
        }
        public async Task <ApplicantDto> Get(int userId)
        {
            var result = await _applicant.Get(userId);

            int?countryId;

            if (result.StateId != null)
            {
                countryId = await _applicant.GetCountryId(result.StateId);
            }
            else
            {
                countryId = null;
            }
            var applicantDetail = new ApplicantDto
            {
                Id          = result.Id,
                FirstName   = result.FirstName,
                LastName    = result.LastName,
                Email       = result.Email,
                DateOfBirth = result.DateOfBirth,
                Country     = countryId,
                State       = result.StateId,
                Disabled    = result.Disabled,
                Address     = result.Address,
                City        = result.City,
                PostalCode  = result.PostalCode,
                Mobile      = result.Mobile,
                Phone       = result.Phone
            };

            return(applicantDetail);
        }
示例#7
0
        public async Task <ApplicantDto> GetById(int applicantId)
        {
            try
            {
                var applicant = await _applicantRepository.GetById(applicantId);

                var applicantDto = new ApplicantDto()
                {
                    Id              = applicant.Id,
                    Name            = applicant.Name,
                    FamilyName      = applicant.FamilyName,
                    Address         = applicant.Address,
                    CountryOfOrigin = applicant.CountryOfOrigin,
                    EmailAddress    = applicant.EmailAddress,
                    Age             = applicant.Age,
                    Hired           = applicant.Hired,
                };
                return(applicantDto);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
        }
示例#8
0
        public async Task <IActionResult> PostRegisterAsync([FromBody] ApplicantDto applicantDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest());
                }
                else
                {
                    var applicant = _mapper.Map <Applicant>(applicantDto);

                    _applicationViewModel = await _serviceAXA.PostRegisterAsync <ApplicationViewModel, Applicant>(applicant);

                    return(Ok(_applicationViewModel));
                }
            }
            catch (Exception ex)
            {
                _applicationViewModel.IsSuccess = false;
                _applicationViewModel.Message   = ex.Message;

                return(StatusCode(500, _applicationViewModel));
            }
        }
 private void Apply(Applicant applicant, ApplicantDto update)
 {
     applicant.Set(new Name(update.Name));
     applicant.Set(new FamilyName(update.FamilyName));
     applicant.Set(new Address(update.Address));
     applicant.Set(new EmailAddress(update.EmailAddress));
     applicant.Set(new Age(update.Age));
     applicant.Set(update.CountryOfOrigin);
     applicant.Set(update.Hired);
 }
        public IActionResult UpdateVacancy([FromBody] ApplicantDto applicantDto)
        {
            if (ModelState.IsValid)
            {
                _applicantService.UpdateApplicant(applicantDto);
                return(StatusCode(StatusCodes.Status204NoContent));
            }

            return(BadRequest());
        }
        public Task <Result <Applicant> > RegisterApplicant(ApplicantDto dto) =>
        TryCatch(async() =>
        {
            await ValidateApplicantDtoAsync(dto);

            var applicant = new Applicant(new Name(dto.Name), new FamilyName(dto.FamilyName),
                                          new Address(dto.Address), dto.CountryOfOrigin, new EmailAddress(dto.EmailAddress),
                                          new Age(dto.Age), dto.Hired);
            await _applicantRepository.Create(applicant);
            return(Result.Success(applicant));
        });
示例#12
0
        protected async Task ValidateApplicatint(ApplicantDto applicantDto)
        {
            var countryList = await _mediator.Send(new GetAllCountriesQuery());

            var matches = countryList.Where(p => String.Equals(p.Name.Trim().ToLower(), applicantDto.CountryOfOrigin.Trim().ToLower(), StringComparison.CurrentCulture));

            if (matches.Count() == 0)
            {
                throw new Exception($"Country of origin - {applicantDto.CountryOfOrigin} is not a valid country. Please provide a valid one");
            }
        }
示例#13
0
 public async Task <IActionResult> Delete([FromBody] ApplicantDto dto)
 {
     try
     {
         return(Ok(await _applicantService.DeleteApplicant(dto)));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
        public void AddApplicantByUserModel(RegistrationModel registrationModel)
        {
            var applicantDto = new ApplicantDto
            {
                FirstName = registrationModel.FirstName,
                LastName  = registrationModel.LastName,
                Email     = registrationModel.Email,
                UserId    = registrationModel.UserId,
            };

            _applicantService.AddApplicant(applicantDto);
        }
示例#15
0
        public async Task <IActionResult> Post(ApplicantDto applicant)
        {
            try
            {
                var newCompanyId = await _applicantService.CreateApplicant(applicant);

                return(new CreatedAtActionResult(nameof(Get), "Applicant", new { id = newCompanyId }, newCompanyId));
            }
            catch (FluentValidation.ValidationException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#16
0
        public async Task <Object> UpdateApplicant([FromBody] ApplicantDto applicantDto, [FromRoute] string id)
        {
            var applicant = await _databaseContext.Applicants.FirstOrDefaultAsync(x => x.Id.ToString() == id);

            if (applicant == null)
            {
                return(BadRequest("Введен "));
            }
            applicant = _mapper.Map <ApplicantDto, Applicant>(applicantDto);
            await _databaseContext.SaveChangesAsync();

            return(Ok("Информация о соискателе успешно обновлена"));
        }
示例#17
0
        //create
        public IdentityResult CreateDriver(ApplicantDto userdto)
        {
            IdentityUser identityUser = new IdentityUser();

            identityUser.UserName = userdto.Email;
            identityUser.Email    = userdto.Email;


            IdentityResult identityResult = manager.Create(identityUser, userdto.Password);
            IdentityUser   user           = Find(userdto.Email, userdto.Password);

            return(manager.AddToRole(user.Id, "Driver"));
        }
示例#18
0
        public async Task <IActionResult> Put(ApplicantDto applicant)
        {
            try
            {
                await _applicantService.UpdateApplicant(applicant);

                return(NoContent());
            }
            catch (FluentValidation.ValidationException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#19
0
        public async Task UpdateApplicant(ApplicantDto applicantDto)
        {
            var applicantDomain = await _repository.GetApplicant(applicantDto.Id);

            applicantDomain.Name            = applicantDto.Name;
            applicantDomain.FamilyName      = applicantDto.FamilyName;
            applicantDomain.Hired           = applicantDto.Hired;
            applicantDomain.EMailAddress    = applicantDto.EMailAddress;
            applicantDomain.Address         = applicantDto.Address;
            applicantDomain.Age             = applicantDto.Age;
            applicantDomain.CountryOfOrigin = applicantDto.CountryOfOrigin;

            await _repository.UpdateApplicant(applicantDomain);
        }
示例#20
0
        public async Task <Object> CreateApplicant([FromBody] ApplicantDto applicantDto)
        {
            var applicant = _mapper.Map <ApplicantDto, Applicant>(applicantDto);

            if (applicant != null)
            {
                await _databaseContext.Applicants.AddAsync(applicant);

                await _databaseContext.SaveChangesAsync();

                return(applicant.Id);
            }

            return(BadRequest("Введены неверные данные"));
        }
示例#21
0
        public async Task <int> CreateApplicant(ApplicantDto applicant)
        {
            var newApplicant = new Applicant()
            {
                Name            = applicant.Name,
                FamilyName      = applicant.FamilyName,
                Age             = applicant.Age,
                EMailAddress    = applicant.EMailAddress,
                CountryOfOrigin = applicant.CountryOfOrigin,
                Address         = applicant.Address,
                Hired           = applicant.Hired
            };

            return(await _repository.CreateApplicant(newApplicant));
        }
示例#22
0
 public async Task <IActionResult> Post([FromBody] ApplicantDto dto)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         return(Ok(await _applicantService.AddApplicant(dto)));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
        public Task <Result <Applicant> > ModifyApplicant(int applicantId, ApplicantDto update) =>
        TryCatch(async() =>
        {
            await ValidateApplicantDtoAsync(update);

            var applicant = await _applicantRepository.FindById(applicantId);
            if (applicant == null)
            {
                return(Result.Failure <Applicant>($"applicant {applicantId} not found!"));
            }

            Apply(applicant, update);

            await _applicantRepository.Update(applicant);
            return(Result.Success(applicant));
        });
        /// <summary>
        /// Updates applicant
        /// </summary>
        /// <param name="applicantDto">Applicant details</param>
        public async Task <bool> EditApplicantAsync(ApplicantDto applicantDto)
        {
            using (var uow = UnitOfWorkProvider.Create())
            {
                if (await applicantService.GetAsync(applicantDto.Id, false) == null)
                {
                    return(false);
                }

                await applicantService.Update(applicantDto);

                await uow.Commit();

                return(true);
            }
        }
        public async Task <ActionResult <ApplicantDto> > Get([FromRoute] int id)
        {
            try
            {
                var applicant = await _applicantService.GetApplicant(id);

                if (applicant != null)
                {
                    return(Ok(ResultDto <ApplicantDto> .CreateSuccessfulResult(ApplicantDto.FromApplicant(applicant))));
                }
                return(NotFound());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error On get single applicant: id: {id}", id);
                return(StatusCode(500, "Something went wrong on server side"));
            }
        }
        public async Task <ApplicantDetail> Save(ApplicantDto detail)
        {
            var applicantDetail = new ApplicantDetail {
                Id          = detail.Id,
                FirstName   = detail.FirstName,
                LastName    = detail.LastName,
                Email       = detail.Email,
                DateOfBirth = detail.DateOfBirth,
                StateId     = detail.State,
                Disabled    = detail.Disabled,
                Address     = detail.Address,
                City        = detail.City,
                PostalCode  = detail.PostalCode,
                Mobile      = detail.Mobile,
                Phone       = detail.Phone
            };

            return(await _applicant.Save(applicantDetail));
        }
示例#27
0
        public void Should_fail_to_add_applicant_when_any_required_data_is_Invalid(string name, string familyName,
                                                                                   string address, string country, string email, int age, bool isHired
                                                                                   )
        {
            ApplicantDto requestModel = new ApplicantDto();

            Given_name(requestModel, name);
            Given_family_name(requestModel, familyName);
            Given_address(requestModel, address);
            Given_country_of_origin(requestModel, country);
            Given_email(requestModel, email);
            Given_age(requestModel, age);
            Given_hired(requestModel, isHired);

            //act
            Func <Task> action = async() => { await _applicantService.RegisterApplicant(requestModel); };

            //assert
            action.Should().ThrowExactly <ApplicantPropertyValidationException>();
        }
示例#28
0
        //[ProducesResponseType(StatusCodes.Status201Created)]

        public async Task <IActionResult> Post([FromBody] ApplicantDto model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var data = await _mediator.Send(new CreateApplicantCommand { Applicant = model });

                //return CreatedAtRoute("GetById",new { id = data.Id });
                return(CreatedAtAction(nameof(GetById), new { id = data.Id }, data));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message.ToString(), model);
                throw ex;
            }
        }
示例#29
0
        public void Should_fail_to_modify_applicant_when_any_update_data_is_Invalid(string name, string familyName,
                                                                                    string address, string country, string email, int age, bool isHired
                                                                                    )
        {
            int          applicantId = 1;
            ApplicantDto updateModel = new ApplicantDto();

            Given_name(updateModel, name);
            Given_family_name(updateModel, familyName);
            Given_address(updateModel, address);
            Given_country_of_origin(updateModel, country);
            Given_email(updateModel, email);
            Given_age(updateModel, age);
            Given_hired(updateModel, isHired);

            //act
            Func <Task> action = async() => { await _applicantService.ModifyApplicant(applicantId, updateModel); };

            //assert
            action.Should().ThrowExactly <ApplicantPropertyValidationException>();
        }
        private async Task ValidateApplicantDtoAsync(ApplicantDto dto)
        {
            var modelValidator = new ApplicantDtoValidator();
            var validation     = await modelValidator.ValidateAsync(dto);

            if (!validation.IsValid)
            {
                throw new ApplicantPropertyValidationException(
                          validation.Errors.ToDictionary(x => x.PropertyName, x => x.ErrorMessage));
            }

            var fetchCountryData = await _countryDataProvider.ValidateCountry(dto.CountryOfOrigin);

            if (fetchCountryData.IsFailure)
            {
                throw new ApplicantPropertyValidationException(new Dictionary <string, string>()
                {
                    { nameof(ApplicantDto.CountryOfOrigin), $"country {dto.CountryOfOrigin} is not valid!" }
                });
            }
        }