Example #1
0
        public async Task <string> AddEmployer(UpdateClientViewModal user)
        {
            var UId      = Guid.NewGuid();
            var objectId = ObjectId.GenerateNewId().ToString();
            // hash password
            var passHash = _encryptPassword.CreateHash(Guid.NewGuid().ToString());//random temperory password

            var login = new Login()
            {
                Id                     = objectId,
                UId                    = UId,
                Username               = user.Email,
                PasswordHash           = passHash,
                IsDisabled             = false,
                EmailAddressAuthorized = false,
                ExpiredOn              = DateTime.UtcNow.AddHours(24),
                PasswordFormat         = PBKDF2_ITERATIONS,
                TermsAccepted          = false,//get employers to accept it when they login to verify email
                AccountLocked          = true
            };

            var newEmployer = new Employer()
            {
                Id        = objectId,
                CreatedOn = DateTime.UtcNow,
                IsDeleted = false,
                UId       = UId,
                Login     = login
            };

            newEmployer.CompanyContact.Email = user.Email;
            newEmployer.CompanyContact.Name  = user.CompanyName;

            await _employerRepository.Add(newEmployer);

            return(newEmployer.Id);
        }
Example #2
0
        public async Task <IActionResult> AddNewClient([FromBody] UpdateClientViewModal command)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { Success = false, Message = "Parameter can not be null" }));
                }

                string EmployerId = "";
                if (command.ClientId == null)
                {
                    //add client
                    command.Email = command.Email.ToLower();

                    //check if username is unique
                    bool isUniqueEmail = await _authenticationService.UniqueEmail(command.Email);

                    if (!isUniqueEmail)
                    {
                        return(Json(new { Success = false, Message = "This email is currently in use" }));
                    }

                    EmployerId = await _authenticationService.AddEmployer(command);

                    var newClient = (await _authenticationService.AddEmployerAsClientAsync(EmployerId, _userAppContext.CurrentUserId));

                    return(Json(new { Success = true, Message = "Successful", newClient }));
                }
                return(Json(new { Success = false, Message = "OOPS! Something Went Wrong" }));
            }
            catch (ApplicationException e)
            {
                return(Json(new { IsSuccess = false, e.Message }));
            }
        }