public IStoryArcModel Update(IStoryArcModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = StoryArcsRepository.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 (StoryArcMapper.AreEqual(model, existingEntity)) { return(StoryArcMapper.MapToModel(existingEntity)); } // Map model to an existing entity StoryArcMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it StoryArcsRepository.Update(StoryArcMapper.MapToEntity(model)); // Try to Save Changes StoryArcsRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public void Verify_MapToModel_AssignsStoryArcProperties() { // Arrange var mapper = new StoryArcMapper(); var entity = StoryArcsMockingSetup.DoMockingSetupForStoryArc(); // Act var model = mapper.MapToModel(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); Assert.Equal(entity.Object.FirstIssueAppearanceId, model.FirstIssueAppearanceId); Assert.Equal(entity.Object.PublisherId, model.PublisherId); // Associated Objects Assert.Equal(entity.Object.MovieStoryArcs?.Count, model.MovieStoryArcs?.Count); Assert.Equal(entity.Object.StoryArcAliases?.Count, model.StoryArcAliases?.Count); Assert.Equal(entity.Object.StoryArcIssues?.Count, model.StoryArcIssues?.Count); Assert.Equal(entity.Object.StoryArcsWritten?.Count, model.StoryArcsWritten?.Count); }
public IStoryArcModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(StoryArcMapper.MapToModel(StoryArcsRepository.Get(key))); }
public IStoryArcModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(StoryArcMapper.MapToModel(StoryArcsRepository.Get(id))); }