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

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            OriginsRepository.Add(newEntity);
            // Try to Save Changes
            OriginsRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
        public IOriginModel Update(IOriginModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = OriginsRepository.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 (OriginMapper.AreEqual(model, existingEntity))
            {
                return(OriginMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            OriginMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            OriginsRepository.Update(OriginMapper.MapToEntity(model));
            // Try to Save Changes
            OriginsRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
        public virtual IOriginSearchModel MapToSearchModel(IOriginModel model)
        {
            var searchModel = NameableEntityMapper.MapToSearchModel <IOriginModel, OriginSearchModel>(model);

            // Search Properties
            // Return Search Model
            return(searchModel);
        }
 public virtual bool AreEqual(IOriginModel model, IOrigin entity)
 {
     return NameableEntityMapper.AreEqual(model, entity)
         // Origin Properties
         && model.CharacterSet == entity.CharacterSet
         // Related Objects
         // <None>
         ;
 }
 public virtual bool AreEqual(IOriginModel model, IOrigin entity)
 {
     return(NameableEntityMapper.AreEqual(model, entity)
            // Origin Properties
            && model.CharacterSet == entity.CharacterSet
            // Related Objects
            // <None>
            );
 }
 public virtual void MapToEntity(IOriginModel model, ref IOrigin entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     NameableEntityMapper.MapToEntity(model, ref entity);
     // Origin Properties
     entity.CharacterSet = model.CharacterSet;
     // Related Objects
     // <None>
     // Associated Objects
     entity.OriginProfiles = model.OriginProfiles?.Where(i => i.Active).Select(OriginProfileMapperExtensions.MapToEntity).ToList();
 }
 public virtual void MapToEntity(IOriginModel model, ref IOrigin entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     NameableEntityMapper.MapToEntity(model, ref entity);
     // Origin Properties
     entity.CharacterSet = model.CharacterSet;
     // Related Objects
     // <None>
     // Associated Objects
     entity.OriginProfiles = model.OriginProfiles?.Where(i => i.Active).Select(OriginProfileMapperExtensions.MapToEntity).ToList();
 }
 public virtual IOrigin MapToEntity(IOriginModel model, int currentDepth = 1)
 {
     currentDepth++;
     var entity = NameableEntityMapper.MapToEntity<Origin, IOriginModel>(model);
     // Origin Properties
     entity.CharacterSet = model.CharacterSet;
     // Related Objects
     // <None>
     // Associated Objects
     entity.OriginProfiles = model.OriginProfiles?.Where(i => i.Active).Select(OriginProfileMapperExtensions.MapToEntity).Cast<OriginProfile>().ToList();
     // Return Entity
     return entity;
 }
        public virtual IOrigin MapToEntity(IOriginModel model, int currentDepth = 1)
        {
            currentDepth++;
            var entity = NameableEntityMapper.MapToEntity <Origin, IOriginModel>(model);

            // Origin Properties
            entity.CharacterSet = model.CharacterSet;
            // Related Objects
            // <None>
            // Associated Objects
            entity.OriginProfiles = model.OriginProfiles?.Where(i => i.Active).Select(OriginProfileMapperExtensions.MapToEntity).Cast <OriginProfile>().ToList();
            // Return Entity
            return(entity);
        }
        public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var entity = OriginsMockingSetup.DoMockingSetupForOrigin(1);
            var mockOriginsRepository = OriginsMockingSetup.DoMockingSetupForRepository();

            mockOriginsRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object);
            var          businessWorkflow = new OriginsBusinessWorkflow(mockOriginsRepository.Object, new OriginMapper());
            var          model            = OriginsMockingSetup.DoMockingSetupForOriginModel(1);
            IOriginModel 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 IOriginModel Create(IOriginModel 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(OriginMapper.MapToSearchModel(model));
     if (results.Any()) { return results.First(); } // Return the first that matches
     // Map model to a new entity
     var newEntity = OriginMapper.MapToEntity(model);
     newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
     newEntity.UpdatedDate = null;
     newEntity.Active = true;
     // Add it
     OriginsRepository.Add(newEntity);
     // Try to Save Changes
     OriginsRepository.SaveChanges();
     // Return the new value
     return Get(newEntity.Id);
 }
 public IOriginModel Update(IOriginModel model)
 {
     // Validate model
     BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
     //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
     // Find existing entity
     // ReSharper disable once PossibleInvalidOperationException
     var existingEntity = OriginsRepository.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 (OriginMapper.AreEqual(model, existingEntity))
     {
         return OriginMapper.MapToModel(existingEntity);
     }
     // Map model to an existing entity
     OriginMapper.MapToEntity(model, ref existingEntity);
     existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
     // Update it
     OriginsRepository.Update(OriginMapper.MapToEntity(model));
     // Try to Save Changes
     OriginsRepository.SaveChanges();
     // Return the new value
     return Get(existingEntity.Id);
 }
 public static IOrigin MapToEntity(this IOriginModel model, int currentDepth = 1)
 {
     return(Mapper.MapToEntity(model, currentDepth));
 }
 public virtual IOriginSearchModel MapToSearchModel(IOriginModel model)
 {
     var searchModel = NameableEntityMapper.MapToSearchModel<IOriginModel, OriginSearchModel>(model);
     // Search Properties
     // Return Search Model
     return searchModel;
 }
 public static bool AreEqual(this IOriginModel model, IOrigin entity)
 {
     return(Mapper.AreEqual(model, entity));
 }
 public static IOriginSearchModel MapToSearchModel(this IOriginModel model)
 {
     return(Mapper.MapToSearchModel(model));
 }
 public static void MapToEntity(this IOriginModel model, ref IOrigin entity, int currentDepth = 1)
 {
     Mapper.MapToEntity(model, ref entity, currentDepth);
 }