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

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            LocationAliasesRepository.Add(newEntity);
            // Try to Save Changes
            LocationAliasesRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
Пример #2
0
        public ILocationAliasModel Update(ILocationAliasModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = LocationAliasesRepository.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 (LocationAliasMapper.AreEqual(model, existingEntity))
            {
                return(LocationAliasMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            LocationAliasMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            LocationAliasesRepository.Update(LocationAliasMapper.MapToEntity(model));
            // Try to Save Changes
            LocationAliasesRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
 public virtual bool AreEqual(ILocationAliasModel model, ILocationAlias entity)
 {
     return NameableEntityMapper.AreEqual(model, entity)
         // LocationAlias Properties
         // <None>
         // Related Objects
         && model.LocationId == entity.LocationId
         ;
 }
Пример #4
0
 public virtual bool AreEqual(ILocationAliasModel model, ILocationAlias entity)
 {
     return(NameableEntityMapper.AreEqual(model, entity)
            // LocationAlias Properties
            // <None>
            // Related Objects
            && model.LocationId == entity.LocationId
            );
 }
Пример #5
0
 public virtual void MapToEntity(ILocationAliasModel model, ref ILocationAlias entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     NameableEntityMapper.MapToEntity(model, ref entity);
     // LocationAlias Properties
     // <None>
     // Related Objects
     entity.LocationId = model.LocationId;
     entity.Location   = (Location)model.Location?.MapToEntity();
     // Associated Objects
     // <None>
 }
 public virtual void MapToEntity(ILocationAliasModel model, ref ILocationAlias entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     NameableEntityMapper.MapToEntity(model, ref entity);
     // LocationAlias Properties
     // <None>
     // Related Objects
     entity.LocationId = model.LocationId;
     entity.Location = (Location)model.Location?.MapToEntity();
     // Associated Objects
     // <None>
 }
 public virtual ILocationAlias MapToEntity(ILocationAliasModel model, int currentDepth = 1)
 {
     currentDepth++;
     var entity = NameableEntityMapper.MapToEntity<LocationAlias, ILocationAliasModel>(model);
     // LocationAlias Properties
     // <None>
     // Related Objects
     entity.LocationId = model.LocationId;
     entity.Location = (Location)model.Location?.MapToEntity();
     // Associated Objects
     // <None>
     // Return Entity
     return entity;
 }
Пример #8
0
        public virtual ILocationAlias MapToEntity(ILocationAliasModel model, int currentDepth = 1)
        {
            currentDepth++;
            var entity = NameableEntityMapper.MapToEntity <LocationAlias, ILocationAliasModel>(model);

            // LocationAlias Properties
            // <None>
            // Related Objects
            entity.LocationId = model.LocationId;
            entity.Location   = (Location)model.Location?.MapToEntity();
            // Associated Objects
            // <None>
            // Return Entity
            return(entity);
        }
Пример #9
0
        public virtual ILocationAliasSearchModel MapToSearchModel(ILocationAliasModel model)
        {
            var searchModel = NameableEntityMapper.MapToSearchModel <ILocationAliasModel, LocationAliasSearchModel>(model);

            // Search Properties
            searchModel.LocationId               = model.LocationId;
            searchModel.LocationCustomKey        = model.Location?.CustomKey;
            searchModel.LocationApiDetailUrl     = model.Location?.ApiDetailUrl;
            searchModel.LocationSiteDetailUrl    = model.Location?.SiteDetailUrl;
            searchModel.LocationName             = model.Location?.Name;
            searchModel.LocationShortDescription = model.Location?.ShortDescription;
            searchModel.LocationDescription      = model.Location?.Description;
            // Return Search Model
            return(searchModel);
        }
Пример #10
0
        public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var entity = LocationAliasesMockingSetup.DoMockingSetupForLocationAlias(1);
            var mockLocationAliasesRepository = LocationAliasesMockingSetup.DoMockingSetupForRepository();

            mockLocationAliasesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object);
            var businessWorkflow       = new LocationAliasesBusinessWorkflow(mockLocationAliasesRepository.Object, new LocationAliasMapper());
            var model                  = LocationAliasesMockingSetup.DoMockingSetupForLocationAliasModel(1);
            ILocationAliasModel 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 ILocationAliasModel Create(ILocationAliasModel 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(LocationAliasMapper.MapToSearchModel(model));
     if (results.Any()) { return results.First(); } // Return the first that matches
     // Map model to a new entity
     var newEntity = LocationAliasMapper.MapToEntity(model);
     newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
     newEntity.UpdatedDate = null;
     newEntity.Active = true;
     // Add it
     LocationAliasesRepository.Add(newEntity);
     // Try to Save Changes
     LocationAliasesRepository.SaveChanges();
     // Return the new value
     return Get(newEntity.Id);
 }
 public ILocationAliasModel Update(ILocationAliasModel model)
 {
     // Validate model
     BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
     //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
     // Find existing entity
     // ReSharper disable once PossibleInvalidOperationException
     var existingEntity = LocationAliasesRepository.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 (LocationAliasMapper.AreEqual(model, existingEntity))
     {
         return LocationAliasMapper.MapToModel(existingEntity);
     }
     // Map model to an existing entity
     LocationAliasMapper.MapToEntity(model, ref existingEntity);
     existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
     // Update it
     LocationAliasesRepository.Update(LocationAliasMapper.MapToEntity(model));
     // Try to Save Changes
     LocationAliasesRepository.SaveChanges();
     // Return the new value
     return Get(existingEntity.Id);
 }
Пример #13
0
 public static bool AreEqual(this ILocationAliasModel model, ILocationAlias entity)
 {
     return(Mapper.AreEqual(model, entity));
 }
Пример #14
0
 public static ILocationAliasSearchModel MapToSearchModel(this ILocationAliasModel model)
 {
     return(Mapper.MapToSearchModel(model));
 }
Пример #15
0
 public static ILocationAlias MapToEntity(this ILocationAliasModel model, int currentDepth = 1)
 {
     return(Mapper.MapToEntity(model, currentDepth));
 }
Пример #16
0
 public static void MapToEntity(this ILocationAliasModel model, ref ILocationAlias entity, int currentDepth = 1)
 {
     Mapper.MapToEntity(model, ref entity, currentDepth);
 }
 public virtual ILocationAliasSearchModel MapToSearchModel(ILocationAliasModel model)
 {
     var searchModel = NameableEntityMapper.MapToSearchModel<ILocationAliasModel, LocationAliasSearchModel>(model);
     // Search Properties
     searchModel.LocationId = model.LocationId;
     searchModel.LocationCustomKey = model.Location?.CustomKey;
     searchModel.LocationApiDetailUrl = model.Location?.ApiDetailUrl;
     searchModel.LocationSiteDetailUrl = model.Location?.SiteDetailUrl;
     searchModel.LocationName = model.Location?.Name;
     searchModel.LocationShortDescription = model.Location?.ShortDescription;
     searchModel.LocationDescription = model.Location?.Description;
     // Return Search Model
     return searchModel;
 }