public IMovieObjectModel Update(IMovieObjectModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = MovieObjectsRepository.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 (MovieObjectMapper.AreEqual(model, existingEntity)) { return(MovieObjectMapper.MapToModel(existingEntity)); } // Map model to an existing entity MovieObjectMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it MovieObjectsRepository.Update(MovieObjectMapper.MapToEntity(model)); // Try to Save Changes MovieObjectsRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public void Verify_MapToModel_AssignsMovieObjectProperties() { // Arrange var mapper = new MovieObjectMapper(); var entity = MovieObjectsMockingSetup.DoMockingSetupForMovieObject(); // Act var model = mapper.MapToModel(entity.Object); // Assert // <None> // Related Objects Assert.Equal(entity.Object.MovieId, model.MovieId); Assert.Equal(entity.Object.ObjectId, model.ObjectId); // Associated Objects // <None> }
public IMovieObjectModel Get(string key) { BusinessWorkflowBase.ValidateRequiredKey(key); return(MovieObjectMapper.MapToModel(MovieObjectsRepository.Get(key))); }
public IMovieObjectModel Get(int id) { BusinessWorkflowBase.ValidateRequiredID(id); return(MovieObjectMapper.MapToModel(MovieObjectsRepository.Get(id))); }