Пример #1
0
        public Provider EnlistProvider(ProviderInfo providerInfo, Guid practiceId)
        {
            var person   = Find(providerInfo.PersonNameInfo);
            var provider = Provider.Create(providerInfo, practiceId);

            if (null == person)
            {
                person = Person.CreateProvider(providerInfo);

                var newProvider = person.AssignProvider(provider);

                _personRepository.InsertOrUpdate(person);
                _personRepository.Save();
                _providerRepository.InsertOrUpdate(newProvider);
                _providerRepository.Save();
                return(newProvider);
            }

            var personName = PersonName.Create(providerInfo.PersonNameInfo);

            var updatedNames   = person.AssignName(personName);
            var updateProvider = person.AssignProvider(provider);

            _personNameRepository.InsertOrUpdate(updatedNames);
            _personNameRepository.Save();
            _providerRepository.InsertOrUpdate(updateProvider);
            _providerRepository.Save();

            return(updateProvider);
        }
        public async Task Create(string firstName, string lastName, int age, int suffixId)
        {
            var            firstNameResult = Name.Create(firstName);
            var            lastNameResult  = Name.Create(lastName);
            var            ageResult       = Age.Create(age);
            Maybe <Suffix> maybeSuffix     = Suffix.FromId(suffixId);

            await Result
            .Combine(firstNameResult, lastNameResult, ageResult)
            .Bind(() => PersonName.Create(firstNameResult.Value, lastNameResult.Value, maybeSuffix.Value))
            .Bind(personName => Person.Create(personName, ageResult.Value))
            .Tap(person => _repository.Save(person))
            .Tap(() => _unitOfWork.CommitAsync())
            .Tap(() => _logger.LogInformation($"Person was stored to db: {firstName} {lastName}"))
            .OnFailure(error => _logger.LogError(error));

            /*
             * var firstNameResult = Name.Create(firstName);
             * var lastNameResult = Name.Create(lastName);
             * var ageResult = Age.Create(age);
             * var personName = PersonName.Create(firstNameResult.Value, lastNameResult.Value);
             * var personResult = Person.Create(personName.Value, ageResult.Value);
             *
             * _repository.Save(personResult.Value);
             * await _unitOfWork.CommitAsync();
             */
        }
        public async Task Rename(int personId, string firstName, string lastName, int suffixId)
        {
            var            firstNameResult = Name.Create(firstName);
            var            lastNameResult  = Name.Create(lastName);
            Maybe <Suffix> maybeSuffix     = Suffix.FromId(suffixId);

            await Result
            .Combine(firstNameResult, lastNameResult, maybeSuffix.ToResult("Suffix is null."))
            .Bind(() => _repository
                  .GetByIdAsync(personId)
                  .ToResult($"Person was not found for ID: {personId}"))
            .Bind(person => PersonName
                  .Create(firstNameResult.Value, lastNameResult.Value, maybeSuffix.Value)
                  .Tap(personName => person.Rename(personName)))
            .Tap(() => _unitOfWork.CommitAsync())
            .Tap(() => _logger.LogInformation($"Person was renamed to {maybeSuffix.Value} {firstName} {lastName}"))
            .OnFailure(error => _logger.LogError(error));

            /*
             * var firstNameResult = Name.Create(firstName);
             * var lastNameResult = Name.Create(lastName);
             * var personNameResult = PersonName.Create(firstNameResult.Value, lastNameResult.Value);
             *
             * var maybePerson = await _repository.GetById(personId);
             * maybePerson.Value.Rename(personNameResult.Value);
             */
        }
Пример #4
0
        public async Task ShouldUpdate_EmployeeContactPerson_UsingRepo()
        {
            var employee = await _employeeRepo.GetByIdAsync(new Guid("4b900a74-e2d9-4837-b9a4-9e828752716e"));

            var contact = (from item in employee.ContactPersons()
                           where item.Id.Equals(2)
                           select item).SingleOrDefault();

            Assert.Equal("Steve", contact.ContactName.FirstName);
            Assert.Equal("Harvey", contact.ContactName.LastName);
            Assert.Equal("972-854-5688", contact.Telephone);

            employee.UpdateContactPerson
            (
                contact.Id,
                PersonName.Create("Bubba", "Smith", "C"),
                PhoneNumber.Create("987-965-1234"),
                "You have been updated"
            );
            _employeeRepo.Update(employee);
            await _unitOfWork.Commit();

            var result = (from item in employee.ContactPersons()
                          where item.Id.Equals(2)
                          select item).SingleOrDefault();

            Assert.Equal("Bubba", result.ContactName.FirstName);
            Assert.Equal("987-965-1234", result.Telephone);
            Assert.Equal("You have been updated", result.Notes);
        }
Пример #5
0
        public User EnlistUser(UserInfo userInfo, Guid practiceId)
        {
            var person = Find(userInfo.PersonNameInfo);
            var user   = User.Create(userInfo, practiceId);

            if (null == person)
            {
                person = Person.CreateUser(userInfo);

                var newUser = person.AssignUser(user);

                _personRepository.InsertOrUpdate(person);
                _personRepository.Save();
                _userRepository.InsertOrUpdate(newUser);
                _userRepository.Save();
                return(newUser);
            }

            var personName = PersonName.Create(userInfo.PersonNameInfo);

            var updatedNames = person.AssignName(personName);
            var updateUser   = person.AssignUser(user);

            _personNameRepository.InsertOrUpdate(updatedNames);
            _personNameRepository.Save();
            _userRepository.InsertOrUpdate(updateUser);
            _userRepository.Save();

            return(updateUser);
        }
Пример #6
0
        public async Task ShouldInsert_ExternalAgentAndEmployee()
        {
            Guid id = Guid.NewGuid();

            Employee employee = new Employee
                                (
                new ExternalAgent(id, AgentType.Employee),
                SupervisorId.Create(id),
                PersonName.Create("George", "Orwell", "J"),
                SSN.Create("623789999"),
                PhoneNumber.Create("817-987-1234"),
                MaritalStatus.Create("M"),
                TaxExemption.Create(5),
                PayRate.Create(40.00M),
                StartDate.Create(new DateTime(1998, 12, 2)),
                IsActive.Create(true)
                                );

            await _employeeRepo.AddAsync(employee);

            await _unitOfWork.Commit();

            var employeeResult = await _employeeRepo.Exists(employee.Id);

            Assert.True(employeeResult);
        }
Пример #7
0
        private static Nomination LoadSuperStarAwardsNominationFromSurveyExport(Row row, int rowNumber)
        {
            var isAnonymousNominator            = row[10] != @"Display My Name (Recommended)";
            var nominatorName                   = PersonName.CreateForNominator(row[9], isAnonymousNominator);
            var nomineeName                     = PersonName.Create(row[12]);
            var awardType                       = AwardType.SuperStar;
            var nomineeOfficeLocation           = OfficeLocation.FindByName(row[14]);
            var hasContinuouslyImproving        = !string.IsNullOrWhiteSpace(row[15]);
            var hasDrivingInnovation            = !string.IsNullOrWhiteSpace(row[16]);
            var hasDelightingCustomers          = !string.IsNullOrWhiteSpace(row[17]);
            var hasBehavingWithIntegrity        = !string.IsNullOrWhiteSpace(row[18]);
            var hasDeliveringMeaningfulOutcomes = !string.IsNullOrWhiteSpace(row[19]);
            var hasStreamingGood                = !string.IsNullOrWhiteSpace(row[20]);
            var writeUp        = NominationWriteUp.Create(nomineeName, row[21]);
            var writeUpSummary = NominationWriteUpSummary.NotApplicable;

            var companyValues = GetCompanyValues(hasContinuouslyImproving, hasDrivingInnovation, hasDelightingCustomers,
                                                 hasBehavingWithIntegrity, hasDeliveringMeaningfulOutcomes, hasStreamingGood);

            var nominee = Person.Create(nomineeName, nomineeOfficeLocation, nomineeName.DerivedEmailAddress);

            var nomination = new Nomination(rowNumber, NomineeVotingIdentifier.Unknown, nominee, awardType,
                                            nominatorName, companyValues, writeUp, writeUpSummary);

            return(nomination);
        }
Пример #8
0
 public static Person GetPersonWithoutId()
 {
     return(new Person(
                surrogateId: Option.None <string>(),
                firstName: PersonFirstName.Create("firstname").Value,
                name: PersonName.Create("name").Value,
                email: PersonEmail.Create("*****@*****.**").Value));
 }
Пример #9
0
 public static Person GetPerson(Option <PersonFirstName> firstName, Option <PersonName> name, Option <PersonEmail> email)
 {
     return(new Person(
                surrogateId: Option.None <string>(),
                firstName: firstName.ValueOr(PersonFirstName.Create("firstname").Value),
                name: name.ValueOr(PersonName.Create("name").Value),
                email: email.Else(Option.None <PersonEmail>())));
 }
 public static Person ToBusinessObject(this CreatePersonModel model)
 {
     return new Person(
         surrogateId: Option.None<string>(),
         firstName: PersonFirstName.Create(model.FirstName).Value,
         name: PersonName.Create(model.Name).Value,
         email: PersonEmail.Create(model.Email).Value);
 }
 public static Person ToBusiness(this PersonEntity personEntity)
 {
     return(new Person(
                surrogateId: Option.Some(personEntity.Id),
                firstName: PersonFirstName.Create(personEntity.FirstName).Value,
                name: PersonName.Create(personEntity.Name).Value,
                email: PersonEmail.Create(personEntity.Email).Value));
 }
Пример #12
0
        public async Task <IActionResult> CreateNewCandidate(CreateNewCandidateRequest request)
        {
            var newPersonName    = PersonName.Create(request.firstName, request.lastName);
            var newCandidate     = new Candidate(newPersonName);
            var createdCandidate = await _candidateService.CreateCandidate(newCandidate);

            return(CreatedAtAction(nameof(GetCandidateById), new { id = createdCandidate.Id }, createdCandidate));
        }
        public static Result Evaluate(this CreatePersonModel model)
        {
            var firstName = PersonFirstName.Create(model.FirstName);
            var name = PersonName.Create(model.Name);
            var email = PersonEmail.Create(model.Email);

            return Result.Combine(firstName, name, email);
        }
Пример #14
0
 private Person GetDefaultPerson()
 {
     return(new Person(
                Option.None <string>(),
                firstName: PersonFirstName.Create("firstname").Value,
                name: PersonName.Create("name").Value,
                email: PersonEmail.Create("*****@*****.**").Value
                ));
 }
Пример #15
0
        internal AwardWinner ToAwardWinner()
        {
            var awardType = ValueObjects.AwardType.FindByAwardName(AwardType);

            var person = Person.Create(PersonName.Create(Name),
                                       ValueObjects.OfficeLocation.FindByName(OfficeLocation),
                                       ValueObjects.EmailAddress.Create(EmailAddress));

            return(new AwardWinner(awardType, person));
        }
Пример #16
0
        public void ShouldRaiseError_FirstNameTooLong()
        {
            var    first = "Joe123456789saaadaadddaaaaaaaaaaaaaeeeeeeessssss";
            string last  = "Blow";
            var    mi    = "Z";

            Action action = () => PersonName.Create(first, last, mi);

            var caughtException = Assert.Throws <ArgumentOutOfRangeException>(action);

            Assert.Contains("Maximum length of the first name is 25 characters.", caughtException.Message);
        }
Пример #17
0
        private void SeedWithFakeData()
        {
            var existingCandidates = new List <Candidate>
            {
                new Candidate(1, PersonName.Create("Joe", "Biden"), null),
                new Candidate(2, PersonName.Create("Abraham", "Lincoln"), null),
                new Candidate(3, PersonName.Create("Richard", "Nixon"), null),
            };

            Candidates.AddRange(existingCandidates);
            SaveChanges();
        }
        public void ShouldRaiseError_AddingContactPersonWithNullTelephoneToEmployee()
        {
            var employee = GetEmployee();
            var name     = PersonName.Create("Fidel", "Castro", null);
            var notes    = "You are being tested.";

            Action action = () => employee.AddContactPerson(1, name, null, notes);

            var caughtException = Assert.Throws <ArgumentNullException>(action);

            Assert.Contains("The contact person telephone number is required.", caughtException.Message);
        }
Пример #19
0
        public void ShouldRaiseError_NullLastName()
        {
            var    first = "Joe";
            string last  = null;
            var    mi    = "Z";

            Action action = () => PersonName.Create(first, last, mi);

            var caughtException = Assert.Throws <ArgumentNullException>(action);

            Assert.Equal("A last name is required.", caughtException.ParamName);
        }
Пример #20
0
        public void ShouldRaiseError_MiddleInitialTooLong()
        {
            var    first = "Joe";
            string last  = "Blow";
            var    mi    = "ZZ";

            Action action = () => PersonName.Create(first, last, mi);

            var caughtException = Assert.Throws <ArgumentOutOfRangeException>(action);

            Assert.Contains("Maximum length of middle initial is 1 character.", caughtException.Message);
        }
Пример #21
0
        public void EmailCanBeEmpty()
        {
            //Init
            var firstName = Option.Some(PersonFirstName.Create("firstname").Value);
            var name      = Option.Some(PersonName.Create("name").Value);
            var email     = Option.None <PersonEmail>();

            //Act
            var person = GetPerson(firstName, name, email);

            //Assert
            Check.That(person.Email.HasValue).IsFalse();
        }
Пример #22
0
        public void NameShouldBeTheSameAsConstructorParameter()
        {
            //Init
            var firstName = Option.None <PersonFirstName>();
            var name      = Option.Some(PersonName.Create("name").Value);
            var email     = Option.None <PersonEmail>();

            //Act
            var person = GetPerson(firstName, name, email);

            //Assert
            Check.That <string>(person.Name).Equals("name");
        }
        public void ShouldAdd_ContactPersonToEmployee()
        {
            var employee = GetEmployee();
            var name     = PersonName.Create("Fidel", "Castro", null);
            var phone    = PhoneNumber.Create("555-555-5555");
            var notes    = "You are being tested.";

            employee.AddContactPerson(1, name, phone, notes);

            var count = employee.ContactPersons().Count;

            Assert.Equal(1, count);
        }
Пример #24
0
        public void ShouldReturn_Valid_PersonName_WithNullMiddleInitial()
        {
            string first = "Joe";
            string last  = "Blow";
            string mi    = null;

            var result = PersonName.Create(first, last, mi);

            Assert.IsType <PersonName>(result);
            Assert.Equal(first, result.FirstName);
            Assert.Equal(last, result.LastName);
            Assert.Equal(mi, result.MiddleInitial);
        }
        public void ShouldRaiseError_AddingDuplicateContactPersonToEmployee()
        {
            var employee = GetEmployee();
            var name     = PersonName.Create("Fidel", "Castro", null);
            var phone    = PhoneNumber.Create("555-555-5555");
            var notes    = "You are being tested.";

            employee.AddContactPerson(1, name, phone, notes);

            Action action = () => employee.AddContactPerson(2, name, phone, notes);

            var caughtException = Assert.Throws <InvalidOperationException>(action);

            Assert.Contains("We already have this contact person.", caughtException.Message);
        }
Пример #26
0
        public void FirstNameShouldNotBeNull()
        {
            PersonFirstName firstName = null;

            Action action = () =>
            {
                new Person(
                    surrogateId: Option.None <string>(),
                    firstName: firstName,
                    name: PersonName.Create("name").Value,
                    email: PersonEmail.Create("*****@*****.**").Value
                    );
            };

            Check.ThatCode(action).Throws <ArgumentException>();
        }
Пример #27
0
 private Result MapCustomer(Maybe <CustomerEntity> customer, CustomerDetailsViewModel viewModel)
 {
     if (customer.HasNoValue)
     {
         return(Result.Fail(new Dictionary <string, object>()
         {
             { nameof(customer.Value), customer.Value }
         }));
     }
     viewModel.FullName     = PersonName.Create(customer).Value;
     viewModel.DateOfBirth  = CustomerDateOfBirth.Create(customer.Value.DateOfBirth, viewModel.Configuration?.Format).Value;
     viewModel.Address      = PostalAddress.Create(customer.Value.PostalAddress).Value;
     viewModel.MobileNumber = customer.Value.MobileNumber;
     viewModel.HomeNumber   = customer.Value.HomeNumber;
     viewModel.EmailAddress = customer.Value.EmailAddress;
     return(Result.Ok());
 }
Пример #28
0
        public async Task ShouldUpdate_Employee_UsingRepository()
        {
            var employee = await _employeeRepo.GetByIdAsync(new Guid("4b900a74-e2d9-4837-b9a4-9e828752716e"));

            Assert.Equal("Ken", employee.EmployeeName.FirstName);
            Assert.Equal("Sanchez", employee.EmployeeName.LastName);

            employee.UpdateEmployeeName(PersonName.Create("Lil", "Wayne", null));

            _employeeRepo.Update(employee);
            await _unitOfWork.Commit();

            var updatedEmployee = await _employeeRepo.GetByIdAsync(new Guid("4b900a74-e2d9-4837-b9a4-9e828752716e"));

            Assert.Equal("Lil", updatedEmployee.EmployeeName.FirstName);
            Assert.Equal("Wayne", updatedEmployee.EmployeeName.LastName);
        }
Пример #29
0
        public async Task <IActionResult> AddVoteToElection(AddVoteToElectionRequest request)
        {
            var Voter = PersonName.Create(request.firstName, request.lastName);

            Election election = await _electionService.AddVoteToElection(request.ElectionId, request.CandidateId, Voter);

            var currentCandidacy = election.Candidacies.First(x => x.Candidate.Id == request.CandidateId);
            var response         = new VoteAddedToElectionResponse
            {
                ElectionId  = request.ElectionId,
                CandidateId = request.CandidateId,
                VoterName   = Voter,
                TotalVotes  = currentCandidacy.Ballots.Count()
            };

            return(Ok(response));
        }
Пример #30
0
        public async Task ShouldAdd_ContactPersonToEmployee_UsingRepo()
        {
            var employee = await _employeeRepo.GetByIdAsync(new Guid("4b900a74-e2d9-4837-b9a4-9e828752716e"));

            var originalContactCount = employee.ContactPersons().Count;

            var name  = PersonName.Create("Fidel", "Castro", null);
            var phone = PhoneNumber.Create("555-555-5555");
            var notes = "You are being tested.";

            employee.AddContactPerson(0, name, phone, notes);
            _employeeRepo.Update(employee);
            await _unitOfWork.Commit();

            var count = employee.ContactPersons().Count;

            Assert.Equal(originalContactCount + 1, count);
        }