示例#1
0
        public async Task <ActionResult> Put(int id, [FromBody] BindRecruiter bindRecruiter)
        {
            try
            {
                if (id != bindRecruiter.RecruiterId)
                {
                    return(BadRequest());
                }

                var updatedRecruiter = await _context.Recruiters.FirstOrDefaultAsync(r => r.RecruiterId == bindRecruiter.RecruiterId);

                updatedRecruiter.Name  = bindRecruiter.Name;
                updatedRecruiter.Email = bindRecruiter.Email;
                updatedRecruiter.Phone = bindRecruiter.Phone;

                _context.Entry(updatedRecruiter).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                return(NoContent());
            }
            catch
            {
                return(BadRequest());
            }
        }
示例#2
0
        public async Task <ActionResult <Recruiter> > Post([FromBody] BindRecruiter bindRecruiter)
        {
            try
            {
                if (bindRecruiter != null)
                {
                    var newRecruiter = new Recruiter()
                    {
                        Name  = bindRecruiter.Name,
                        Email = bindRecruiter.Email,
                        Phone = bindRecruiter.Phone
                    };

                    _context.Recruiters.Add(newRecruiter);
                    await _context.SaveChangesAsync();

                    var insertedRecruiter = _context.Recruiters.Where(j => j.RecruiterId == newRecruiter.RecruiterId);
                    if (insertedRecruiter != null)
                    {
                        return(CreatedAtAction(nameof(newRecruiter), new { id = newRecruiter.RecruiterId }, newRecruiter));
                    }
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }