Пример #1
0
        public IVideoModel Create(IVideoModel 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(VideoMapper.MapToSearchModel(model));

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            VideosRepository.Add(newEntity);
            // Try to Save Changes
            VideosRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
        public virtual IVideoSearchModel MapToSearchModel(IVideoModel model)
        {
            var searchModel = NameableEntityMapper.MapToSearchModel <IVideoModel, VideoSearchModel>(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.VideoTypeId               = model.VideoTypeId;
            searchModel.VideoTypeCustomKey        = model.VideoType?.CustomKey;
            searchModel.VideoTypeApiDetailUrl     = model.VideoType?.ApiDetailUrl;
            searchModel.VideoTypeSiteDetailUrl    = model.VideoType?.SiteDetailUrl;
            searchModel.VideoTypeName             = model.VideoType?.Name;
            searchModel.VideoTypeShortDescription = model.VideoType?.ShortDescription;
            searchModel.VideoTypeDescription      = model.VideoType?.Description;
            // Return Search Model
            return(searchModel);
        }
Пример #3
0
        public void TestTrimVideo()
        {
            _model = DownloadVideoIfNotExists();

            _trimmer.SetTrimSection("00:00:10", "00:00:15");
            _trimmer.Run();
        }
Пример #4
0
        public IVideoModel Update(IVideoModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = VideosRepository.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 (VideoMapper.AreEqual(model, existingEntity))
            {
                return(VideoMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            VideoMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            VideosRepository.Update(VideoMapper.MapToEntity(model));
            // Try to Save Changes
            VideosRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
 public virtual bool AreEqual(IVideoModel model, IVideo entity)
 {
     return(NameableEntityMapper.AreEqual(model, entity)
            // Video Properties
            && model.LowUrl == entity.LowUrl &&
            model.HighUrl == entity.HighUrl &&
            model.HdUrl == entity.HdUrl &&
            model.Url == entity.Url &&
            model.LengthSeconds == entity.LengthSeconds &&
            model.PublishDate == entity.PublishDate
            // Related Objects
            && model.PrimaryImageFileId == entity.PrimaryImageFileId &&
            model.AuthorId == entity.AuthorId &&
            model.VideoTypeId == entity.VideoTypeId
            );
 }
 public virtual bool AreEqual(IVideoModel model, IVideo entity)
 {
     return NameableEntityMapper.AreEqual(model, entity)
         // Video Properties
         && model.LowUrl == entity.LowUrl
         && model.HighUrl == entity.HighUrl
         && model.HdUrl == entity.HdUrl
         && model.Url == entity.Url
         && model.LengthSeconds == entity.LengthSeconds
         && model.PublishDate == entity.PublishDate
         // Related Objects
         && model.PrimaryImageFileId == entity.PrimaryImageFileId
         && model.AuthorId == entity.AuthorId
         && model.VideoTypeId == entity.VideoTypeId
         ;
 }
        public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var entity = VideosMockingSetup.DoMockingSetupForVideo(1);
            var mockVideosRepository = VideosMockingSetup.DoMockingSetupForRepository();

            mockVideosRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object);
            var         businessWorkflow = new VideosBusinessWorkflow(mockVideosRepository.Object, new VideoMapper());
            var         model            = VideosMockingSetup.DoMockingSetupForVideoModel(1);
            IVideoModel 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 IVideoModel Create(IVideoModel 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(VideoMapper.MapToSearchModel(model));
     if (results.Any()) { return results.First(); } // Return the first that matches
     // Map model to a new entity
     var newEntity = VideoMapper.MapToEntity(model);
     newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
     newEntity.UpdatedDate = null;
     newEntity.Active = true;
     // Add it
     VideosRepository.Add(newEntity);
     // Try to Save Changes
     VideosRepository.SaveChanges();
     // Return the new value
     return Get(newEntity.Id);
 }
 public virtual void MapToEntity(IVideoModel model, ref IVideo entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     NameableEntityMapper.MapToEntity(model, ref entity);
     // Video Properties
     entity.LowUrl        = model.LowUrl;
     entity.HighUrl       = model.HighUrl;
     entity.HdUrl         = model.HdUrl;
     entity.Url           = model.Url;
     entity.LengthSeconds = model.LengthSeconds;
     entity.PublishDate   = model.PublishDate;
     // Related Objects
     entity.PrimaryImageFileId = model.PrimaryImageFileId;
     entity.PrimaryImageFile   = (ImageFile)model.PrimaryImageFile?.MapToEntity();
     entity.AuthorId           = model.AuthorId;
     entity.Author             = (Person)model.Author?.MapToEntity();
     entity.VideoTypeId        = model.VideoTypeId;
     entity.VideoType          = (VideoType)model.VideoType?.MapToEntity();
     // Associated Objects
     // <None>
 }
 public virtual void MapToEntity(IVideoModel model, ref IVideo entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     NameableEntityMapper.MapToEntity(model, ref entity);
     // Video Properties
     entity.LowUrl = model.LowUrl;
     entity.HighUrl = model.HighUrl;
     entity.HdUrl = model.HdUrl;
     entity.Url = model.Url;
     entity.LengthSeconds = model.LengthSeconds;
     entity.PublishDate = model.PublishDate;
     // Related Objects
     entity.PrimaryImageFileId = model.PrimaryImageFileId;
     entity.PrimaryImageFile = (ImageFile)model.PrimaryImageFile?.MapToEntity();
     entity.AuthorId = model.AuthorId;
     entity.Author = (Person)model.Author?.MapToEntity();
     entity.VideoTypeId = model.VideoTypeId;
     entity.VideoType = (VideoType)model.VideoType?.MapToEntity();
     // Associated Objects
     // <None>
 }
 public virtual IVideo MapToEntity(IVideoModel model, int currentDepth = 1)
 {
     currentDepth++;
     var entity = NameableEntityMapper.MapToEntity<Video, IVideoModel>(model);
     // Video Properties
     entity.LowUrl = model.LowUrl;
     entity.HighUrl = model.HighUrl;
     entity.HdUrl = model.HdUrl;
     entity.Url = model.Url;
     entity.LengthSeconds = model.LengthSeconds;
     entity.PublishDate = model.PublishDate;
     // Related Objects
     entity.PrimaryImageFileId = model.PrimaryImageFileId;
     entity.PrimaryImageFile = (ImageFile)model.PrimaryImageFile?.MapToEntity();
     entity.AuthorId = model.AuthorId;
     entity.Author = (Person)model.Author?.MapToEntity();
     entity.VideoTypeId = model.VideoTypeId;
     entity.VideoType = (VideoType)model.VideoType?.MapToEntity();
     // Associated Objects
     // <None>
     // Return Entity
     return entity;
 }
        public virtual IVideo MapToEntity(IVideoModel model, int currentDepth = 1)
        {
            currentDepth++;
            var entity = NameableEntityMapper.MapToEntity <Video, IVideoModel>(model);

            // Video Properties
            entity.LowUrl        = model.LowUrl;
            entity.HighUrl       = model.HighUrl;
            entity.HdUrl         = model.HdUrl;
            entity.Url           = model.Url;
            entity.LengthSeconds = model.LengthSeconds;
            entity.PublishDate   = model.PublishDate;
            // Related Objects
            entity.PrimaryImageFileId = model.PrimaryImageFileId;
            entity.PrimaryImageFile   = (ImageFile)model.PrimaryImageFile?.MapToEntity();
            entity.AuthorId           = model.AuthorId;
            entity.Author             = (Person)model.Author?.MapToEntity();
            entity.VideoTypeId        = model.VideoTypeId;
            entity.VideoType          = (VideoType)model.VideoType?.MapToEntity();
            // Associated Objects
            // <None>
            // Return Entity
            return(entity);
        }
 public static bool AreEqual(this IVideoModel model, IVideo entity)
 {
     return(Mapper.AreEqual(model, entity));
 }
 public static IVideoSearchModel MapToSearchModel(this IVideoModel model)
 {
     return(Mapper.MapToSearchModel(model));
 }
 public static void MapToEntity(this IVideoModel model, ref IVideo entity, int currentDepth = 1)
 {
     Mapper.MapToEntity(model, ref entity, currentDepth);
 }
 public virtual IVideoSearchModel MapToSearchModel(IVideoModel model)
 {
     var searchModel = NameableEntityMapper.MapToSearchModel<IVideoModel, VideoSearchModel>(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.VideoTypeId = model.VideoTypeId;
     searchModel.VideoTypeCustomKey = model.VideoType?.CustomKey;
     searchModel.VideoTypeApiDetailUrl = model.VideoType?.ApiDetailUrl;
     searchModel.VideoTypeSiteDetailUrl = model.VideoType?.SiteDetailUrl;
     searchModel.VideoTypeName = model.VideoType?.Name;
     searchModel.VideoTypeShortDescription = model.VideoType?.ShortDescription;
     searchModel.VideoTypeDescription = model.VideoType?.Description;
     // Return Search Model
     return searchModel;
 }
 public static IVideo MapToEntity(this IVideoModel model, int currentDepth = 1)
 {
     return(Mapper.MapToEntity(model, currentDepth));
 }
 public IVideoModel Update(IVideoModel model)
 {
     // Validate model
     BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
     //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
     // Find existing entity
     // ReSharper disable once PossibleInvalidOperationException
     var existingEntity = VideosRepository.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 (VideoMapper.AreEqual(model, existingEntity))
     {
         return VideoMapper.MapToModel(existingEntity);
     }
     // Map model to an existing entity
     VideoMapper.MapToEntity(model, ref existingEntity);
     existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
     // Update it
     VideosRepository.Update(VideoMapper.MapToEntity(model));
     // Try to Save Changes
     VideosRepository.SaveChanges();
     // Return the new value
     return Get(existingEntity.Id);
 }