Exemple #1
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));
        }
Exemple #2
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 void Verify_MapToEntity_WithExistingEntity_AssignsVideoProperties()
        {
            // Arrange
            var mapper = new VideoMapper();
            var model  = VideosMockingSetup.DoMockingSetupForVideoModel();
            // Act
            IVideo existingEntity = new Video {
                Id = 1
            };

            mapper.MapToEntity(model.Object, ref existingEntity);
            // Assert
            Assert.Equal(model.Object.LowUrl, existingEntity.LowUrl);
            Assert.Equal(model.Object.HighUrl, existingEntity.HighUrl);
            Assert.Equal(model.Object.HdUrl, existingEntity.HdUrl);
            Assert.Equal(model.Object.Url, existingEntity.Url);
            Assert.Equal(model.Object.LengthSeconds, existingEntity.LengthSeconds);
            Assert.Equal(model.Object.PublishDate, existingEntity.PublishDate);
            // Related Objects
            Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId);
            Assert.Equal(model.Object.AuthorId, existingEntity.AuthorId);
            Assert.Equal(model.Object.VideoTypeId, existingEntity.VideoTypeId);
            // Associated Objects
            // <None>
        }
 public void Verify_MapToEntity_WithExistingEntity_AssignsVideoProperties()
 {
     // Arrange
     var mapper = new VideoMapper();
     var model = VideosMockingSetup.DoMockingSetupForVideoModel();
     // Act
     IVideo existingEntity = new Video { Id = 1 };
     mapper.MapToEntity(model.Object, ref existingEntity);
     // Assert
     Assert.Equal(model.Object.LowUrl, existingEntity.LowUrl);
     Assert.Equal(model.Object.HighUrl, existingEntity.HighUrl);
     Assert.Equal(model.Object.HdUrl, existingEntity.HdUrl);
     Assert.Equal(model.Object.Url, existingEntity.Url);
     Assert.Equal(model.Object.LengthSeconds, existingEntity.LengthSeconds);
     Assert.Equal(model.Object.PublishDate, existingEntity.PublishDate);
     // Related Objects
     Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId);
     Assert.Equal(model.Object.AuthorId, existingEntity.AuthorId);
     Assert.Equal(model.Object.VideoTypeId, existingEntity.VideoTypeId);
     // Associated Objects
     // <None>
 }