public async Task <IActionResult> PutApplicant(int id, Applicant applicant)
        {
            _logger.LogInformation("{0} called with id {1}.", nameof(PutApplicant), id);
            if (id != applicant.Id)
            {
                return(BadRequest());
            }

            _context.Entry(applicant).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ApplicantExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <int> CreateApplicant(ApplicantModel applicantModel)
        {
            if (applicantModel != null)
            {
                await _applicantContext.Applicants.AddAsync(applicantModel);

                await _applicantContext.SaveChangesAsync();

                return(applicantModel.ID);
            }

            return(0);
        }
예제 #3
0
        public async Task <Applicant> Add(ApplicantPostRequest model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            var entityToAdd = _mapper.Map <Data.Entities.Applicant>(model);
            await _context.AddAsync(entityToAdd);

            await _context.SaveChangesAsync();

            var result = await Get(entityToAdd.Id);

            return(result);
        }
예제 #4
0
        public async Task <ApplicantObjResponse> AddApplicant(ApplicantObj applicant)
        {
            try
            {
                ApplicantValidator validator = new ApplicantValidator();

                ValidationResult results = validator.Validate(applicant);
                if (!results.IsValid)
                {
                    IList <ValidationFailure> failures = results.Errors;
                    return(new ApplicantObjResponse()
                    {
                        ValidationResults = failures
                    });
                }
                var app = new Applicant
                {
                    Address         = applicant.Address,
                    Age             = applicant.Age,
                    EMailAdress     = applicant.EMailAdress,
                    FamilyName      = applicant.FamilyName,
                    Hired           = applicant.Hired,
                    Name            = applicant.Name,
                    CountryOfOrigin = applicant.CountryOfOrigin
                };
                _logger.LogInformation($"request from applicant--- {JsonConvert.SerializeObject(app)}");
                var res = await _context.Applicants.AddAsync(app);

                await _context.SaveChangesAsync();

                return(new ApplicantObjResponse()
                {
                    Success = true
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message + " " + ex.StackTrace);
                return(new ApplicantObjResponse()
                {
                    Success = false
                });
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="applicant"></param>
        /// <returns></returns>
        public async Task <Applicant> UpdateApplicant(T applicant)
        {
            Applicant applicantDB = applicant as Applicant;

            using (var context = new ApplicantContext(dbContextOptions))
            {
                context.Applicants.Update(applicantDB);
                await context.SaveChangesAsync();
            }
            return(applicantDB);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="applicant"></param>
        /// <returns></returns>
        public async Task <Applicant> AddApplicant(T applicant)
        {
            Applicant applicantDB = applicant as Applicant;

            using (var context = new ApplicantContext(dbContextOptions))
            {
                //logger.LogInformation($"Db Connvetion Successful");
                context.Applicants.Add(applicantDB);
                //logger.LogInformation($"Entity Data was added into the Context");

                await context.SaveChangesAsync(acceptAllChangesOnSuccess : true);

                //logger.LogInformation($"Entity Data was saved in the DB");
            }
            return(applicantDB);
        }
 /// <summary>
 /// Asynchronously saves all changes made in this _context to the underlying inmemory database.
 /// </summary>
 /// <param name="applicant"></param>
 /// <returns></returns>
 public async Task <int> AddApplicant(Applicant applicant)
 {
     _context.Applicants.Add(applicant);
     return(await _context.SaveChangesAsync());
 }