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