public IIssueModel Create(IIssueModel 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(IssueMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = IssueMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it IssuesRepository.Add(newEntity); // Try to Save Changes IssuesRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public IIssueModel Update(IIssueModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = IssuesRepository.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 (IssueMapper.AreEqual(model, existingEntity)) { return(IssueMapper.MapToModel(existingEntity)); } // Map model to an existing entity IssueMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it IssuesRepository.Update(IssueMapper.MapToEntity(model)); // Try to Save Changes IssuesRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public virtual bool AreEqual(IIssueModel model, IIssue entity) { return NameableEntityMapper.AreEqual(model, entity) // Issue Properties && model.HasStaffReview == entity.HasStaffReview && model.CoverDate == entity.CoverDate && model.StoreDate == entity.StoreDate && model.IssueNumber == entity.IssueNumber // Related Objects && model.PrimaryImageFileId == entity.PrimaryImageFileId && model.VolumeId == entity.VolumeId ; }
public virtual bool AreEqual(IIssueModel model, IIssue entity) { return(NameableEntityMapper.AreEqual(model, entity) // Issue Properties && model.HasStaffReview == entity.HasStaffReview && model.CoverDate == entity.CoverDate && model.StoreDate == entity.StoreDate && model.IssueNumber == entity.IssueNumber // Related Objects && model.PrimaryImageFileId == entity.PrimaryImageFileId && model.VolumeId == entity.VolumeId ); }
public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal() { // Arrange var entity = IssuesMockingSetup.DoMockingSetupForIssue(1); var mockIssuesRepository = IssuesMockingSetup.DoMockingSetupForRepository(); mockIssuesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object); var businessWorkflow = new IssuesBusinessWorkflow(mockIssuesRepository.Object, new IssueMapper()); var model = IssuesMockingSetup.DoMockingSetupForIssueModel(1); IIssueModel 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 virtual void MapToEntity(IIssueModel model, ref IIssue entity, int currentDepth = 1) { currentDepth++; // Assign Base properties NameableEntityMapper.MapToEntity(model, ref entity); // Issue Properties entity.HasStaffReview = model.HasStaffReview; entity.CoverDate = model.CoverDate; entity.StoreDate = model.StoreDate; entity.IssueNumber = model.IssueNumber; // Related Objects entity.PrimaryImageFileId = model.PrimaryImageFileId; entity.PrimaryImageFile = (ImageFile)model.PrimaryImageFile?.MapToEntity(); entity.VolumeId = model.VolumeId; entity.Volume = (Volume)model.Volume?.MapToEntity(); // Associated Objects entity.IssueAliases = model.IssueAliases?.Where(i => i.Active).Select(IssueAliasMapperExtensions.MapToEntity).ToList(); entity.IssueStoryArcs = model.IssueStoryArcs?.Where(i => i.Active).Select(StoryArcIssueMapperExtensions.MapToEntity).ToList(); entity.IssueWriters = model.IssueWriters?.Where(i => i.Active).Select(IssueWriterMapperExtensions.MapToEntity).ToList(); }
public IIssueModel Create(IIssueModel 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(IssueMapper.MapToSearchModel(model)); if (results.Any()) { return results.First(); } // Return the first that matches // Map model to a new entity var newEntity = IssueMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it IssuesRepository.Add(newEntity); // Try to Save Changes IssuesRepository.SaveChanges(); // Return the new value return Get(newEntity.Id); }
public virtual IIssue MapToEntity(IIssueModel model, int currentDepth = 1) { currentDepth++; var entity = NameableEntityMapper.MapToEntity<Issue, IIssueModel>(model); // Issue Properties entity.HasStaffReview = model.HasStaffReview; entity.CoverDate = model.CoverDate; entity.StoreDate = model.StoreDate; entity.IssueNumber = model.IssueNumber; // Related Objects entity.PrimaryImageFileId = model.PrimaryImageFileId; entity.PrimaryImageFile = (ImageFile)model.PrimaryImageFile?.MapToEntity(); entity.VolumeId = model.VolumeId; entity.Volume = (Volume)model.Volume?.MapToEntity(); // Associated Objects entity.IssueAliases = model.IssueAliases?.Where(i => i.Active).Select(IssueAliasMapperExtensions.MapToEntity).Cast<IssueAlias>().ToList(); entity.IssueStoryArcs = model.IssueStoryArcs?.Where(i => i.Active).Select(StoryArcIssueMapperExtensions.MapToEntity).Cast<StoryArcIssue>().ToList(); entity.IssueWriters = model.IssueWriters?.Where(i => i.Active).Select(IssueWriterMapperExtensions.MapToEntity).Cast<IssueWriter>().ToList(); // Return Entity return entity; }
public virtual IIssue MapToEntity(IIssueModel model, int currentDepth = 1) { currentDepth++; var entity = NameableEntityMapper.MapToEntity <Issue, IIssueModel>(model); // Issue Properties entity.HasStaffReview = model.HasStaffReview; entity.CoverDate = model.CoverDate; entity.StoreDate = model.StoreDate; entity.IssueNumber = model.IssueNumber; // Related Objects entity.PrimaryImageFileId = model.PrimaryImageFileId; entity.PrimaryImageFile = (ImageFile)model.PrimaryImageFile?.MapToEntity(); entity.VolumeId = model.VolumeId; entity.Volume = (Volume)model.Volume?.MapToEntity(); // Associated Objects entity.IssueAliases = model.IssueAliases?.Where(i => i.Active).Select(IssueAliasMapperExtensions.MapToEntity).Cast <IssueAlias>().ToList(); entity.IssueStoryArcs = model.IssueStoryArcs?.Where(i => i.Active).Select(StoryArcIssueMapperExtensions.MapToEntity).Cast <StoryArcIssue>().ToList(); entity.IssueWriters = model.IssueWriters?.Where(i => i.Active).Select(IssueWriterMapperExtensions.MapToEntity).Cast <IssueWriter>().ToList(); // Return Entity return(entity); }
public IssueViewModel( IIssueModel model, IRedmineRepository redmine) { Model = model; var mapConfig = new MapperConfiguration(cfg => { cfg.CreateMap <Issue, IssueViewModel>(); }); Mapper = mapConfig.CreateMapper(); SaveCommand = ReactiveCommand.CreateFromTask(async(x) => { try { var newIssue = new Issue { Subject = Subject, Description = Description, AssignedTo = AssignedTo, Project = Project, Status = Status, Tracker = Tracker, Priority = Priority, CustomFields = CustomFields }; var saved = await redmine.CreateOrUpdateIssueAsync(newIssue); } catch (Exception ex) { Trace.WriteLine(ex); } }); CancelCommand = ReactiveCommand.Create(() => Close()); }
public virtual IIssueSearchModel MapToSearchModel(IIssueModel model) { var searchModel = NameableEntityMapper.MapToSearchModel <IIssueModel, IssueSearchModel>(model); // Search Properties searchModel.PrimaryImageFileId = model.PrimaryImageFileId; searchModel.PrimaryImageFileCustomKey = model.PrimaryImageFile?.CustomKey; searchModel.PrimaryImageFileApiDetailUrl = model.PrimaryImageFile?.ApiDetailUrl; searchModel.PrimaryImageFileSiteDetailUrl = model.PrimaryImageFile?.SiteDetailUrl; searchModel.PrimaryImageFileName = model.PrimaryImageFile?.Name; searchModel.PrimaryImageFileShortDescription = model.PrimaryImageFile?.ShortDescription; searchModel.PrimaryImageFileDescription = model.PrimaryImageFile?.Description; searchModel.VolumeId = model.VolumeId; searchModel.VolumeCustomKey = model.Volume?.CustomKey; searchModel.VolumeApiDetailUrl = model.Volume?.ApiDetailUrl; searchModel.VolumeSiteDetailUrl = model.Volume?.SiteDetailUrl; searchModel.VolumeName = model.Volume?.Name; searchModel.VolumeShortDescription = model.Volume?.ShortDescription; searchModel.VolumeDescription = model.Volume?.Description; searchModel.HasStaffReview = model.HasStaffReview; // Return Search Model return(searchModel); }
public static bool AreEqual(this IIssueModel model, IIssue entity) { return(Mapper.AreEqual(model, entity)); }
public static IIssueSearchModel MapToSearchModel(this IIssueModel model) { return(Mapper.MapToSearchModel(model)); }
public static void MapToEntity(this IIssueModel model, ref IIssue entity, int currentDepth = 1) { Mapper.MapToEntity(model, ref entity, currentDepth); }
public IIssueModel Update(IIssueModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = IssuesRepository.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 (IssueMapper.AreEqual(model, existingEntity)) { return IssueMapper.MapToModel(existingEntity); } // Map model to an existing entity IssueMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it IssuesRepository.Update(IssueMapper.MapToEntity(model)); // Try to Save Changes IssuesRepository.SaveChanges(); // Return the new value return Get(existingEntity.Id); }
public static IIssue MapToEntity(this IIssueModel model, int currentDepth = 1) { return(Mapper.MapToEntity(model, currentDepth)); }
public virtual IIssueSearchModel MapToSearchModel(IIssueModel model) { var searchModel = NameableEntityMapper.MapToSearchModel<IIssueModel, IssueSearchModel>(model); // Search Properties searchModel.PrimaryImageFileId = model.PrimaryImageFileId; searchModel.PrimaryImageFileCustomKey = model.PrimaryImageFile?.CustomKey; searchModel.PrimaryImageFileApiDetailUrl = model.PrimaryImageFile?.ApiDetailUrl; searchModel.PrimaryImageFileSiteDetailUrl = model.PrimaryImageFile?.SiteDetailUrl; searchModel.PrimaryImageFileName = model.PrimaryImageFile?.Name; searchModel.PrimaryImageFileShortDescription = model.PrimaryImageFile?.ShortDescription; searchModel.PrimaryImageFileDescription = model.PrimaryImageFile?.Description; searchModel.VolumeId = model.VolumeId; searchModel.VolumeCustomKey = model.Volume?.CustomKey; searchModel.VolumeApiDetailUrl = model.Volume?.ApiDetailUrl; searchModel.VolumeSiteDetailUrl = model.Volume?.SiteDetailUrl; searchModel.VolumeName = model.Volume?.Name; searchModel.VolumeShortDescription = model.Volume?.ShortDescription; searchModel.VolumeDescription = model.Volume?.Description; searchModel.HasStaffReview = model.HasStaffReview; // Return Search Model return searchModel; }