public IPersonAliasModel Create(IPersonAliasModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateIDIsNull(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Search for an Existing Record (Don't allow Duplicates
            var results = Search(PersonAliasMapper.MapToSearchModel(model));

            if (results.Any())
            {
                return(results.First());
            }                                              // Return the first that matches
            // Map model to a new entity
            var newEntity = PersonAliasMapper.MapToEntity(model);

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            PersonAliasesRepository.Add(newEntity);
            // Try to Save Changes
            PersonAliasesRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
예제 #2
0
        public void Verify_MapToSearchModel_AssignsPersonAliasSearchProperties()
        {
            // Arrange
            var mapper = new PersonAliasMapper();
            var model  = PersonAliasesMockingSetup.DoMockingSetupForPersonAliasModel();
            // Act
            var searchModel = mapper.MapToSearchModel(model.Object);

            // Assert
            Assert.Equal(model.Object.PersonId, searchModel.PersonId);
            Assert.Equal(model.Object.Person?.CustomKey, searchModel.PersonCustomKey);
            Assert.Equal(model.Object.Person?.ApiDetailUrl, searchModel.PersonApiDetailUrl);
            Assert.Equal(model.Object.Person?.SiteDetailUrl, searchModel.PersonSiteDetailUrl);
            Assert.Equal(model.Object.Person?.Name, searchModel.PersonName);
            Assert.Equal(model.Object.Person?.ShortDescription, searchModel.PersonShortDescription);
            Assert.Equal(model.Object.Person?.Description, searchModel.PersonDescription);
        }
 public void Verify_MapToSearchModel_AssignsPersonAliasSearchProperties()
 {
     // Arrange
     var mapper = new PersonAliasMapper();
     var model = PersonAliasesMockingSetup.DoMockingSetupForPersonAliasModel();
     // Act
     var searchModel = mapper.MapToSearchModel(model.Object);
     // Assert
     Assert.Equal(model.Object.PersonId, searchModel.PersonId);
     Assert.Equal(model.Object.Person?.CustomKey, searchModel.PersonCustomKey);
     Assert.Equal(model.Object.Person?.ApiDetailUrl, searchModel.PersonApiDetailUrl);
     Assert.Equal(model.Object.Person?.SiteDetailUrl, searchModel.PersonSiteDetailUrl);
     Assert.Equal(model.Object.Person?.Name, searchModel.PersonName);
     Assert.Equal(model.Object.Person?.ShortDescription, searchModel.PersonShortDescription);
     Assert.Equal(model.Object.Person?.Description, searchModel.PersonDescription);
 }