public IVolumeLocationModel Create(IVolumeLocationModel 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(VolumeLocationMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = VolumeLocationMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it VolumeLocationsRepository.Add(newEntity); // Try to Save Changes VolumeLocationsRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_MapToSearchModel_AssignsVolumeLocationSearchProperties() { // Arrange var mapper = new VolumeLocationMapper(); var model = VolumeLocationsMockingSetup.DoMockingSetupForVolumeLocationModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert Assert.Equal(model.Object.VolumeId, searchModel.VolumeId); Assert.Equal(model.Object.Volume?.CustomKey, searchModel.VolumeCustomKey); Assert.Equal(model.Object.Volume?.ApiDetailUrl, searchModel.VolumeApiDetailUrl); Assert.Equal(model.Object.Volume?.SiteDetailUrl, searchModel.VolumeSiteDetailUrl); Assert.Equal(model.Object.Volume?.Name, searchModel.VolumeName); Assert.Equal(model.Object.Volume?.ShortDescription, searchModel.VolumeShortDescription); Assert.Equal(model.Object.Volume?.Description, searchModel.VolumeDescription); Assert.Equal(model.Object.LocationId, searchModel.LocationId); Assert.Equal(model.Object.Location?.CustomKey, searchModel.LocationCustomKey); Assert.Equal(model.Object.Location?.ApiDetailUrl, searchModel.LocationApiDetailUrl); Assert.Equal(model.Object.Location?.SiteDetailUrl, searchModel.LocationSiteDetailUrl); Assert.Equal(model.Object.Location?.Name, searchModel.LocationName); Assert.Equal(model.Object.Location?.ShortDescription, searchModel.LocationShortDescription); Assert.Equal(model.Object.Location?.Description, searchModel.LocationDescription); }