Пример #1
0
        public async Task UpdateApplicant(UpdateApplicantCommand command)
        {
            var applicant = await _applicantRepository.Get(command.Id);

            var modifiedApplicant = Applicant.Instance(applicant, _countryService)
                                    .WithName(command.Name)
                                    .WithFamily(command.Family)
                                    .WithAddress(command.Address)
                                    .WithCountryOfOrigin(command.CountryOfOrigin)
                                    .WithEmailAddress(command.EmailAddress)
                                    .WithAge(command.Age)
                                    .WithHired(command.Hired)
                                    .Build();
            await _applicantRepository.Update(modifiedApplicant);
        }
        public async Task <IActionResult> Update(Applicant applicant)
        {
            int id = 0;

            try
            {
            }
            catch (Exception ex)
            {
            }
            if (ModelState.IsValid)
            {
                id = await _repository.Update(applicant);

                if (id > 0)
                {
                    return(CreatedAtAction(nameof(GetOne), new { id = applicant.Id }, applicant));
                }
                else
                {
                    return(BadRequest("Something Went Wrong"));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
        public async Task <ApplicantGet> Update(ApplicantUpdate applicantUpdate)
        {
            ApplicantUpdateValidator applicantUpdateValidator = new ApplicantUpdateValidator(_restCountryClient);

            ValidationResult results = await applicantUpdateValidator.ValidateAsync(applicantUpdate);

            if (!results.IsValid)
            {
                foreach (var failure in results.Errors)
                {
                    throw new Exception("Property " + failure.PropertyName + " failed validation. Error was: " +
                                        failure.ErrorMessage);
                }
            }

            try
            {
                Applicant applicant = await _applicantRepository.Update(_mapper.Map <Applicant>(applicantUpdate));

                return(_mapper.Map <ApplicantGet>(applicant));
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
        public async Task UpdateApplicant(ApplicantDto input)
        {
            Applicant result = _mapper.Map <Applicant>(input);

            result.ModifiedDate = DateTime.Now;

            await _applicantrepository.Update(input.Id, result);
        }
Пример #5
0
        public object Put(int id, [FromBody] Dictionary <string, string> fields)
        {
            fields = fields.ToDictionary(item => item.Key, item => item.Value, StringComparer.OrdinalIgnoreCase);
            var entity = _builder.CreateObject(fields);

            _repository.Update(entity);

            return(entity);
        }
Пример #6
0
        public async Task <(bool isSuccess, string errorMessage)> Update(int id, ApplicantViewModel applicantViewModel)
        {
            if (await _applicantRepository.IsEmailExist(applicantViewModel.EmailAddress, id))
            {
                return(false, Resource.Error_EmailDuplicated);
            }
            bool isSuccess = await _applicantRepository.Update(id, applicantViewModel);

            return(isSuccess, string.Empty);
        }
Пример #7
0
 public Applicant Update(Applicant entity)
 {
     try
     {
         return(_applicantRepository.Update(entity).Result);
     }
     catch (Exception e)
     {
         throw;
     }
 }
Пример #8
0
        public async Task <Applicant> Update(Applicant applicant)
        {
            var success = await _repository.Update(applicant).ConfigureAwait(false);

            if (success)
            {
                return(applicant);
            }
            else
            {
                return(null);
            }
        }
        public void Update(int id, ApplicantModel model)
        {
            var entity = _repository.GetById(id);

            entity.Name            = model.Name;
            entity.FamilyName      = model.FamilyName;
            entity.Address         = model.Address;
            entity.CountryOfOrigin = model.CountryOfOrigin;
            entity.EMailAddress    = model.EMailAddress;
            entity.Age             = model.Age;
            entity.Hired           = model.Hired;
            _repository.Update(entity);
        }
        public async Task <ResponseModel> UpdateAsync(Applicant applicant)
        {
            var existingApplicant = await applicantRepository.FindByIdAsync(applicant.ID);

            if (existingApplicant == null)
            {
                return new ResponseModel {
                           Success = false, Message = "Applicant not exisit", StatusCode = 400
                }
            }
            ;

            var validationResult = new Validator.ApplicantValidator().Validate(applicant);

            if (!validationResult.IsValid)
            {
                return new ResponseModel {
                           Success = false, Message = validationResult.ToString(" Error:"), StatusCode = 400
                }
            }
            ;

            existingApplicant.Name            = applicant.Name;
            existingApplicant.Address         = applicant.Address;
            existingApplicant.Age             = applicant.Age;
            existingApplicant.CountryOfOrigin = applicant.CountryOfOrigin;
            existingApplicant.EMailAddress    = applicant.EMailAddress;
            existingApplicant.FamilyName      = applicant.FamilyName;
            existingApplicant.Hired           = applicant.Hired;

            try
            {
                applicantRepository.Update(existingApplicant);

                await unitOfWork.CompleteAsync();

                return(new ResponseModel {
                    Success = true, Message = "Applicant updated successfully", Data = applicant, StatusCode = 200
                });
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new ResponseModel {
                    Message = $"An error occurred when updating the product: {ex.Message}", Success = false, StatusCode = 400
                });
            }
        }
    }
}
Пример #11
0
        public void Update(int id, Applicant applicant)
        {
            if (id == 0)
            {
                throw new Exception(string.Format("Invalid applicant id supplied: {0}", id));
            }

            Applicant dupApplicant = _ApplicantRepository.GetById(id);

            if (dupApplicant == null)
            {
                throw new Exception(string.Format("No applicant has been found by this id : {0}", id));
            }
            _ApplicantRepository.Update(applicant);
        }
        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));
        });
Пример #13
0
        public async Task <int> Update(int id, Applicant applicant)
        {
            var validator           = new ApplicantValidator();
            ValidationResult result = validator.Validate(applicant);

            if (result.IsValid)
            {
                return(await _repository.Update(id, applicant));
            }

            var exceptionMessage = String.Join(",",
                                               result.Errors.Select(x => $"{x.ErrorMessage}").ToArray());

            _logger.LogError(exceptionMessage);

            throw new Exception(exceptionMessage);
        }
Пример #14
0
        public async Task <Applicant> Update(Applicant applicant)
        {
            if (applicant.Hired == null)
            {
                applicant.Hired = false;
            }

            var success = await _repository.Update(applicant);

            if (success)
            {
                return(applicant);
            }
            else
            {
                return(null);
            }
        }
Пример #15
0
        public async Task <ApplicantDetail> Update(ApplicantDto detail)
        {
            var details = 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.Update(details));
        }
Пример #16
0
        public void Update(Applicant dest)
        {
            if (dest == null)
            {
                throw new ArgumentNullException(nameof(dest));
            }

            var source = repo.Get(dest.ID);

            if (source == null)
            {
                throw new ApplicantMissingExcpetion(dest.ID);
            }

            if (!validator.Validate(dest, out IEnumerable <string> errors))
            {
                throw new ValidationFailedException(errors);
            }

            repo.Update(dest);
        }
Пример #17
0
        public async Task <ResponseMessagesDto> UpdateApplicant(ApplicantDto dto)
        {
            try
            {
                await _applicantRepository.Update(new Applicant()
                {
                    Id              = dto.Id,
                    Name            = dto.Name,
                    FamilyName      = dto.FamilyName,
                    Address         = dto.Address,
                    CountryOfOrigin = dto.CountryOfOrigin,
                    EmailAddress    = dto.EmailAddress,
                    Age             = dto.Age,
                    Hired           = dto.Hired,
                });

                return(new ResponseMessagesDto()
                {
                    Id = dto.Id,
                    SuccessMessage = "Successfully Updated",
                    Success = true,
                    Error = false
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ResponseMessagesDto()
                {
                    Id = 0,
                    FailureMessage = "Failed To Update",
                    Success = false,
                    Error = true,
                    ExceptionMessage = e.InnerException != null ? e.InnerException.Message : e.Message
                });
            }
        }
 public Task <Applicant> Update(Applicant applicant)
 {
     _logger.LogInformation("Executing {0} service method for applicant {1}.", nameof(Update), applicant.Id);
     return(_repository.Update(applicant));
 }