Exemplo n.º 1
0
        public IPublisherModel Update(IPublisherModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = PublishersRepository.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 (PublisherMapper.AreEqual(model, existingEntity))
            {
                return(PublisherMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            PublisherMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            PublishersRepository.Update(PublisherMapper.MapToEntity(model));
            // Try to Save Changes
            PublishersRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
Exemplo n.º 2
0
        public IPublisherModel Create(IPublisherModel 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(PublisherMapper.MapToSearchModel(model));

            if (results.Any())
            {
                return(results.First());
            }                                              // Return the first that matches
            // Map model to a new entity
            var newEntity = PublisherMapper.MapToEntity(model);

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            PublishersRepository.Add(newEntity);
            // Try to Save Changes
            PublishersRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
 public virtual bool AreEqual(IPublisherModel model, IPublisher entity)
 {
     return NameableEntityMapper.AreEqual(model, entity)
         // Publisher Properties
         && model.LocationAddress == entity.LocationAddress
         && model.LocationCity == entity.LocationCity
         && model.LocationState == entity.LocationState
         // Related Objects
         && model.PrimaryImageFileId == entity.PrimaryImageFileId
         ;
 }
Exemplo n.º 4
0
 public virtual bool AreEqual(IPublisherModel model, IPublisher entity)
 {
     return(NameableEntityMapper.AreEqual(model, entity)
            // Publisher Properties
            && model.LocationAddress == entity.LocationAddress &&
            model.LocationCity == entity.LocationCity &&
            model.LocationState == entity.LocationState
            // Related Objects
            && model.PrimaryImageFileId == entity.PrimaryImageFileId
            );
 }
Exemplo n.º 5
0
        public virtual IPublisherSearchModel MapToSearchModel(IPublisherModel model)
        {
            var searchModel = NameableEntityMapper.MapToSearchModel <IPublisherModel, PublisherSearchModel>(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;
            // Return Search Model
            return(searchModel);
        }
Exemplo n.º 6
0
        public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var entity = PublishersMockingSetup.DoMockingSetupForPublisher(1);
            var mockPublishersRepository = PublishersMockingSetup.DoMockingSetupForRepository();

            mockPublishersRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object);
            var             businessWorkflow = new PublishersBusinessWorkflow(mockPublishersRepository.Object, new PublisherMapper());
            var             model            = PublishersMockingSetup.DoMockingSetupForPublisherModel(1);
            IPublisherModel 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 void MapToEntity(IPublisherModel model, ref IPublisher entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     NameableEntityMapper.MapToEntity(model, ref entity);
     // Publisher Properties
     entity.LocationAddress = model.LocationAddress;
     entity.LocationCity = model.LocationCity;
     entity.LocationState = model.LocationState;
     // Related Objects
     entity.PrimaryImageFileId = model.PrimaryImageFileId;
     entity.PrimaryImageFile = (ImageFile)model.PrimaryImageFile?.MapToEntity();
     // Associated Objects
     entity.CharactersPublished = model.CharactersPublished?.Where(i => i.Active).Select(CharacterMapperExtensions.MapToEntity).ToList();
     entity.PublisherAliases = model.PublisherAliases?.Where(i => i.Active).Select(PublisherAliasMapperExtensions.MapToEntity).ToList();
     entity.SeriesPublished = model.SeriesPublished?.Where(i => i.Active).Select(SeriesMapperExtensions.MapToEntity).ToList();
     entity.StoryArcsPublished = model.StoryArcsPublished?.Where(i => i.Active).Select(StoryArcMapperExtensions.MapToEntity).ToList();
     entity.TeamsPublished = model.TeamsPublished?.Where(i => i.Active).Select(TeamMapperExtensions.MapToEntity).ToList();
     entity.VolumesPublished = model.VolumesPublished?.Where(i => i.Active).Select(VolumeMapperExtensions.MapToEntity).ToList();
 }
 public IPublisherModel Create(IPublisherModel 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(PublisherMapper.MapToSearchModel(model));
     if (results.Any()) { return results.First(); } // Return the first that matches
     // Map model to a new entity
     var newEntity = PublisherMapper.MapToEntity(model);
     newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
     newEntity.UpdatedDate = null;
     newEntity.Active = true;
     // Add it
     PublishersRepository.Add(newEntity);
     // Try to Save Changes
     PublishersRepository.SaveChanges();
     // Return the new value
     return Get(newEntity.Id);
 }
Exemplo n.º 9
0
 public virtual void MapToEntity(IPublisherModel model, ref IPublisher entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     NameableEntityMapper.MapToEntity(model, ref entity);
     // Publisher Properties
     entity.LocationAddress = model.LocationAddress;
     entity.LocationCity    = model.LocationCity;
     entity.LocationState   = model.LocationState;
     // Related Objects
     entity.PrimaryImageFileId = model.PrimaryImageFileId;
     entity.PrimaryImageFile   = (ImageFile)model.PrimaryImageFile?.MapToEntity();
     // Associated Objects
     entity.CharactersPublished = model.CharactersPublished?.Where(i => i.Active).Select(CharacterMapperExtensions.MapToEntity).ToList();
     entity.PublisherAliases    = model.PublisherAliases?.Where(i => i.Active).Select(PublisherAliasMapperExtensions.MapToEntity).ToList();
     entity.SeriesPublished     = model.SeriesPublished?.Where(i => i.Active).Select(SeriesMapperExtensions.MapToEntity).ToList();
     entity.StoryArcsPublished  = model.StoryArcsPublished?.Where(i => i.Active).Select(StoryArcMapperExtensions.MapToEntity).ToList();
     entity.TeamsPublished      = model.TeamsPublished?.Where(i => i.Active).Select(TeamMapperExtensions.MapToEntity).ToList();
     entity.VolumesPublished    = model.VolumesPublished?.Where(i => i.Active).Select(VolumeMapperExtensions.MapToEntity).ToList();
 }
 public virtual IPublisher MapToEntity(IPublisherModel model, int currentDepth = 1)
 {
     currentDepth++;
     var entity = NameableEntityMapper.MapToEntity<Publisher, IPublisherModel>(model);
     // Publisher Properties
     entity.LocationAddress = model.LocationAddress;
     entity.LocationCity = model.LocationCity;
     entity.LocationState = model.LocationState;
     // Related Objects
     entity.PrimaryImageFileId = model.PrimaryImageFileId;
     entity.PrimaryImageFile = (ImageFile)model.PrimaryImageFile?.MapToEntity();
     // Associated Objects
     entity.CharactersPublished = model.CharactersPublished?.Where(i => i.Active).Select(CharacterMapperExtensions.MapToEntity).Cast<Character>().ToList();
     entity.PublisherAliases = model.PublisherAliases?.Where(i => i.Active).Select(PublisherAliasMapperExtensions.MapToEntity).Cast<PublisherAlias>().ToList();
     entity.SeriesPublished = model.SeriesPublished?.Where(i => i.Active).Select(SeriesMapperExtensions.MapToEntity).Cast<Series>().ToList();
     entity.StoryArcsPublished = model.StoryArcsPublished?.Where(i => i.Active).Select(StoryArcMapperExtensions.MapToEntity).Cast<StoryArc>().ToList();
     entity.TeamsPublished = model.TeamsPublished?.Where(i => i.Active).Select(TeamMapperExtensions.MapToEntity).Cast<Team>().ToList();
     entity.VolumesPublished = model.VolumesPublished?.Where(i => i.Active).Select(VolumeMapperExtensions.MapToEntity).Cast<Volume>().ToList();
     // Return Entity
     return entity;
 }
Exemplo n.º 11
0
        public virtual IPublisher MapToEntity(IPublisherModel model, int currentDepth = 1)
        {
            currentDepth++;
            var entity = NameableEntityMapper.MapToEntity <Publisher, IPublisherModel>(model);

            // Publisher Properties
            entity.LocationAddress = model.LocationAddress;
            entity.LocationCity    = model.LocationCity;
            entity.LocationState   = model.LocationState;
            // Related Objects
            entity.PrimaryImageFileId = model.PrimaryImageFileId;
            entity.PrimaryImageFile   = (ImageFile)model.PrimaryImageFile?.MapToEntity();
            // Associated Objects
            entity.CharactersPublished = model.CharactersPublished?.Where(i => i.Active).Select(CharacterMapperExtensions.MapToEntity).Cast <Character>().ToList();
            entity.PublisherAliases    = model.PublisherAliases?.Where(i => i.Active).Select(PublisherAliasMapperExtensions.MapToEntity).Cast <PublisherAlias>().ToList();
            entity.SeriesPublished     = model.SeriesPublished?.Where(i => i.Active).Select(SeriesMapperExtensions.MapToEntity).Cast <Series>().ToList();
            entity.StoryArcsPublished  = model.StoryArcsPublished?.Where(i => i.Active).Select(StoryArcMapperExtensions.MapToEntity).Cast <StoryArc>().ToList();
            entity.TeamsPublished      = model.TeamsPublished?.Where(i => i.Active).Select(TeamMapperExtensions.MapToEntity).Cast <Team>().ToList();
            entity.VolumesPublished    = model.VolumesPublished?.Where(i => i.Active).Select(VolumeMapperExtensions.MapToEntity).Cast <Volume>().ToList();
            // Return Entity
            return(entity);
        }
Exemplo n.º 12
0
 public static bool AreEqual(this IPublisherModel model, IPublisher entity)
 {
     return(Mapper.AreEqual(model, entity));
 }
Exemplo n.º 13
0
 public static IPublisher MapToEntity(this IPublisherModel model, int currentDepth = 1)
 {
     return(Mapper.MapToEntity(model, currentDepth));
 }
 public virtual IPublisherSearchModel MapToSearchModel(IPublisherModel model)
 {
     var searchModel = NameableEntityMapper.MapToSearchModel<IPublisherModel, PublisherSearchModel>(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;
     // Return Search Model
     return searchModel;
 }
 public IPublisherModel Update(IPublisherModel model)
 {
     // Validate model
     BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
     //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
     // Find existing entity
     // ReSharper disable once PossibleInvalidOperationException
     var existingEntity = PublishersRepository.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 (PublisherMapper.AreEqual(model, existingEntity))
     {
         return PublisherMapper.MapToModel(existingEntity);
     }
     // Map model to an existing entity
     PublisherMapper.MapToEntity(model, ref existingEntity);
     existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
     // Update it
     PublishersRepository.Update(PublisherMapper.MapToEntity(model));
     // Try to Save Changes
     PublishersRepository.SaveChanges();
     // Return the new value
     return Get(existingEntity.Id);
 }
Exemplo n.º 16
0
 public static void MapToEntity(this IPublisherModel model, ref IPublisher entity, int currentDepth = 1)
 {
     Mapper.MapToEntity(model, ref entity, currentDepth);
 }
Exemplo n.º 17
0
 public static IPublisherSearchModel MapToSearchModel(this IPublisherModel model)
 {
     return(Mapper.MapToSearchModel(model));
 }