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

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

            newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
            newEntity.UpdatedDate = null;
            newEntity.Active      = true;
            // Add it
            ObjectIssuesRepository.Add(newEntity);
            // Try to Save Changes
            ObjectIssuesRepository.SaveChanges();
            // Return the new value
            return(Get(newEntity.Id));
        }
        public IObjectIssueModel Update(IObjectIssueModel model)
        {
            // Validate model
            BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
            //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
            // Find existing entity
            // ReSharper disable once PossibleInvalidOperationException
            var existingEntity = ObjectIssuesRepository.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 (ObjectIssueMapper.AreEqual(model, existingEntity))
            {
                return(ObjectIssueMapper.MapToModel(existingEntity));
            }
            // Map model to an existing entity
            ObjectIssueMapper.MapToEntity(model, ref existingEntity);
            existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
            // Update it
            ObjectIssuesRepository.Update(ObjectIssueMapper.MapToEntity(model));
            // Try to Save Changes
            ObjectIssuesRepository.SaveChanges();
            // Return the new value
            return(Get(existingEntity.Id));
        }
예제 #3
0
 public virtual bool AreEqual(IObjectIssueModel model, IObjectIssue entity)
 {
     return(EntityMapper.AreEqual(model, entity)
            // ObjectIssue Properties
            // <None>
            // Related Objects
            && model.ObjectId == entity.ObjectId &&
            model.IssueId == entity.IssueId
            );
 }
예제 #4
0
 public virtual void MapToEntity(IObjectIssueModel model, ref IObjectIssue entity, int currentDepth = 1)
 {
     currentDepth++;
     // Assign Base properties
     EntityMapper.MapToEntity(model, ref entity);
     // ObjectIssue Properties
     // <None>
     // Related Objects
     entity.ObjectId = model.ObjectId;
     entity.Object   = (Object)model.Object?.MapToEntity();
     entity.IssueId  = model.IssueId;
     entity.Issue    = (Issue)model.Issue?.MapToEntity();
     // Associated Objects
     // <None>
 }
예제 #5
0
        public virtual IObjectIssue MapToEntity(IObjectIssueModel model, int currentDepth = 1)
        {
            currentDepth++;
            var entity = EntityMapper.MapToEntity <ObjectIssue, IObjectIssueModel>(model);

            // ObjectIssue Properties
            // <None>
            // Related Objects
            entity.ObjectId = model.ObjectId;
            entity.Object   = (Object)model.Object?.MapToEntity();
            entity.IssueId  = model.IssueId;
            entity.Issue    = (Issue)model.Issue?.MapToEntity();
            // Associated Objects
            // <None>
            // Return Entity
            return(entity);
        }
        public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal()
        {
            // Arrange
            var entity = ObjectIssuesMockingSetup.DoMockingSetupForObjectIssue(1);
            var mockObjectIssuesRepository = ObjectIssuesMockingSetup.DoMockingSetupForRepository();

            mockObjectIssuesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object);
            var businessWorkflow     = new ObjectIssuesBusinessWorkflow(mockObjectIssuesRepository.Object, new ObjectIssueMapper());
            var model                = ObjectIssuesMockingSetup.DoMockingSetupForObjectIssueModel(1);
            IObjectIssueModel 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 IObjectIssueModel Create(IObjectIssueModel 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(ObjectIssueMapper.MapToSearchModel(model));
     if (results.Any()) { return results.First(); } // Return the first that matches
     // Map model to a new entity
     var newEntity = ObjectIssueMapper.MapToEntity(model);
     newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime;
     newEntity.UpdatedDate = null;
     newEntity.Active = true;
     // Add it
     ObjectIssuesRepository.Add(newEntity);
     // Try to Save Changes
     ObjectIssuesRepository.SaveChanges();
     // Return the new value
     return Get(newEntity.Id);
 }
예제 #8
0
        public virtual IObjectIssueSearchModel MapToSearchModel(IObjectIssueModel model)
        {
            var searchModel = EntityMapper.MapToSearchModel <IObjectIssueModel, ObjectIssueSearchModel>(model);

            // Search Properties
            searchModel.ObjectId               = model.ObjectId;
            searchModel.ObjectCustomKey        = model.Object?.CustomKey;
            searchModel.ObjectApiDetailUrl     = model.Object?.ApiDetailUrl;
            searchModel.ObjectSiteDetailUrl    = model.Object?.SiteDetailUrl;
            searchModel.ObjectName             = model.Object?.Name;
            searchModel.ObjectShortDescription = model.Object?.ShortDescription;
            searchModel.ObjectDescription      = model.Object?.Description;
            searchModel.IssueId               = model.IssueId;
            searchModel.IssueCustomKey        = model.Issue?.CustomKey;
            searchModel.IssueApiDetailUrl     = model.Issue?.ApiDetailUrl;
            searchModel.IssueSiteDetailUrl    = model.Issue?.SiteDetailUrl;
            searchModel.IssueName             = model.Issue?.Name;
            searchModel.IssueShortDescription = model.Issue?.ShortDescription;
            searchModel.IssueDescription      = model.Issue?.Description;
            // Return Search Model
            return(searchModel);
        }
 public IObjectIssueModel Update(IObjectIssueModel model)
 {
     // Validate model
     BusinessWorkflowBase.ValidateRequiredNullableID(model.Id);
     //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name));
     // Find existing entity
     // ReSharper disable once PossibleInvalidOperationException
     var existingEntity = ObjectIssuesRepository.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 (ObjectIssueMapper.AreEqual(model, existingEntity))
     {
         return ObjectIssueMapper.MapToModel(existingEntity);
     }
     // Map model to an existing entity
     ObjectIssueMapper.MapToEntity(model, ref existingEntity);
     existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime;
     // Update it
     ObjectIssuesRepository.Update(ObjectIssueMapper.MapToEntity(model));
     // Try to Save Changes
     ObjectIssuesRepository.SaveChanges();
     // Return the new value
     return Get(existingEntity.Id);
 }
예제 #10
0
 public static bool AreEqual(this IObjectIssueModel model, IObjectIssue entity)
 {
     return(Mapper.AreEqual(model, entity));
 }
예제 #11
0
 public static IObjectIssueSearchModel MapToSearchModel(this IObjectIssueModel model)
 {
     return(Mapper.MapToSearchModel(model));
 }
예제 #12
0
 public static void MapToEntity(this IObjectIssueModel model, ref IObjectIssue entity, int currentDepth = 1)
 {
     Mapper.MapToEntity(model, ref entity, currentDepth);
 }
예제 #13
0
 public static IObjectIssue MapToEntity(this IObjectIssueModel model, int currentDepth = 1)
 {
     return(Mapper.MapToEntity(model, currentDepth));
 }