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