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