public IMovieProducerModel Create(IMovieProducerModel 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(MovieProducerMapper.MapToSearchModel(model));

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            MovieProducersRepository.Add(newEntity);
            // Try to Save Changes
            MovieProducersRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
        public IMovieProducerModel Update(IMovieProducerModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = MovieProducersRepository.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 (MovieProducerMapper.AreEqual(model, existingEntity))
            {
                return(MovieProducerMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            MovieProducerMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            MovieProducersRepository.Update(MovieProducerMapper.MapToEntity(model));
            // Try to Save Changes
            MovieProducersRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
 public virtual bool AreEqual(IMovieProducerModel model, IMovieProducer entity)
 {
     return EntityMapper.AreEqual(model, entity)
         // MovieProducer Properties
         // <None>
         // Related Objects
         && model.MovieId == entity.MovieId
         && model.ProducerId == entity.ProducerId
         ;
 }
 public virtual bool AreEqual(IMovieProducerModel model, IMovieProducer entity)
 {
     return(EntityMapper.AreEqual(model, entity)
            // MovieProducer Properties
            // <None>
            // Related Objects
            && model.MovieId == entity.MovieId &&
            model.ProducerId == entity.ProducerId
            );
 }
 public virtual void MapToEntity(IMovieProducerModel model, ref IMovieProducer entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     EntityMapper.MapToEntity(model, ref entity);
     // MovieProducer Properties
     // <None>
     // Related Objects
     entity.MovieId    = model.MovieId;
     entity.Movie      = (Movie)model.Movie?.MapToEntity();
     entity.ProducerId = model.ProducerId;
     entity.Producer   = (Person)model.Producer?.MapToEntity();
     // Associated Objects
     // <None>
 }
 public virtual void MapToEntity(IMovieProducerModel model, ref IMovieProducer entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     EntityMapper.MapToEntity(model, ref entity);
     // MovieProducer Properties
     // <None>
     // Related Objects
     entity.MovieId = model.MovieId;
     entity.Movie = (Movie)model.Movie?.MapToEntity();
     entity.ProducerId = model.ProducerId;
     entity.Producer = (Person)model.Producer?.MapToEntity();
     // Associated Objects
     // <None>
 }
 public virtual IMovieProducer MapToEntity(IMovieProducerModel model, int currentDepth = 1)
 {
     currentDepth++;
     var entity = EntityMapper.MapToEntity<MovieProducer, IMovieProducerModel>(model);
     // MovieProducer Properties
     // <None>
     // Related Objects
     entity.MovieId = model.MovieId;
     entity.Movie = (Movie)model.Movie?.MapToEntity();
     entity.ProducerId = model.ProducerId;
     entity.Producer = (Person)model.Producer?.MapToEntity();
     // Associated Objects
     // <None>
     // Return Entity
     return entity;
 }
        public virtual IMovieProducer MapToEntity(IMovieProducerModel model, int currentDepth = 1)
        {
            currentDepth++;
            var entity = EntityMapper.MapToEntity <MovieProducer, IMovieProducerModel>(model);

            // MovieProducer Properties
            // <None>
            // Related Objects
            entity.MovieId    = model.MovieId;
            entity.Movie      = (Movie)model.Movie?.MapToEntity();
            entity.ProducerId = model.ProducerId;
            entity.Producer   = (Person)model.Producer?.MapToEntity();
            // Associated Objects
            // <None>
            // Return Entity
            return(entity);
        }
        public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var entity = MovieProducersMockingSetup.DoMockingSetupForMovieProducer(1);
            var mockMovieProducersRepository = MovieProducersMockingSetup.DoMockingSetupForRepository();

            mockMovieProducersRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object);
            var businessWorkflow       = new MovieProducersBusinessWorkflow(mockMovieProducersRepository.Object, new MovieProducerMapper());
            var model                  = MovieProducersMockingSetup.DoMockingSetupForMovieProducerModel(1);
            IMovieProducerModel 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 IMovieProducerModel Create(IMovieProducerModel 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(MovieProducerMapper.MapToSearchModel(model));
     if (results.Any()) { return results.First(); } // Return the first that matches
     // Map model to a new entity
     var newEntity = MovieProducerMapper.MapToEntity(model);
     newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
     newEntity.UpdatedDate = null;
     newEntity.Active = true;
     // Add it
     MovieProducersRepository.Add(newEntity);
     // Try to Save Changes
     MovieProducersRepository.SaveChanges();
     // Return the new value
     return Get(newEntity.Id);
 }
        public virtual IMovieProducerSearchModel MapToSearchModel(IMovieProducerModel model)
        {
            var searchModel = EntityMapper.MapToSearchModel <IMovieProducerModel, MovieProducerSearchModel>(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.ProducerId               = model.ProducerId;
            searchModel.ProducerCustomKey        = model.Producer?.CustomKey;
            searchModel.ProducerApiDetailUrl     = model.Producer?.ApiDetailUrl;
            searchModel.ProducerSiteDetailUrl    = model.Producer?.SiteDetailUrl;
            searchModel.ProducerName             = model.Producer?.Name;
            searchModel.ProducerShortDescription = model.Producer?.ShortDescription;
            searchModel.ProducerDescription      = model.Producer?.Description;
            // Return Search Model
            return(searchModel);
        }
 public IMovieProducerModel Update(IMovieProducerModel model)
 {
     // Validate model
     BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
     //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
     // Find existing entity
     // ReSharper disable once PossibleInvalidOperationException
     var existingEntity = MovieProducersRepository.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 (MovieProducerMapper.AreEqual(model, existingEntity))
     {
         return MovieProducerMapper.MapToModel(existingEntity);
     }
     // Map model to an existing entity
     MovieProducerMapper.MapToEntity(model, ref existingEntity);
     existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
     // Update it
     MovieProducersRepository.Update(MovieProducerMapper.MapToEntity(model));
     // Try to Save Changes
     MovieProducersRepository.SaveChanges();
     // Return the new value
     return Get(existingEntity.Id);
 }
 public virtual IMovieProducerSearchModel MapToSearchModel(IMovieProducerModel model)
 {
     var searchModel = EntityMapper.MapToSearchModel<IMovieProducerModel, MovieProducerSearchModel>(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.ProducerId = model.ProducerId;
     searchModel.ProducerCustomKey = model.Producer?.CustomKey;
     searchModel.ProducerApiDetailUrl = model.Producer?.ApiDetailUrl;
     searchModel.ProducerSiteDetailUrl = model.Producer?.SiteDetailUrl;
     searchModel.ProducerName = model.Producer?.Name;
     searchModel.ProducerShortDescription = model.Producer?.ShortDescription;
     searchModel.ProducerDescription = model.Producer?.Description;
     // Return Search Model
     return searchModel;
 }
 public static bool AreEqual(this IMovieProducerModel model, IMovieProducer entity)
 {
     return(Mapper.AreEqual(model, entity));
 }
 public static IMovieProducerSearchModel MapToSearchModel(this IMovieProducerModel model)
 {
     return(Mapper.MapToSearchModel(model));
 }
 public static void MapToEntity(this IMovieProducerModel model, ref IMovieProducer entity, int currentDepth = 1)
 {
     Mapper.MapToEntity(model, ref entity, currentDepth);
 }
 public static IMovieProducer MapToEntity(this IMovieProducerModel model, int currentDepth = 1)
 {
     return(Mapper.MapToEntity(model, currentDepth));
 }