public ILocationModel Update(ILocationModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = LocationsRepository.Get(model.Id.Value); // Check if we would be applying identical information, if we are, just return the original // ReSharper disable once SuspiciousTypeConversion.Global if (LocationMapper.AreEqual(model, existingEntity)) { return(LocationMapper.MapToModel(existingEntity)); } // Map model to an existing entity LocationMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it LocationsRepository.Update(LocationMapper.MapToEntity(model)); // Try to Save Changes LocationsRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public void Verify_MapToModel_AssignsLocationProperties() { // Arrange var mapper = new LocationMapper(); var entity = LocationsMockingSetup.DoMockingSetupForLocation(); // Act var model = mapper.MapToModel(entity.Object); // Assert Assert.Equal(entity.Object.StartYear, model.StartYear); // Related Objects Assert.Equal(entity.Object.FirstIssueAppearanceId, model.FirstIssueAppearanceId); Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); // Associated Objects Assert.Equal(entity.Object.LocationAliases?.Count, model.LocationAliases?.Count); Assert.Equal(entity.Object.LocationAppearedInIssues?.Count, model.LocationAppearedInIssues?.Count); Assert.Equal(entity.Object.LocationIssues?.Count, model.LocationIssues?.Count); Assert.Equal(entity.Object.LocationMovies?.Count, model.LocationMovies?.Count); Assert.Equal(entity.Object.LocationStoryArcs?.Count, model.LocationStoryArcs?.Count); Assert.Equal(entity.Object.LocationVolumes?.Count, model.LocationVolumes?.Count); }
public ILocationModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(LocationMapper.MapToModel(LocationsRepository.Get(id))); }
public ILocationModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(LocationMapper.MapToModel(LocationsRepository.Get(key))); }