private ERAUserModel RegisterNewUser(ERAUserModel userModel) { ERAUserModel user = null; var userRepo = unitOfWork.GetRepository <OnlineAssessmentUser>(); var userTypeID = (int)userModel.UserTypeId; if (userTypeID == 0 && !string.IsNullOrEmpty(userModel.UserType)) { userTypeID = GetUserTypeIDByType(userModel.UserType); } else { userModel.UserType = GetUserTypeByID(userTypeID); } if (userTypeID != -1) { userModel.UserTypeId = Convert.ToByte(userTypeID); var newUser = DataToDomain.MapERAUserModelToUser(userModel); userRepo.Insert(newUser); unitOfWork.Save(); user = DataToDomain.MapUserToERAUserModel(newUser); user.UserType = userModel.UserType; } return(user); }
private UserModel RegisterNewUser(UserModel userModel) { UserModel user = null; var userRepo = unitOfWork.GetRepository <User>(); var jobID = (int)userModel.JobID; if (jobID == 0 && !string.IsNullOrEmpty(userModel.JobTitle)) { jobID = GetJobIDByTitle(userModel.JobTitle); } else { userModel.JobTitle = GetJobByID(jobID); } if (jobID != -1) { userModel.JobID = Convert.ToByte(jobID); var newUser = DataToDomain.MapUserModelToUser(userModel); //newUser.UserActive = 1; userRepo.Insert(newUser); unitOfWork.Save(); user = DataToDomain.MapUserToUserModel(newUser); user.JobTitle = userModel.JobTitle; } return(user); }
public async Task <ERAUserModel> ValidateUserCredential(ERAUserModel userModel) { ERAUserModel result = null; var userRepo = unitOfWork.GetRepository <OnlineAssessmentUser>(); var userTypeRepo = unitOfWork.GetRepository <UserType>(); var userRiskRepo = unitOfWork.GetRepository <UserRisk>(); var user = await Task.Run(() => userRepo.Get(x => x.Email == userModel.Email && x.Password == userModel.Password).FirstOrDefault()); if (user != null) { result = DataToDomain.MapUserToERAUserModel(user); var userType = await Task.Run(() => userTypeRepo.Get(x => x.UserTypeId == user.UserTypeId).FirstOrDefault()); if (userType != null) { result.UserType = userType.UserTypeName; } var userRisk = userRiskRepo.Get(x => x.UserId == user.UserId).ToList(); if (userRisk != null) { var latestTestEntry = userRisk.Select(x => new { x.AssesmentDate, x.TestIdentifier }).OrderByDescending(x => x.AssesmentDate).FirstOrDefault(); if (latestTestEntry != null) { result.IsTestTaken = true; result.LastAssessmentDate = latestTestEntry.AssesmentDate; result.LatestTestIdentifier = latestTestEntry.TestIdentifier; } //result.LastTestTakenOn = lastCompetency.RatingDate; } } return(result); }
public async Task <UserModel> ValidateUserCredential(UserModel userModel) { UserModel result = null; var userRepo = unitOfWork.GetRepository <User>(); var userCompRepo = unitOfWork.GetRepository <UserCompetencyMatrix>(); var jobRepo = unitOfWork.GetRepository <Job>(); var user = await Task.Run(() => userRepo.Get(x => x.UserEmail == userModel.UserEmail && x.UserPassword == userModel.UserPassword).FirstOrDefault()); if (user != null) { result = DataToDomain.MapUserToUserModel(user); var job = await Task.Run(() => jobRepo.Get(x => x.JobID == user.JobID).FirstOrDefault()); if (job != null) { result.JobTitle = job.JobTitle; } var lastCompetency = userCompRepo.Get(x => x.UserID == user.UserID).OrderByDescending(x => x.RatingDate).FirstOrDefault(); if (lastCompetency != null) { result.IsTestTaken = true; result.LastTestTakenOn = lastCompetency.RatingDate; } } return(result); }
public async Task <ERAUserRiskResponse> InsertUserRisks(ERAUserRiskWriteRequest request) { ERAUserRiskResponse response = null; List <UserRisk> userRisks = null; List <ERAUserRiskModel> userRisksModel = null; if (request != null && request.UserRisks.Any()) { var userRiskRepo = unitOfWork.GetRepository <UserRisk>(); userRisks = DataToDomain.MapERAUserRisksToUserRisks(request.UserRisks); await Task.Run(() => { try { userRiskRepo.InsertAll(userRisks); unitOfWork.Save(); } catch (Exception ex) { throw ex; } }); } if (userRisks != null && userRisks.Any()) { userRisksModel = DataToDomain.MapUserRisksToERAUserRisks(userRisks); response = new ERAUserRiskResponse() { UserRisks = userRisksModel, TotalRecords = userRisksModel.Count() }; } return(response); }
public async Task <Tuple <string, ERAUserModel, int> > GetUserProfile(ERAUserModel userModel) { ERAUserModel result = null; int status = 0; var message = ""; var userRepo = unitOfWork.GetRepository <OnlineAssessmentUser>(); if (userModel != null && userModel.UserId > 0) { var user = await Task.Run(() => userRepo.Get(x => x.UserId == userModel.UserId).FirstOrDefault()); if (user == null) { status = -1; message = "User does not exist!!"; result = userModel; } else { result = DataToDomain.MapUserToERAUserModel(user); if (result != null) { status = 1; message = "User profile found!!"; } } } return(new Tuple <string, ERAUserModel, int>(message, result, status)); }
public async Task <Tuple <string, List <ERAUserModel> > > GetERAUserReport(ERAReportRequest request) { List <ERAUserModel> response = null; var message = ""; var userRepo = unitOfWork.GetRepository <OnlineAssessmentUser>(); var userRiskRepo = unitOfWork.GetRepository <UserRisk>(); var users = await Task.Run(() => userRepo.Get(x => (string.IsNullOrEmpty(request.LastName) || x.LastName.Contains(request.LastName)) && (string.IsNullOrEmpty(request.Email) || x.Email.Contains(request.Email)) && (string.IsNullOrEmpty(request.CompanyName) || x.CompanyName.Contains(request.CompanyName))).ToList()); if (users.Any()) { var userTakenTest = userRiskRepo.Get().ToList(); if (userTakenTest != null) { response = new List <ERAUserModel>(); var userTakenTestIDs = request.TestIdentifier.HasValue ? userTakenTest.Select(x => new { x.UserId, x.TestIdentifier, x.AssesmentDate }).Where(x => x.TestIdentifier == request.TestIdentifier).Distinct().ToList() : userTakenTest.Select(x => new { x.UserId, x.TestIdentifier, x.AssesmentDate }).Distinct().ToList(); userTakenTestIDs.ForEach(x => { var user = users.FirstOrDefault(z => z.UserId == x.UserId); if (user != null) { response.Add(DataToDomain.MapUserToERAUserModel(user, true, x.AssesmentDate, x.TestIdentifier)); } }); message = "Found " + response.Count() + " records"; } } log.LogDebug(message); return(new Tuple <string, List <ERAUserModel> >(message, response)); }
private List <UserImage> InsertUserImages(List <ERAUserImageModel> userImages) { var insertMe = new List <UserImage>(); if (userImages.Any()) { var repo = unitOfWork.GetRepository <UserImage>(); insertMe = DataToDomain.MapERAUserImagesToUserImages(userImages); repo.InsertAll(insertMe); unitOfWork.Save(); userImages = DataToDomain.MapUserImagesToERAUserImages(insertMe); } return(insertMe); }
public async Task <Tuple <string, ERAUserModel, int> > UpdateUserProfile(ERAUserModel userModel) { ERAUserModel result = null; int status = 0; var message = ""; var userRepo = unitOfWork.GetRepository <OnlineAssessmentUser>(); if (userModel != null && userModel.UserId > 0) { var user = await Task.Run(() => userRepo.Get(x => x.UserId == userModel.UserId).FirstOrDefault()); if (user == null) { status = -1; message = "User does not exist!!"; result = userModel; } else { var userEmail = await Task.Run(() => userRepo.Get(x => x.UserId != userModel.UserId && x.Email == userModel.Email).FirstOrDefault()); if (userEmail == null) { user.CompanyName = userModel.CompanyName; user.Email = userModel.Email; user.EmployeeNumber = userModel.EmployeeNumber; user.FirstName = userModel.FirstName; user.LastName = userModel.LastName; user.Password = userModel.Password; userRepo.Update(user); unitOfWork.Save(); result = DataToDomain.MapUserToERAUserModel(user); if (result != null) { status = 1; message = "User profile updated successfully!!"; } } else { status = -2; message = "Email trying to update already exist.!!"; } } } log.LogDebug(message); return(new Tuple <string, ERAUserModel, int>(message, result, status)); }
public async Task <ERAQuestionResponse> GetQuestions(ERAQuestionRequest request) { ERAQuestionResponse response = null; List <ERAQuestionModel> questionsModel = null; var questionRepo = unitOfWork.GetRepository <Question>(); var questions = await Task.Run(() => questionRepo.Get(x => (x.RiskId == request.RiskID || request.RiskID == 0) && (x.QuestionId == request.QuestionID || request.QuestionID == 0)).ToList()); if (questions != null && questions.Any()) { questionsModel = DataToDomain.MapQuestionToERAQuestions(questions); response = new ERAQuestionResponse() { Questions = questionsModel, TotalRecords = questions.Count() }; } return(response); }
public async Task <ERARiskResponse> GetRisks(ERARiskRequest request) { ERARiskResponse response = null; List <ERARiskModel> risksModel = null; var riskRepo = unitOfWork.GetRepository <Risk>(); var risks = await Task.Run(() => riskRepo.Get(x => (x.RiskId == request.RiskID || request.RiskID == 0)).ToList()); if (risks != null && risks.Any()) { risksModel = DataToDomain.MapRisksToERARisks(risks); response = new ERARiskResponse() { Risks = risksModel, TotalRecords = risksModel.Count() }; } return(response); }
public async Task <ERAUserAnswerResponse> InsertUserAnswers(ERAUserAnswerWriteRequest request) { ERAUserAnswerResponse response = null; List <UserAnswer> userAnswers = null; List <ERAUserAnswerModel> answersModel = null; if (request != null && request.Answers.Any()) { var answersRepo = unitOfWork.GetRepository <UserAnswer>(); userAnswers = DataToDomain.MapERAUserAnswersToUserAnswers(request.Answers); await Task.Run(() => { try { answersRepo.InsertAll(userAnswers); unitOfWork.Save(); } catch (Exception ex) { throw ex; } }); } if (userAnswers != null && userAnswers.Any()) { foreach (var answer in request.Answers) { if (answer.UserImages != null && answer.UserImages.Any()) { answer.UserImages.ForEach(x => x.UserAnswerID = userAnswers.FirstOrDefault(z => z.QuestionId == answer.QuestionID).UserAnswerId); var userImages = InsertUserImages(answer.UserImages); userAnswers.Where(x => x.QuestionId == answer.QuestionID).Select(x => { x.UserImages = userImages; return(x); }).ToList(); } } answersModel = DataToDomain.MapUserAnswersToERAUserAnswers(userAnswers); response = new ERAUserAnswerResponse() { Answers = answersModel, TotalRecords = answersModel.Count() }; } return(response); }
public async Task <ERAUserRiskResponse> GetUserRisks(ERAUserRiskReadRequest request) { ERAUserRiskResponse response = null; List <ERAUserRiskModel> userRisksModel = null; var userRiskRepo = unitOfWork.GetRepository <UserRisk>(); var userRisks = await Task.Run(() => userRiskRepo.Get(x => (x.RiskId == request.RiskID || request.RiskID == 0) && (x.UserId == request.UserID || request.UserID == 0) && (x.TestIdentifier == request.TestIdentifier || request.TestIdentifier == null)).ToList()); if (userRisks != null && userRisks.Any()) { userRisksModel = DataToDomain.MapUserRisksToERAUserRisks(userRisks); response = new ERAUserRiskResponse() { UserRisks = userRisksModel, TotalRecords = userRisksModel.Count() }; } return(response); }
public async Task <ERAUserAnswerResponse> GetUserAnswers(ERAUserAnswerReadRequest request) { ERAUserAnswerResponse response = null; List <ERAUserAnswerModel> answersModel = null; var answersRepo = unitOfWork.GetRepository <UserAnswer>(); var answers = await Task.Run(() => answersRepo.Get(x => (x.RiskId == request.RiskID || request.RiskID == 0) && (x.QuestionId == request.QuestionID || request.QuestionID == 0) && (x.UserId == request.UserID || request.UserID == 0) && (x.TestIdentifier == request.TestIdentifier || request.TestIdentifier == null), includeProperties : "UserImages").ToList()); if (answers != null && answers.Any()) { answersModel = DataToDomain.MapUserAnswersToERAUserAnswers(answers); response = new ERAUserAnswerResponse() { Answers = answersModel, TotalRecords = answersModel.Count() }; } return(response); }
public async Task <Tuple <string, UserModel, int> > ValidateUserAndRegister(UserModel userModel) { UserModel result = null; int status = 0; var message = ""; var userRepo = unitOfWork.GetRepository <User>(); var user = await Task.Run(() => userRepo.Get(x => x.ID == userModel.ID).FirstOrDefault()); if (user != null) { var userEmail = await Task.Run(() => userRepo.Get(x => x.UserEmail == userModel.UserEmail).FirstOrDefault()); if (userEmail != null) { status = -1; message = "User already exist!!"; result = DataToDomain.MapUserToUserModel(userEmail); result.JobTitle = userModel.JobTitle; } else { result = RegisterNewUser(userModel); if (result != null) { status = 1; message = "User registered successfully!!"; } else { message = "No job found with title:" + userModel.JobTitle; } } } else { var userEmail = await Task.Run(() => userRepo.Get(x => x.UserEmail == userModel.UserEmail).FirstOrDefault()); if (userEmail != null) { status = -1; message = "User already exist!!"; result = DataToDomain.MapUserToUserModel(userEmail); result.JobTitle = userModel.JobTitle; } else { if (userModel.ID.Length >= 13) { var identityHelper = new IdentityHelper(userModel.ID); if (identityHelper.IsValid) { result = RegisterNewUser(userModel); if (result != null) { status = 1; message = "User registered successfully!!"; } else { message = "No job found with title:" + userModel.JobTitle; } } else { status = -2; message = "ID is Invalid!!"; result = userModel; } } else { result = RegisterNewUser(userModel); if (result != null) { status = 1; message = "User registered successfully!!"; } else { message = "No job found with title:" + userModel.JobTitle; } } } } log.LogDebug(message); return(new Tuple <string, UserModel, int>(message, result, status)); }
public async Task <Tuple <string, ERAUserModel, int> > ValidateUserAndRegister(ERAUserModel userModel) { ERAUserModel result = null; int status = 0; var message = ""; var userRepo = unitOfWork.GetRepository <OnlineAssessmentUser>(); var user = await Task.Run(() => userRepo.Get(x => x.UserId == userModel.UserId).FirstOrDefault()); if (user != null) { var userEmail = await Task.Run(() => userRepo.Get(x => x.Email == userModel.Email).FirstOrDefault()); if (userEmail != null) { status = -1; message = "User already exist!!"; result = DataToDomain.MapUserToERAUserModel(userEmail); result.UserType = userModel.UserType; } else { result = RegisterNewUser(userModel); if (result != null) { status = 1; message = "User registered successfully!!"; } else { message = "No user type found with user type name:" + userModel.UserType; } } } else { var userEmail = await Task.Run(() => userRepo.Get(x => x.Email == userModel.Email).FirstOrDefault()); if (userEmail != null) { status = -1; message = "User already exist!!"; result = DataToDomain.MapUserToERAUserModel(userEmail); result.UserType = userModel.UserType; } else { result = RegisterNewUser(userModel); if (result != null) { status = 1; message = "User registered successfully!!"; } else { message = "No user type found with user type name:" + userModel.UserType; } } } log.LogDebug(message); return(new Tuple <string, ERAUserModel, int>(message, result, status)); }