public IVolumeModel Update(IVolumeModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = VolumesRepository.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 (VolumeMapper.AreEqual(model, existingEntity)) { return(VolumeMapper.MapToModel(existingEntity)); } // Map model to an existing entity VolumeMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it VolumesRepository.Update(VolumeMapper.MapToEntity(model)); // Try to Save Changes VolumesRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public void Verify_MapToModel_AssignsVolumeProperties() { // Arrange var mapper = new VolumeMapper(); var entity = VolumesMockingSetup.DoMockingSetupForVolume(); // Act var model = mapper.MapToModel(entity.Object); // Assert Assert.Equal(entity.Object.Startyear, model.Startyear); // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); Assert.Equal(entity.Object.FirstIssueId, model.FirstIssueId); Assert.Equal(entity.Object.LastIssueId, model.LastIssueId); Assert.Equal(entity.Object.PublisherId, model.PublisherId); // Associated Objects Assert.Equal(entity.Object.Issues?.Count, model.Issues?.Count); Assert.Equal(entity.Object.VolumeAliases?.Count, model.VolumeAliases?.Count); Assert.Equal(entity.Object.VolumeCharacters?.Count, model.VolumeCharacters?.Count); Assert.Equal(entity.Object.VolumeConcepts?.Count, model.VolumeConcepts?.Count); Assert.Equal(entity.Object.VolumeLocations?.Count, model.VolumeLocations?.Count); Assert.Equal(entity.Object.VolumeObjects?.Count, model.VolumeObjects?.Count); Assert.Equal(entity.Object.VolumeTeams?.Count, model.VolumeTeams?.Count); Assert.Equal(entity.Object.VolumeWriters?.Count, model.VolumeWriters?.Count); }
public void Verify_MapToModel_AssignsVolumeProperties() { // Arrange var mapper = new VolumeMapper(); var entity = VolumesMockingSetup.DoMockingSetupForVolume(); // Act var model = mapper.MapToModel(entity.Object); // Assert Assert.Equal(entity.Object.Startyear, model.Startyear); // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); Assert.Equal(entity.Object.FirstIssueId, model.FirstIssueId); Assert.Equal(entity.Object.LastIssueId, model.LastIssueId); Assert.Equal(entity.Object.PublisherId, model.PublisherId); // Associated Objects Assert.Equal(entity.Object.Issues?.Count, model.Issues?.Count); Assert.Equal(entity.Object.VolumeAliases?.Count, model.VolumeAliases?.Count); Assert.Equal(entity.Object.VolumeCharacters?.Count, model.VolumeCharacters?.Count); Assert.Equal(entity.Object.VolumeConcepts?.Count, model.VolumeConcepts?.Count); Assert.Equal(entity.Object.VolumeLocations?.Count, model.VolumeLocations?.Count); Assert.Equal(entity.Object.VolumeObjects?.Count, model.VolumeObjects?.Count); Assert.Equal(entity.Object.VolumeTeams?.Count, model.VolumeTeams?.Count); Assert.Equal(entity.Object.VolumeWriters?.Count, model.VolumeWriters?.Count); }
public IVolumeModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(VolumeMapper.MapToModel(VolumesRepository.Get(key))); }
public IVolumeModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(VolumeMapper.MapToModel(VolumesRepository.Get(id))); }