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

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            MovieStudiosRepository.Add(newEntity);
            // Try to Save Changes
            MovieStudiosRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
 public virtual bool AreEqual(IMovieStudioModel model, IMovieStudio entity)
 {
     return EntityMapper.AreEqual(model, entity)
         // MovieStudio Properties
         // <None>
         // Related Objects
         && model.MovieId == entity.MovieId
         && model.StudioId == entity.StudioId
         ;
 }
Example #4
0
 public virtual bool AreEqual(IMovieStudioModel model, IMovieStudio entity)
 {
     return(EntityMapper.AreEqual(model, entity)
            // MovieStudio Properties
            // <None>
            // Related Objects
            && model.MovieId == entity.MovieId &&
            model.StudioId == entity.StudioId
            );
 }
 public virtual void MapToEntity(IMovieStudioModel model, ref IMovieStudio entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     EntityMapper.MapToEntity(model, ref entity);
     // MovieStudio Properties
     // <None>
     // Related Objects
     entity.MovieId = model.MovieId;
     entity.Movie = (Movie)model.Movie?.MapToEntity();
     entity.StudioId = model.StudioId;
     entity.Studio = (Studio)model.Studio?.MapToEntity();
     // Associated Objects
     // <None>
 }
Example #6
0
 public virtual void MapToEntity(IMovieStudioModel model, ref IMovieStudio entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     EntityMapper.MapToEntity(model, ref entity);
     // MovieStudio Properties
     // <None>
     // Related Objects
     entity.MovieId  = model.MovieId;
     entity.Movie    = (Movie)model.Movie?.MapToEntity();
     entity.StudioId = model.StudioId;
     entity.Studio   = (Studio)model.Studio?.MapToEntity();
     // Associated Objects
     // <None>
 }
 public virtual IMovieStudio MapToEntity(IMovieStudioModel model, int currentDepth = 1)
 {
     currentDepth++;
     var entity = EntityMapper.MapToEntity<MovieStudio, IMovieStudioModel>(model);
     // MovieStudio Properties
     // <None>
     // Related Objects
     entity.MovieId = model.MovieId;
     entity.Movie = (Movie)model.Movie?.MapToEntity();
     entity.StudioId = model.StudioId;
     entity.Studio = (Studio)model.Studio?.MapToEntity();
     // Associated Objects
     // <None>
     // Return Entity
     return entity;
 }
Example #8
0
        public virtual IMovieStudio MapToEntity(IMovieStudioModel model, int currentDepth = 1)
        {
            currentDepth++;
            var entity = EntityMapper.MapToEntity <MovieStudio, IMovieStudioModel>(model);

            // MovieStudio Properties
            // <None>
            // Related Objects
            entity.MovieId  = model.MovieId;
            entity.Movie    = (Movie)model.Movie?.MapToEntity();
            entity.StudioId = model.StudioId;
            entity.Studio   = (Studio)model.Studio?.MapToEntity();
            // Associated Objects
            // <None>
            // Return Entity
            return(entity);
        }
        public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var entity = MovieStudiosMockingSetup.DoMockingSetupForMovieStudio(1);
            var mockMovieStudiosRepository = MovieStudiosMockingSetup.DoMockingSetupForRepository();

            mockMovieStudiosRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object);
            var businessWorkflow     = new MovieStudiosBusinessWorkflow(mockMovieStudiosRepository.Object, new MovieStudioMapper());
            var model                = MovieStudiosMockingSetup.DoMockingSetupForMovieStudioModel(1);
            IMovieStudioModel 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 IMovieStudioModel Create(IMovieStudioModel 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(MovieStudioMapper.MapToSearchModel(model));
     if (results.Any()) { return results.First(); } // Return the first that matches
     // Map model to a new entity
     var newEntity = MovieStudioMapper.MapToEntity(model);
     newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
     newEntity.UpdatedDate = null;
     newEntity.Active = true;
     // Add it
     MovieStudiosRepository.Add(newEntity);
     // Try to Save Changes
     MovieStudiosRepository.SaveChanges();
     // Return the new value
     return Get(newEntity.Id);
 }
Example #11
0
        public virtual IMovieStudioSearchModel MapToSearchModel(IMovieStudioModel model)
        {
            var searchModel = EntityMapper.MapToSearchModel <IMovieStudioModel, MovieStudioSearchModel>(model);

            // Search Properties
            searchModel.MovieId                = model.MovieId;
            searchModel.MovieCustomKey         = model.Movie?.CustomKey;
            searchModel.MovieApiDetailUrl      = model.Movie?.ApiDetailUrl;
            searchModel.MovieSiteDetailUrl     = model.Movie?.SiteDetailUrl;
            searchModel.MovieName              = model.Movie?.Name;
            searchModel.MovieShortDescription  = model.Movie?.ShortDescription;
            searchModel.MovieDescription       = model.Movie?.Description;
            searchModel.StudioId               = model.StudioId;
            searchModel.StudioCustomKey        = model.Studio?.CustomKey;
            searchModel.StudioApiDetailUrl     = model.Studio?.ApiDetailUrl;
            searchModel.StudioSiteDetailUrl    = model.Studio?.SiteDetailUrl;
            searchModel.StudioName             = model.Studio?.Name;
            searchModel.StudioShortDescription = model.Studio?.ShortDescription;
            searchModel.StudioDescription      = model.Studio?.Description;
            // Return Search Model
            return(searchModel);
        }
 public virtual IMovieStudioSearchModel MapToSearchModel(IMovieStudioModel model)
 {
     var searchModel = EntityMapper.MapToSearchModel<IMovieStudioModel, MovieStudioSearchModel>(model);
     // Search Properties
     searchModel.MovieId = model.MovieId;
     searchModel.MovieCustomKey = model.Movie?.CustomKey;
     searchModel.MovieApiDetailUrl = model.Movie?.ApiDetailUrl;
     searchModel.MovieSiteDetailUrl = model.Movie?.SiteDetailUrl;
     searchModel.MovieName = model.Movie?.Name;
     searchModel.MovieShortDescription = model.Movie?.ShortDescription;
     searchModel.MovieDescription = model.Movie?.Description;
     searchModel.StudioId = model.StudioId;
     searchModel.StudioCustomKey = model.Studio?.CustomKey;
     searchModel.StudioApiDetailUrl = model.Studio?.ApiDetailUrl;
     searchModel.StudioSiteDetailUrl = model.Studio?.SiteDetailUrl;
     searchModel.StudioName = model.Studio?.Name;
     searchModel.StudioShortDescription = model.Studio?.ShortDescription;
     searchModel.StudioDescription = model.Studio?.Description;
     // Return Search Model
     return searchModel;
 }
 public IMovieStudioModel Update(IMovieStudioModel model)
 {
     // Validate model
     BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
     //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
     // Find existing entity
     // ReSharper disable once PossibleInvalidOperationException
     var existingEntity = MovieStudiosRepository.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 (MovieStudioMapper.AreEqual(model, existingEntity))
     {
         return MovieStudioMapper.MapToModel(existingEntity);
     }
     // Map model to an existing entity
     MovieStudioMapper.MapToEntity(model, ref existingEntity);
     existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
     // Update it
     MovieStudiosRepository.Update(MovieStudioMapper.MapToEntity(model));
     // Try to Save Changes
     MovieStudiosRepository.SaveChanges();
     // Return the new value
     return Get(existingEntity.Id);
 }
Example #14
0
 public static bool AreEqual(this IMovieStudioModel model, IMovieStudio entity)
 {
     return(Mapper.AreEqual(model, entity));
 }
Example #15
0
 public static IMovieStudioSearchModel MapToSearchModel(this IMovieStudioModel model)
 {
     return(Mapper.MapToSearchModel(model));
 }
Example #16
0
 public static void MapToEntity(this IMovieStudioModel model, ref IMovieStudio entity, int currentDepth = 1)
 {
     Mapper.MapToEntity(model, ref entity, currentDepth);
 }
Example #17
0
 public static IMovieStudio MapToEntity(this IMovieStudioModel model, int currentDepth = 1)
 {
     return(Mapper.MapToEntity(model, currentDepth));
 }