Exemplo n.º 1
0
        public void SetupContractorAccounts()
        {
            TrueContractor = new ContractorAccount
            {
                EmailAddress = "*****@*****.**",
                Password     = "******",
                FirstName    = "James",
                LastName     = "Bond"
            };

            FalseEmailContractor = new ContractorAccount
            {
                EmailAddress = "agsdzs",
                Password     = "******",
                FirstName    = "Jason",
                LastName     = "Bourne"
            };

            ExistingContractor = new ContractorAccount
            {
                EmailAddress = "*****@*****.**",
                Password     = "******",
                FirstName    = "Jason",
                LastName     = "Bourne"
            };
        }
        public void DeleteContractorAccount(string emailAddress)
        {
            ContractorAccount userToDelete = FindContractorAccount(emailAddress);

            DbContext.ContractorAccounts.Remove(userToDelete);
            DbContext.SaveChanges();
        }
        public void TestSaveContractor()
        {
            Repository.SaveNewContractorAccount(NewContractorAccount);
            ContractorAccount savedAccount = Repository.FindContractorAccount("*****@*****.**");

            Assert.NotNull(savedAccount);
        }
        private void CreateContractorProfile(ContractorAccount contractorAccount)
        {
            ContractorProfile ContractorProfile = new ContractorProfile
            {
                EmailAddress = contractorAccount.EmailAddress,
                FirstName    = contractorAccount.FirstName,
                LastName     = contractorAccount.LastName
            };

            ContractorProfileRepository.SaveNewContractorProfile(ContractorProfile);
        }
        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));
            }
        }
 public void MarkAsModified(ContractorAccount contractorAccount)
 {
     DbContext.Entry(contractorAccount).State = EntityState.Modified;
 }
        public ContractorAccount FindContractorAccount(string emailAddress)
        {
            ContractorAccount contractor = DbContext.ContractorAccounts.Find(emailAddress);

            return(contractor);
        }
 public void SaveNewContractorAccount(ContractorAccount contractorAccount)
 {
     DbContext.ContractorAccounts.Add(contractorAccount);
     DbContext.SaveChanges();
 }
Exemplo n.º 9
0
        public ContractorRegistrationPageViewModel(
            INavigationService navigationService,
            IAnalyticService analyticService) : base(navigationService)
        {
            Title = "Contractor";
            analyticService.TrackScreen(
                "registration-page",
                new Dictionary <string, string>
            {
                { "registration-type", "contractor" }
            });

            // store the fields in an enumerable for easy use later on in this class
            _validatableFields = new IValidity[]
            {
                CompanyName,
                CompanyEmail,
                CompanyUrl,
                AddressLineOne,
                AddressLineTwo,
                City,
                State,
                Zip,
                PrimaryPhone,
                SecondaryPhone,
                SocialNetwork1,
                SocialNetwork2,
                SocialNetwork3,
                PrimaryContact
            };

            AddValidationRules();

            NavigatingTo
            .Where(args => args.ContainsKey("user_id"))
            .Select(args => args["user_id"].ToString())
            .BindTo(this, x => x._userId);

            Next = ReactiveCommand.CreateFromTask(async() =>
            {
                if (!IsValid())
                {
                    return;
                }

                var contractor = new ContractorAccount
                {
                    AccountId    = _userId,
                    EmailAddress = CompanyEmail.Value,
                    CompanyName  = CompanyName.Value,
                    CompanyUrl   = CompanyUrl.Value,

                    //PrimaryContact = PrimaryContact.Value,
                    PhoneNumber = PrimaryPhone.Value,

                    //SecondaryPhoneNumber = SecondaryPhone.Value,
                    //PhysicalAddress = new Models.Address
                    //{
                    //    Address1 = AddressLineOne.Value,
                    //    Address2 = AddressLineTwo.Value,
                    //    City = City.Value,
                    //    State = State.Value,
                    //    PostalCode = Zip.Value
                    //},
                    //SocialNetwork1 = SocialNetwork1.Value,
                    //SocialNetwork2 = SocialNetwork2.Value,
                    //SocialNetwork3 = SocialNetwork3.Value
                };

                // TODO: ...
                await navigationService.NavigateAsync(
                    nameof(TradeSpecialtiesPage),
                    new NavigationParameters {
                    { "account", contractor }
                }).ConfigureAwait(false);
            });
        }
 public ContractorAccountRepositoryTests()
 {
     Repository           = new ContractorAccountRepository(DissertationContext);
     NewContractorAccount = new ContractorAccount(ExampleEmailAddress, "IAmAContractor", "John", "Doe");
 }