public void TestSaveContractor()
        {
            Repository.SaveNewContractorAccount(NewContractorAccount);
            ContractorAccount savedAccount = Repository.FindContractorAccount("*****@*****.**");

            Assert.NotNull(savedAccount);
        }
        public IActionResult RegisterContractor([FromForm] ContractorAccount contractor)
        {
            IActionResult response;

            if (ModelState.IsValid)
            {
                bool AccountExist = ContractorAccountRepository.CheckIfAccountExist(contractor.EmailAddress);

                EmailValidator EmailValidator = new EmailValidator();

                bool isEmailValid = EmailValidator.IsValidEmail(contractor.EmailAddress);

                if (AccountExist == true || (isEmailValid == false))
                {
                    string errorMessage = "This email address is already in use or invalid";
                    response = BadRequest(new { error = errorMessage });
                }
                else
                {
                    PasswordManager PasswordManager = new PasswordManager();

                    string encryptedPassword = PasswordManager.GeneratePassword(contractor.Password);

                    contractor.Password = encryptedPassword;

                    ContractorAccountRepository.MarkAsModified(contractor);

                    string userToken = BuildUserIdentity(contractor);

                    ContractorAccountRepository.SaveNewContractorAccount(contractor);

                    CreateContractorProfile(contractor);

                    var jsonResponse = new {
                        user = new {
                            account = contractor.EmailAddress,
                            token   = userToken,
                            role    = "contractor"
                        }
                    };

                    response = Ok(jsonResponse);
                }
                return(response);
            }
            else
            {
                return(new BadRequestObjectResult(ModelState));
            }
        }