public IVideoTypeModel Update(IVideoTypeModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = VideoTypesRepository.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 (VideoTypeMapper.AreEqual(model, existingEntity)) { return(VideoTypeMapper.MapToModel(existingEntity)); } // Map model to an existing entity VideoTypeMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it VideoTypesRepository.Update(VideoTypeMapper.MapToEntity(model)); // Try to Save Changes VideoTypesRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public IVideoTypeModel Create(IVideoTypeModel 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(VideoTypeMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = VideoTypeMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it VideoTypesRepository.Add(newEntity); // Try to Save Changes VideoTypesRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal() { // Arrange var entity = VideoTypesMockingSetup.DoMockingSetupForVideoType(1); var mockVideoTypesRepository = VideoTypesMockingSetup.DoMockingSetupForRepository(); mockVideoTypesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object); var businessWorkflow = new VideoTypesBusinessWorkflow(mockVideoTypesRepository.Object, new VideoTypeMapper()); var model = VideoTypesMockingSetup.DoMockingSetupForVideoTypeModel(1); IVideoTypeModel 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 IVideoTypeModel Create(IVideoTypeModel 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(VideoTypeMapper.MapToSearchModel(model)); if (results.Any()) { return results.First(); } // Return the first that matches // Map model to a new entity var newEntity = VideoTypeMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it VideoTypesRepository.Add(newEntity); // Try to Save Changes VideoTypesRepository.SaveChanges(); // Return the new value return Get(newEntity.Id); }
public IVideoTypeModel Update(IVideoTypeModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = VideoTypesRepository.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 (VideoTypeMapper.AreEqual(model, existingEntity)) { return VideoTypeMapper.MapToModel(existingEntity); } // Map model to an existing entity VideoTypeMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it VideoTypesRepository.Update(VideoTypeMapper.MapToEntity(model)); // Try to Save Changes VideoTypesRepository.SaveChanges(); // Return the new value return Get(existingEntity.Id); }