public IPromoModel Create(IPromoModel 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(PromoMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = PromoMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it PromosRepository.Add(newEntity); // Try to Save Changes PromosRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public IPromoModel Update(IPromoModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = PromosRepository.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 (PromoMapper.AreEqual(model, existingEntity)) { return(PromoMapper.MapToModel(existingEntity)); } // Map model to an existing entity PromoMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it PromosRepository.Update(PromoMapper.MapToEntity(model)); // Try to Save Changes PromosRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public virtual IPromoSearchModel MapToSearchModel(IPromoModel model) { var searchModel = NameableEntityMapper.MapToSearchModel <IPromoModel, PromoSearchModel>(model); // Search Properties searchModel.PrimaryImageFileId = model.PrimaryImageFileId; searchModel.PrimaryImageFileCustomKey = model.PrimaryImageFile?.CustomKey; searchModel.PrimaryImageFileApiDetailUrl = model.PrimaryImageFile?.ApiDetailUrl; searchModel.PrimaryImageFileSiteDetailUrl = model.PrimaryImageFile?.SiteDetailUrl; searchModel.PrimaryImageFileName = model.PrimaryImageFile?.Name; searchModel.PrimaryImageFileShortDescription = model.PrimaryImageFile?.ShortDescription; searchModel.PrimaryImageFileDescription = model.PrimaryImageFile?.Description; searchModel.AuthorId = model.AuthorId; searchModel.AuthorCustomKey = model.Author?.CustomKey; searchModel.AuthorApiDetailUrl = model.Author?.ApiDetailUrl; searchModel.AuthorSiteDetailUrl = model.Author?.SiteDetailUrl; searchModel.AuthorName = model.Author?.Name; searchModel.AuthorShortDescription = model.Author?.ShortDescription; searchModel.AuthorDescription = model.Author?.Description; searchModel.ResourceTypeId = model.ResourceTypeId; searchModel.ResourceTypeCustomKey = model.ResourceType?.CustomKey; searchModel.ResourceTypeApiDetailUrl = model.ResourceType?.ApiDetailUrl; searchModel.ResourceTypeSiteDetailUrl = model.ResourceType?.SiteDetailUrl; searchModel.ResourceTypeName = model.ResourceType?.Name; searchModel.ResourceTypeShortDescription = model.ResourceType?.ShortDescription; searchModel.ResourceTypeDescription = model.ResourceType?.Description; // Return Search Model return(searchModel); }
public virtual bool AreEqual(IPromoModel model, IPromo entity) { return NameableEntityMapper.AreEqual(model, entity) // Promo Properties && model.Link == entity.Link // Related Objects && model.PrimaryImageFileId == entity.PrimaryImageFileId && model.AuthorId == entity.AuthorId && model.ResourceTypeId == entity.ResourceTypeId ; }
public virtual bool AreEqual(IPromoModel model, IPromo entity) { return(NameableEntityMapper.AreEqual(model, entity) // Promo Properties && model.Link == entity.Link // Related Objects && model.PrimaryImageFileId == entity.PrimaryImageFileId && model.AuthorId == entity.AuthorId && model.ResourceTypeId == entity.ResourceTypeId ); }
public virtual void MapToEntity(IPromoModel model, ref IPromo entity, int currentDepth = 1) { currentDepth++; // Assign Base properties NameableEntityMapper.MapToEntity(model, ref entity); // Promo Properties entity.Link = model.Link; // Related Objects entity.PrimaryImageFileId = model.PrimaryImageFileId; entity.PrimaryImageFile = (ImageFile)model.PrimaryImageFile?.MapToEntity(); entity.AuthorId = model.AuthorId; entity.Author = (Person)model.Author?.MapToEntity(); entity.ResourceTypeId = model.ResourceTypeId; entity.ResourceType = (ResourceType)model.ResourceType?.MapToEntity(); // Associated Objects // <None> }
public virtual IPromo MapToEntity(IPromoModel model, int currentDepth = 1) { currentDepth++; var entity = NameableEntityMapper.MapToEntity<Promo, IPromoModel>(model); // Promo Properties entity.Link = model.Link; // Related Objects entity.PrimaryImageFileId = model.PrimaryImageFileId; entity.PrimaryImageFile = (ImageFile)model.PrimaryImageFile?.MapToEntity(); entity.AuthorId = model.AuthorId; entity.Author = (Person)model.Author?.MapToEntity(); entity.ResourceTypeId = model.ResourceTypeId; entity.ResourceType = (ResourceType)model.ResourceType?.MapToEntity(); // Associated Objects // <None> // Return Entity return entity; }
public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal() { // Arrange var entity = PromosMockingSetup.DoMockingSetupForPromo(1); var mockPromosRepository = PromosMockingSetup.DoMockingSetupForRepository(); mockPromosRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object); var businessWorkflow = new PromosBusinessWorkflow(mockPromosRepository.Object, new PromoMapper()); var model = PromosMockingSetup.DoMockingSetupForPromoModel(1); IPromoModel 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 virtual IPromo MapToEntity(IPromoModel model, int currentDepth = 1) { currentDepth++; var entity = NameableEntityMapper.MapToEntity <Promo, IPromoModel>(model); // Promo Properties entity.Link = model.Link; // Related Objects entity.PrimaryImageFileId = model.PrimaryImageFileId; entity.PrimaryImageFile = (ImageFile)model.PrimaryImageFile?.MapToEntity(); entity.AuthorId = model.AuthorId; entity.Author = (Person)model.Author?.MapToEntity(); entity.ResourceTypeId = model.ResourceTypeId; entity.ResourceType = (ResourceType)model.ResourceType?.MapToEntity(); // Associated Objects // <None> // Return Entity return(entity); }
public IPromoModel Create(IPromoModel 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(PromoMapper.MapToSearchModel(model)); if (results.Any()) { return results.First(); } // Return the first that matches // Map model to a new entity var newEntity = PromoMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it PromosRepository.Add(newEntity); // Try to Save Changes PromosRepository.SaveChanges(); // Return the new value return Get(newEntity.Id); }
public IPromoModel Update(IPromoModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = PromosRepository.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 (PromoMapper.AreEqual(model, existingEntity)) { return PromoMapper.MapToModel(existingEntity); } // Map model to an existing entity PromoMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it PromosRepository.Update(PromoMapper.MapToEntity(model)); // Try to Save Changes PromosRepository.SaveChanges(); // Return the new value return Get(existingEntity.Id); }
public static IPromo MapToEntity(this IPromoModel model, int currentDepth = 1) { return(Mapper.MapToEntity(model, currentDepth)); }
public virtual IPromoSearchModel MapToSearchModel(IPromoModel model) { var searchModel = NameableEntityMapper.MapToSearchModel<IPromoModel, PromoSearchModel>(model); // Search Properties searchModel.PrimaryImageFileId = model.PrimaryImageFileId; searchModel.PrimaryImageFileCustomKey = model.PrimaryImageFile?.CustomKey; searchModel.PrimaryImageFileApiDetailUrl = model.PrimaryImageFile?.ApiDetailUrl; searchModel.PrimaryImageFileSiteDetailUrl = model.PrimaryImageFile?.SiteDetailUrl; searchModel.PrimaryImageFileName = model.PrimaryImageFile?.Name; searchModel.PrimaryImageFileShortDescription = model.PrimaryImageFile?.ShortDescription; searchModel.PrimaryImageFileDescription = model.PrimaryImageFile?.Description; searchModel.AuthorId = model.AuthorId; searchModel.AuthorCustomKey = model.Author?.CustomKey; searchModel.AuthorApiDetailUrl = model.Author?.ApiDetailUrl; searchModel.AuthorSiteDetailUrl = model.Author?.SiteDetailUrl; searchModel.AuthorName = model.Author?.Name; searchModel.AuthorShortDescription = model.Author?.ShortDescription; searchModel.AuthorDescription = model.Author?.Description; searchModel.ResourceTypeId = model.ResourceTypeId; searchModel.ResourceTypeCustomKey = model.ResourceType?.CustomKey; searchModel.ResourceTypeApiDetailUrl = model.ResourceType?.ApiDetailUrl; searchModel.ResourceTypeSiteDetailUrl = model.ResourceType?.SiteDetailUrl; searchModel.ResourceTypeName = model.ResourceType?.Name; searchModel.ResourceTypeShortDescription = model.ResourceType?.ShortDescription; searchModel.ResourceTypeDescription = model.ResourceType?.Description; // Return Search Model return searchModel; }
public static void MapToEntity(this IPromoModel model, ref IPromo entity, int currentDepth = 1) { Mapper.MapToEntity(model, ref entity, currentDepth); }
public static IPromoSearchModel MapToSearchModel(this IPromoModel model) { return(Mapper.MapToSearchModel(model)); }
public static bool AreEqual(this IPromoModel model, IPromo entity) { return(Mapper.AreEqual(model, entity)); }