Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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));
        }