Esempio n. 1
0
        public async Task <IActionResult> PutJob([FromRoute] int id, [FromBody] BindJob bindJob)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != bindJob.JobId)
            {
                return(BadRequest());
            }
            var updatedJob = await _context.Jobs
                             .FirstOrDefaultAsync(j => j.JobId == bindJob.JobId);

            if (!User.HasClaim(claim => (claim.Type == DefinedClaimTypes.RecruiterId && claim.Value == updatedJob.RecruiterId.ToString()) ||
                               (claim.Type == DefinedClaimTypes.Access && claim.Value == DefinedClaimAccessValues.Elevated)))
            {
                return(BadRequest());
            }

            updatedJob.Title      = bindJob.Title;
            updatedJob.Remarks    = bindJob.Remarks;
            updatedJob.BaseSalary = bindJob.BaseSalary;
            updatedJob.Fee        = bindJob.Fee;
            updatedJob.StartDate  = bindJob.StartDate;
            if (bindJob.ClientId > 0 & updatedJob.ClientId != bindJob.ClientId)
            {
                updatedJob.Client = await _context.CrmClients.FirstOrDefaultAsync(cl => cl.ClientId == bindJob.ClientId);
            }
            if (bindJob.JobStatusId > 0)
            {
                updatedJob.JobStatus = await _context.JobStatuses.FirstOrDefaultAsync(js => js.JobStatusId == bindJob.JobStatusId);
            }

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

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

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> PostJob([FromBody] BindJob bindJob)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (bindJob.RecruiterId < 1)
            {
                return(BadRequest());
            }

            var newJob = new Job()
            {
                Title   = bindJob.Title,
                Remarks = bindJob.Remarks
            };

            if (bindJob.ClientId > 0)
            {
                newJob.Client = await _context.CrmClients.FirstOrDefaultAsync(cl => cl.ClientId == bindJob.ClientId);
            }
            if (bindJob.RecruiterId > 0)
            {
                newJob.Recruiter = await _context.Recruiters.FirstOrDefaultAsync(r => r.RecruiterId == bindJob.RecruiterId);
            }

            newJob.CandidatesSent = new List <CandidateSentToIntrerview>();
            if (bindJob.CandidateId > 0)
            {
                newJob.CandidatesSent
                .Add(new CandidateSentToIntrerview()
                {
                    CandidateSentToIntrerviewId = bindJob.CandidateId
                });
            }
            if (bindJob.JobStatusId > 0)
            {
                newJob.JobStatus = await _context.JobStatuses.FirstOrDefaultAsync(js => js.JobStatusId == bindJob.JobStatusId);
            }

            _context.Jobs.Add(newJob);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetJob", new { id = newJob.JobId }, newJob));
        }