public IGenderModel Create(IGenderModel 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(GenderMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = GenderMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it GendersRepository.Add(newEntity); // Try to Save Changes GendersRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public IGenderModel Update(IGenderModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = GendersRepository.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 (GenderMapper.AreEqual(model, existingEntity)) { return(GenderMapper.MapToModel(existingEntity)); } // Map model to an existing entity GenderMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it GendersRepository.Update(GenderMapper.MapToEntity(model)); // Try to Save Changes GendersRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public virtual IGenderSearchModel MapToSearchModel(IGenderModel model) { var searchModel = NameableEntityMapper.MapToSearchModel <IGenderModel, GenderSearchModel>(model); // Search Properties // Return Search Model return(searchModel); }
public virtual bool AreEqual(IGenderModel model, IGender entity) { return NameableEntityMapper.AreEqual(model, entity) // Gender Properties // <None> // Related Objects // <None> ; }
public virtual bool AreEqual(IGenderModel model, IGender entity) { return(NameableEntityMapper.AreEqual(model, entity) // Gender Properties // <None> // Related Objects // <None> ); }
public virtual void MapToEntity(IGenderModel model, ref IGender entity, int currentDepth = 1) { currentDepth++; // Assign Base properties NameableEntityMapper.MapToEntity(model, ref entity); // Gender Properties // <None> // Related Objects // <None> // Associated Objects entity.Characters = model.Characters?.Where(i => i.Active).Select(CharacterMapperExtensions.MapToEntity).ToList(); entity.People = model.People?.Where(i => i.Active).Select(PersonMapperExtensions.MapToEntity).ToList(); }
public virtual IGender MapToEntity(IGenderModel model, int currentDepth = 1) { currentDepth++; var entity = NameableEntityMapper.MapToEntity<Gender, IGenderModel>(model); // Gender Properties // <None> // Related Objects // <None> // Associated Objects entity.Characters = model.Characters?.Where(i => i.Active).Select(CharacterMapperExtensions.MapToEntity).Cast<Character>().ToList(); entity.People = model.People?.Where(i => i.Active).Select(PersonMapperExtensions.MapToEntity).Cast<Person>().ToList(); // Return Entity return entity; }
public virtual IGender MapToEntity(IGenderModel model, int currentDepth = 1) { currentDepth++; var entity = NameableEntityMapper.MapToEntity <Gender, IGenderModel>(model); // Gender Properties // <None> // Related Objects // <None> // Associated Objects entity.Characters = model.Characters?.Where(i => i.Active).Select(CharacterMapperExtensions.MapToEntity).Cast <Character>().ToList(); entity.People = model.People?.Where(i => i.Active).Select(PersonMapperExtensions.MapToEntity).Cast <Person>().ToList(); // Return Entity return(entity); }
public PatientPresenter(IPatientSearchForm patientSearchView, IPatientModel model, IGenderModel modelGender) { this.patientSearchView = patientSearchView; this.patientModel = model; this.genderModel = modelGender; genderModel.GetGender(); this.patientSearchView.DataSourceGender = genderModel.ListGender; this.patientSearchView.LoadDataDataEvent += GetAllPatientsFromModelEventHandler; this.patientSearchView.PatientDetailData.AddOrUpdatePatientEvent += AddOrUpdatePatientEventHandler; this.patientSearchView.EditPatientEvent += EditPatientEventHandler; this.patientSearchView.DeletePatientEvent += DeletePatientEventHandler; this.patientSearchView.SaveDataToModelEvent += SaveDataToModelEventHandler; this.patientSearchView.ShowPatientDataEvent += ShowPatientDataEventHandler; this.patientSearchView.ShowOrdersEvent += ShowOrdersEventHandler; }
public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal() { // Arrange var entity = GendersMockingSetup.DoMockingSetupForGender(1); var mockGendersRepository = GendersMockingSetup.DoMockingSetupForRepository(); mockGendersRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object); var businessWorkflow = new GendersBusinessWorkflow(mockGendersRepository.Object, new GenderMapper()); var model = GendersMockingSetup.DoMockingSetupForGenderModel(1); IGenderModel 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 IGenderModel Create(IGenderModel 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(GenderMapper.MapToSearchModel(model)); if (results.Any()) { return results.First(); } // Return the first that matches // Map model to a new entity var newEntity = GenderMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it GendersRepository.Add(newEntity); // Try to Save Changes GendersRepository.SaveChanges(); // Return the new value return Get(newEntity.Id); }
public IGenderModel Update(IGenderModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = GendersRepository.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 (GenderMapper.AreEqual(model, existingEntity)) { return GenderMapper.MapToModel(existingEntity); } // Map model to an existing entity GenderMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it GendersRepository.Update(GenderMapper.MapToEntity(model)); // Try to Save Changes GendersRepository.SaveChanges(); // Return the new value return Get(existingEntity.Id); }
public static bool AreEqual(this IGenderModel model, IGender entity) { return(Mapper.AreEqual(model, entity)); }
public static IGenderSearchModel MapToSearchModel(this IGenderModel model) { return(Mapper.MapToSearchModel(model)); }
public static IGender MapToEntity(this IGenderModel model, int currentDepth = 1) { return(Mapper.MapToEntity(model, currentDepth)); }
public static void MapToEntity(this IGenderModel model, ref IGender entity, int currentDepth = 1) { Mapper.MapToEntity(model, ref entity, currentDepth); }
public virtual IGenderSearchModel MapToSearchModel(IGenderModel model) { var searchModel = NameableEntityMapper.MapToSearchModel<IGenderModel, GenderSearchModel>(model); // Search Properties // Return Search Model return searchModel; }