public ICharacterPowerModel Update(ICharacterPowerModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = CharacterPowersRepository.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 (CharacterPowerMapper.AreEqual(model, existingEntity)) { return(CharacterPowerMapper.MapToModel(existingEntity)); } // Map model to an existing entity CharacterPowerMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it CharacterPowersRepository.Update(CharacterPowerMapper.MapToEntity(model)); // Try to Save Changes CharacterPowersRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public ICharacterPowerModel Create(ICharacterPowerModel model) { // Validate model BusinessWorkflowBase.ValidateIDIsNull(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Search for an Existing Record (Don't allow Duplicates var results = Search(CharacterPowerMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = CharacterPowerMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it CharacterPowersRepository.Add(newEntity); // Try to Save Changes CharacterPowersRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public virtual bool AreEqual(ICharacterPowerModel model, ICharacterPower entity) { return(EntityMapper.AreEqual(model, entity) // CharacterPower Properties // <None> // Related Objects && model.CharacterId == entity.CharacterId && model.PowerId == entity.PowerId ); }
public virtual void MapToEntity(ICharacterPowerModel model, ref ICharacterPower entity, int currentDepth = 1) { currentDepth++; // Assign Base properties EntityMapper.MapToEntity(model, ref entity); // CharacterPower Properties // <None> // Related Objects entity.CharacterId = model.CharacterId; entity.Character = (Character)model.Character?.MapToEntity(); entity.PowerId = model.PowerId; entity.Power = (Power)model.Power?.MapToEntity(); // Associated Objects // <None> }
public virtual ICharacterPower MapToEntity(ICharacterPowerModel model, int currentDepth = 1) { currentDepth++; var entity = EntityMapper.MapToEntity <CharacterPower, ICharacterPowerModel>(model); // CharacterPower Properties // <None> // Related Objects entity.CharacterId = model.CharacterId; entity.Character = (Character)model.Character?.MapToEntity(); entity.PowerId = model.PowerId; entity.Power = (Power)model.Power?.MapToEntity(); // Associated Objects // <None> // Return Entity return(entity); }
public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal() { // Arrange var entity = CharacterPowersMockingSetup.DoMockingSetupForCharacterPower(1); var mockCharacterPowersRepository = CharacterPowersMockingSetup.DoMockingSetupForRepository(); mockCharacterPowersRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object); var businessWorkflow = new CharacterPowersBusinessWorkflow(mockCharacterPowersRepository.Object, new CharacterPowerMapper()); var model = CharacterPowersMockingSetup.DoMockingSetupForCharacterPowerModel(1); ICharacterPowerModel result = null; // Act try { result = businessWorkflow.Update(model.Object); } catch { /* ignored, the Get call at the end doesn't work because don't get a real entity with id on it */ } // Assert Assert.NotNull(result); Assert.Equal("/TEST/KING-STEPHEN", result.ApiDetailUrl); Assert.Null(result.UpdatedDate); }
public ICharacterPowerModel Create(ICharacterPowerModel model) { // Validate model BusinessWorkflowBase.ValidateIDIsNull(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Search for an Existing Record (Don't allow Duplicates var results = Search(CharacterPowerMapper.MapToSearchModel(model)); if (results.Any()) { return results.First(); } // Return the first that matches // Map model to a new entity var newEntity = CharacterPowerMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it CharacterPowersRepository.Add(newEntity); // Try to Save Changes CharacterPowersRepository.SaveChanges(); // Return the new value return Get(newEntity.Id); }
public virtual ICharacterPowerSearchModel MapToSearchModel(ICharacterPowerModel model) { var searchModel = EntityMapper.MapToSearchModel <ICharacterPowerModel, CharacterPowerSearchModel>(model); // Search Properties searchModel.CharacterId = model.CharacterId; searchModel.CharacterCustomKey = model.Character?.CustomKey; searchModel.CharacterApiDetailUrl = model.Character?.ApiDetailUrl; searchModel.CharacterSiteDetailUrl = model.Character?.SiteDetailUrl; searchModel.CharacterName = model.Character?.Name; searchModel.CharacterShortDescription = model.Character?.ShortDescription; searchModel.CharacterDescription = model.Character?.Description; searchModel.PowerId = model.PowerId; searchModel.PowerCustomKey = model.Power?.CustomKey; searchModel.PowerApiDetailUrl = model.Power?.ApiDetailUrl; searchModel.PowerSiteDetailUrl = model.Power?.SiteDetailUrl; searchModel.PowerName = model.Power?.Name; searchModel.PowerShortDescription = model.Power?.ShortDescription; searchModel.PowerDescription = model.Power?.Description; // Return Search Model return(searchModel); }
public ICharacterPowerModel Update(ICharacterPowerModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = CharacterPowersRepository.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 (CharacterPowerMapper.AreEqual(model, existingEntity)) { return CharacterPowerMapper.MapToModel(existingEntity); } // Map model to an existing entity CharacterPowerMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it CharacterPowersRepository.Update(CharacterPowerMapper.MapToEntity(model)); // Try to Save Changes CharacterPowersRepository.SaveChanges(); // Return the new value return Get(existingEntity.Id); }
public static bool AreEqual(this ICharacterPowerModel model, ICharacterPower entity) { return(Mapper.AreEqual(model, entity)); }
public static ICharacterPowerSearchModel MapToSearchModel(this ICharacterPowerModel model) { return(Mapper.MapToSearchModel(model)); }
public static void MapToEntity(this ICharacterPowerModel model, ref ICharacterPower entity, int currentDepth = 1) { Mapper.MapToEntity(model, ref entity, currentDepth); }
public static ICharacterPower MapToEntity(this ICharacterPowerModel model, int currentDepth = 1) { return(Mapper.MapToEntity(model, currentDepth)); }