public async Task <bool> UpdateCandidate(string id, UpdateCandidateModel candidate)
        {
            _logger.Debug($"Updating candidate {id}");
            var objectId = ObjectId.Parse(id);

            if (candidate == null)
            {
                throw new Exception($"Candidate not provided for id={id}");
            }

            if (id != candidate.Id)
            {
                throw new Exception($"Id {id} is different from candidate's id {candidate.Id}");
            }

            var modificationUpdate = Builders <Candidate> .Update
                                     .Set(x => x.FirstName, candidate.FirstName)
                                     .Set(x => x.LastName, candidate.LastName)
                                     .Set(x => x.Description, candidate.Description);

            var result = await MvcApplication.ElectionsContext.Candidates.UpdateOneAsync(x => x._id == objectId, modificationUpdate);

            _logger.Debug($"Candidate {id} updated. isAcknownledged?: {result.IsAcknowledged}.");

            return(result.IsAcknowledged);
        }
Exemple #2
0
        public async Task <IActionResult> Create(IFormFile resume, [FromForm] UpdateCandidateModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(GetModelStateErrors(ModelState)));
                }

                if (resume == null)
                {
                    return(Ok(WebApiResponses <CandidateModel> .ErrorOccured("No resume found")));
                }

                var response = await _candidateService.CreateCandidate(resume.OpenReadStream(), resume.ContentType, model);

                if (response.ResponseCode != ResponseCode.Ok)
                {
                    return(Ok(WebApiResponses <CandidateModel> .ErrorOccured(response.Message)));
                }
                return(Ok(WebApiResponses <CandidateModel> .Successful(response.ResponseData)));
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(Ok(WebApiResponses <CandidateModel> .ErrorOccured(ex.Message)));
            }
        }
        public async Task <ActionResult> Edit(string id)
        {
            var candidate = await _candidateService.GetCandidateById(id);

            var editCandidateModel = new UpdateCandidateModel
            {
                Id        = candidate.Id,
                FirstName = candidate.FirstName,
                LastName  = candidate.LastName
            };

            return(View(editCandidateModel));
        }
Exemple #4
0
        public IActionResult Update(int id, [FromBody] UpdateCandidateModel model)
        {
            var identity = User.Identity as ClaimsIdentity;

            if (identity == null)
            {
                return(Unauthorized());
            }
            if (User.IsInRole("Admin") || int.Parse(identity.Name) == id)
            {
                var candidate = _context.Candidates.Find(id);
                if (candidate == null)
                {
                    return(NotFound());
                }
                var user = _mapper.Map <User>(model);
                user.Id = candidate.UserId;
                bool updated = false;

                if (!string.IsNullOrEmpty(model.SkillSet))
                {
                    candidate.Skillset = model.SkillSet;
                    updated            = true;
                }
                if (model.IsAvailable != candidate.IsAvailable)
                {
                    candidate.IsAvailable = model.IsAvailable;
                    updated = true;
                }
                try
                {
                    _userService.Update(user, model.CurrentPassword, model.NewPassword, model.ConfirmPassword, updated);
                    _context.Candidates.Update(candidate);
                    _context.SaveChanges();
                    return(Ok());
                }
                catch (AppException e)
                {
                    return(BadRequest(new { message = e.Message }));
                }
            }
            return(Unauthorized());
        }
        public async Task <ActionResult> Edit(string id, UpdateCandidateModel candidate)
        {
            if (candidate == null)
            {
                throw new Exception($"Candidate not provided for id={id}");
            }
            if (id != candidate.Id)
            {
                throw new Exception($"Id {id} is different from candidate's id {candidate.Id}");
            }

            if (ModelState.IsValid)
            {
                var result = await _candidateService.UpdateCandidate(id, candidate);

                return(RedirectToAction("Details", "Candidate", new { id }));
            }
            return(View(candidate));
        }
        public ActionResult Update(UpdateCandidateModel vm)
        {
            ApiResult <Candidate> apiResult;

            if (ModelState.IsValid)
            {
                if (vm.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        var selectedCandidate             = _candidateRepository.Get(vm.Id, "Person");
                        selectedCandidate.Email           = vm.Email;
                        selectedCandidate.Source          = vm.Source;
                        selectedCandidate.Qualification   = vm.Qualification;
                        selectedCandidate.TotalExperience = vm.TotalExperience;
                        selectedCandidate.Status          = vm.Status;
                        selectedCandidate.Comments        = vm.Comments;
                        selectedCandidate.CurrentCTC      = vm.CurrentCTC;
                        selectedCandidate.ExpectedCTC     = vm.ExpectedCTC;
                        selectedCandidate.DesignationId   = vm.CandidateDesignation;
                        selectedCandidate.RecievedOn      = vm.RecievedOn;

                        // Update Person
                        selectedCandidate.Person.FirstName            = vm.FirstName;
                        selectedCandidate.Person.MiddleName           = vm.MiddleName;
                        selectedCandidate.Person.LastName             = vm.LastName;
                        selectedCandidate.Person.Gender               = vm.Gender;
                        selectedCandidate.Person.Email                = vm.Email;
                        selectedCandidate.Person.SecondaryEmail       = vm.SecondaryEmail;
                        selectedCandidate.Person.Organization         = vm.Organization;
                        selectedCandidate.Person.Designation          = vm.Designation;
                        selectedCandidate.Person.PhoneNo              = vm.PhoneNo;
                        selectedCandidate.Person.OfficePhone          = vm.OfficePhone;
                        selectedCandidate.Person.Skype                = vm.Skype;
                        selectedCandidate.Person.Facebook             = vm.Facebook;
                        selectedCandidate.Person.Twitter              = vm.Twitter;
                        selectedCandidate.Person.LinkedIn             = vm.LinkedIn;
                        selectedCandidate.Person.GooglePlus           = vm.GooglePlus;
                        selectedCandidate.Person.Address              = vm.Address;
                        selectedCandidate.Person.CommunicationAddress = vm.CommunicationAddress;
                        selectedCandidate.Person.DateOfBirth          = vm.DateOfBirth;

                        _candidateRepository.Update(selectedCandidate);
                        _unitOfWork.Commit();
                        return(selectedCandidate);
                    }, "Candidate updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        var newCandidate = new Candidate
                        {
                            Email           = vm.Email,
                            Source          = vm.Source,
                            Qualification   = vm.Qualification,
                            TotalExperience = vm.TotalExperience,
                            Status          = vm.Status,
                            Comments        = vm.Comments,
                            CurrentCTC      = vm.CurrentCTC,
                            ExpectedCTC     = vm.ExpectedCTC,
                            DesignationId   = vm.CandidateDesignation,
                            RecievedOn      = vm.RecievedOn,
                            Person          = new Person
                            {
                                FirstName            = vm.FirstName,
                                MiddleName           = vm.MiddleName,
                                LastName             = vm.LastName,
                                Gender               = vm.Gender,
                                Email                = vm.Email,
                                SecondaryEmail       = vm.SecondaryEmail,
                                Organization         = vm.Organization,
                                Designation          = vm.Designation,
                                PhoneNo              = vm.PhoneNo,
                                OfficePhone          = vm.OfficePhone,
                                Skype                = vm.Skype,
                                Facebook             = vm.Facebook,
                                Twitter              = vm.Twitter,
                                LinkedIn             = vm.LinkedIn,
                                GooglePlus           = vm.GooglePlus,
                                Address              = vm.Address,
                                CommunicationAddress = vm.CommunicationAddress,
                                DateOfBirth          = vm.DateOfBirth
                            },
                            CreatedByUserId = WebUser.Id
                        };

                        // Update Person

                        _candidateRepository.Create(newCandidate);
                        _unitOfWork.Commit();
                        return(newCandidate);
                    }, "Candidate created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <Candidate>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }