public IActionResult UpdateDetails([FromBody] ProfileSettings profile) { try { AppUser user = _appDbContext.Set <AppUser>().FirstOrDefault(u => u.Id == _clientData.Id); if (user != null) { _appDbContext.Attach(user); if (profile.FirstName != user.FirstName) { user.FirstName = profile.FirstName; } if (profile.LastName != user.LastName) { user.LastName = profile.LastName; } if (_clientData.UserType == (int)UserType.Candidate) { if (profile.AllowSendResume != null) { CandidateUser candidate = _appDbContext.Set <CandidateUser>().FirstOrDefault(u => u.Id == _clientData.ChildId); _appDbContext.Attach(candidate); candidate.AllowSendResume = (bool)profile.AllowSendResume; } } else if (_clientData.UserType == (int)UserType.Recruiter) { if (profile.ReceiveNotifications != null) { RecruiterUser recruiter = _appDbContext.Set <RecruiterUser>().FirstOrDefault(u => u.Id == _clientData.ChildId); _appDbContext.Attach(recruiter); recruiter.ReceiveNotifications = (bool)profile.ReceiveNotifications; } } _appDbContext.SaveChanges(); return(Ok()); } return(BadRequest("There was a problem updating details")); } catch (Exception e) { _log.LogError(e, "Update Details failed"); return(BadRequest(e)); } }
public async Task <IActionResult> RegisterRecruiter([FromBody] RecruiterRegistrationViewModel model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userIdentity = _mapper.Map <AppUser>(model); var result = await _userManager.CreateAsync(userIdentity, model.Password); if (!result.Succeeded) { return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState))); } var recruiter = new RecruiterUser { IdentityId = userIdentity.Id }; await _appDbContext.Recruiters.AddAsync(recruiter); await _appDbContext.SaveChangesAsync(); userIdentity.ChildId = recruiter.Id; userIdentity.UserType = (int)UserType.Recruiter; await _userManager.UpdateAsync(userIdentity); await _appDbContext.SaveChangesAsync(); return(new OkResult()); } catch (Exception e) { return(BadRequest(e)); } }
public void Execute() { if (ApplicationDbContext.options != null && !isRunning) { isRunning = true; ApplicationDbContext appDbContext = new ApplicationDbContext(ApplicationDbContext.options); try { // Load relevant constants from Configration file (appSettings) int minQuestionsRecommend = ConfigurationManager.Instance.GetValue("MIN_QUESTIONS_RECOMMEND", Consts.MIN_QUESTIONS_RECOMMEND); double maxQuestionRank = ConfigurationManager.Instance.GetValue("MAX_QUESTION_RANK", Consts.MAX_QUESTION_RANK); double minDaysAfterRejected = ConfigurationManager.Instance.GetValue("NUM_DAYS_AFTER_REJECTED", Consts.NUM_DAYS_AFTER_REJECTED); // Load relevant candidates (which enabled to send their resume) and solved at least MIN_QUESTIONS_RECOMMEND IEnumerable <CandidateUser> candidates = appDbContext.Set <CandidateUser>() .Include("Questions.Question") .Where(c => c.AllowSendResume && c.Questions.Where(q => q.IsDone).Count() >= minQuestionsRecommend); // Load relevant recruiters (which enabled to receive notifications) Dictionary <string, RecruiterUser> recruiters = appDbContext.Set <RecruiterUser>() .Include(r => r.Identity) .Where(r => r.ReceiveNotifications).ToDictionary(r => r.IdentityId, r => r); // Load only OPEN positions which created by recruiters who enabled notifications IEnumerable <Position> positions = appDbContext.Set <Position>() .Include(p => p.PositionSkills) .Where(p => p.Status == (int)PositionStatus.Opened && recruiters.ContainsKey(p.CreatedBy)); // Load recommendations which is relevant to filter users /* * It is uses in order to prevent from sending recommendations to recruiters * about candidates which sent a recommendation already */ var recommendations = appDbContext.Set <RecommendationNotification>() .Where(r => !(r.Approved == false && r.DateResponded.Value.AddDays(minDaysAfterRejected) < DateTime.Now)) .ToLookup(r => r.PositionId, r => r); foreach (Position position in positions) { IEnumerable <PositionSkill> positionSkills = position.PositionSkills; Dictionary <int, double> matchingNumbersOfCandidates = new Dictionary <int, double>(); foreach (CandidateUser candidate in candidates) { bool skipToNextCandidate = false; //if(recommendations.Contains(position.Id)) //{ //} foreach (RecommendationNotification recommendation in recommendations[position.Id]) { if (recommendation.CandidateId == candidate.Id) { skipToNextCandidate = true; break; } } if (skipToNextCandidate) { continue; } double matchingNumber = 0; foreach (PositionSkill positionSkill in positionSkills) { double skillGrade = 0; double maxTotalRank = 0; double totalRank = 0; double sumQuestionsRank = 0; // Load questions which done by the candidate, and has at least one skill of this position var relevantQuestions = candidate.Questions.Where(cq => cq.IsDone && cq.Question.Rank > 0); var questionsWithAtLeastOneRelevantSkill = new List <CandidateQuestion>(); foreach (CandidateQuestion cq in relevantQuestions) { if (Utils.ConvertStringIdsToList(cq.Question.TestedSkills).Contains(positionSkill.Id)) { questionsWithAtLeastOneRelevantSkill.Add(cq); } } relevantQuestions = questionsWithAtLeastOneRelevantSkill; maxTotalRank = relevantQuestions.Count() * maxQuestionRank; if (maxTotalRank > 0) { foreach (var relevantQuestion in relevantQuestions) { sumQuestionsRank += relevantQuestion.Question.Rank / maxQuestionRank; totalRank += relevantQuestion.Question.Rank; } skillGrade = sumQuestionsRank * (totalRank / maxTotalRank) * positionSkill.SkillWeight; matchingNumber += skillGrade; } } if (matchingNumber > 0) { matchingNumbersOfCandidates.Add(candidate.Id, matchingNumber); } } // Getting the recommended candidate which his matching number is the heighest double max = 0; int candidateId = -1; foreach (var matchingNumber in matchingNumbersOfCandidates) { if (matchingNumber.Value > max) { max = matchingNumber.Value; candidateId = matchingNumber.Key; } } if (candidateId != -1 && recruiters.ContainsKey(position.CreatedBy)) { RecruiterUser relevantRecruiter = recruiters[position.CreatedBy]; // Update recommentdation table Notification notificiation = new Notification() { Type = (int)NotificationType.Recommendation, DateCreated = DateTime.Now, IsViewed = false, Recipent = relevantRecruiter.IdentityId, }; RecommendationNotification recommendation = new RecommendationNotification() { Approved = null, Notification = notificiation, CandidateId = candidateId, PositionId = position.Id, }; var otherDbContext = new ApplicationDbContext(ApplicationDbContext.options); new RecommendationNotificationsRepository(otherDbContext).Add(recommendation); otherDbContext.SaveChanges(); var genericNotificationToClient = new GenericNotification() { NotificationId = recommendation.Notification.Id, Type = recommendation.Notification.Type, DateCreated = recommendation.Notification.DateCreated, IsViewed = recommendation.Notification.IsViewed, Approved = recommendation.Approved, CandidateId = recommendation.CandidateId, }; // Send the recommendation NotificationsHub.Notify(relevantRecruiter.Identity.Email, genericNotificationToClient); } //double maxMatchingNumber = matchingNumbersOfCandidates.Values.Max(); //int candidateId = matchingNumbersOfCandidates.Where((key, value) => value == maxMatchingNumber).First().Key; } } catch (Exception) { // TODO: write to log } finally { isRunning = false; } } }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { String x = "b"; long FindCompany = 1; var CheckCompanyExist = x; var CheckUserExist = await _userManager.FindByEmailAsync("IRecruiterUserI" + model.Email); CheckCompanyExist = _context.AppJobRecruitersCompany.Where(f => f.CompanyName == model.CompanyName).Select(c => c.CompanyName).FirstOrDefault(); @ViewData["Message"] = "Model valid"; var CompanyInfo = new AppJobRecruitersCompany { CompanyName = model.CompanyName, CompanySize = model.CompanySize, CompanyInfo = model.CompanyInfo, CompanyDateCreated = DateTime.Now, CompanyDateUpdated = DateTime.Now, CompanyActiveStatus = true, CompanyMaxUsers = 2, CompanyPublishFrom = DateTime.Now, CompanyPublishTo = DateTime.Now, CompanyPoints = 0, }; if (CheckCompanyExist == null) { if (CheckUserExist == null) { _context.AppJobRecruitersCompany.Add(CompanyInfo); await _context.SaveChangesAsync(); FindCompany = _context.AppJobRecruitersCompany.Where(v => v.CompanyName == model.CompanyName).Select(c => c.CompanyIdd).FirstOrDefault(); } else { ModelState.AddModelError(string.Empty, "Email đã đăng ký trên hệ thống"); return(View(model)); } } else { ModelState.AddModelError(string.Empty, "Tên công ty đã đăng ký trên hệ thống"); return(View(model)); } var user = new RecruiterUser { FullName = model.FullName, UserName = "******" + model.Email, Email = "IRecruiterUserI" + model.Email, NormalizedUserName = "******" + model.Email, NormalizedEmail = "IRecruiterUserI" + model.Email, PhoneNumber = model.PhoneNumber, DateCreated = DateTime.Now, DateUpdated = DateTime.Now, LastLoginDate = DateTime.Now, PasswordChangeDate = DateTime.Now, Birthday = Convert.ToDateTime("01/01/2000"), //SecurityStamp = Guid.NewGuid().ToString() PhoneDesk = model.PhoneDesk, Fax = model.Fax, Address = model.Address, City = model.City, Nation = model.Nation, Position = model.Position, PublishFrom = DateTime.Now, PublishTo = DateTime.Now, CompanyIdd = Convert.ToInt64(FindCompany), }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, "Recruiter"); _logger.LogInformation("User created a new account with password."); // Lấy token xác nhận tài khoản var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); // Gọi UrlHelperExtensions.cs lấy được chuỗi dẫn đến AccountController.ConfirmEmail var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); // Gửi mail chuỗi callbackUrl gọi hàm AccountController.ConfirmEmail await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); //await _signInManager.SignInAsync(user, isPersistent: false); //isPersistent _logger.LogInformation("User created a new account with password."); //return RedirectToLocal(returnUrl); ViewData["EmailConfirm"] = model.Email; return(View("SendingEmailConfirm", new SendingEmailConfirmViewModel { Email = model.Email, })); } AddErrors(result); } else { @ViewData["Message"] = "Invalid!!!"; } //Định nghĩa isPersistent //Persistent cookies will be saved as files in the browser folders until they either expire or manually deleted. //This will cause the cookie to persist even if you close the browser. //If IsPersistent is set to false, the browser will acquire session cookie which gets cleared when the browser is closed // If we got this far, something failed, redisplay form return(View(model)); }