public IProfileModel Create(IProfileModel 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(ProfileMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = ProfileMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it ProfilesRepository.Add(newEntity); // Try to Save Changes ProfilesRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public IProfileModel Update(IProfileModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = ProfilesRepository.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 (ProfileMapper.AreEqual(model, existingEntity)) { return(ProfileMapper.MapToModel(existingEntity)); } // Map model to an existing entity ProfileMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it ProfilesRepository.Update(ProfileMapper.MapToEntity(model)); // Try to Save Changes ProfilesRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
public virtual IProfileSearchModel MapToSearchModel(IProfileModel model) { var searchModel = NameableEntityMapper.MapToSearchModel <IProfileModel, ProfileSearchModel>(model); // Search Properties // Return Search Model return(searchModel); }
/// <summary> /// Установить фото /// </summary> /// <param name="fileName"></param> public void SetPhoto(string fileName) { IProfileModel model = LecturerProvider.SetPhoto(fileName); this.Photo = model.Photo; Updated?.Invoke(this, EventArgs.Empty); }
public virtual bool AreEqual(IProfileModel model, IProfile entity) { return NameableEntityMapper.AreEqual(model, entity) // Profile Properties // <None> // Related Objects // <None> ; }
public virtual bool AreEqual(IProfileModel model, IProfile entity) { return(NameableEntityMapper.AreEqual(model, entity) // Profile Properties // <None> // Related Objects // <None> ); }
public static string ToDisplayName <TKey>(this IProfileModel <TKey> profile, string emptyResult) { if (string.IsNullOrEmpty(profile.FirstName) && string.IsNullOrEmpty(profile.LastName)) { return(emptyResult); } else { return(profile.FirstName + " " + profile.LastName); } }
public virtual void MapToEntity(IProfileModel model, ref IProfile entity, int currentDepth = 1) { currentDepth++; // Assign Base properties NameableEntityMapper.MapToEntity(model, ref entity); // Profile Properties // <None> // Related Objects // <None> // Associated Objects entity.OriginProfiles = model.OriginProfiles?.Where(i => i.Active).Select(OriginProfileMapperExtensions.MapToEntity).ToList(); }
public virtual IProfile MapToEntity(IProfileModel model, int currentDepth = 1) { currentDepth++; var entity = NameableEntityMapper.MapToEntity<Profile, IProfileModel>(model); // Profile Properties // <None> // Related Objects // <None> // Associated Objects entity.OriginProfiles = model.OriginProfiles?.Where(i => i.Active).Select(OriginProfileMapperExtensions.MapToEntity).Cast<OriginProfile>().ToList(); // Return Entity return entity; }
private void Model_Updated(object sender, EventArgs e) { Model = sender as IProfileModel; lock (views) { views .ToList() .ForEach((x) => { x.Update(Model); }); } }
public virtual IProfile MapToEntity(IProfileModel model, int currentDepth = 1) { currentDepth++; var entity = NameableEntityMapper.MapToEntity <Profile, IProfileModel>(model); // Profile Properties // <None> // Related Objects // <None> // Associated Objects entity.OriginProfiles = model.OriginProfiles?.Where(i => i.Active).Select(OriginProfileMapperExtensions.MapToEntity).Cast <OriginProfile>().ToList(); // Return Entity return(entity); }
public void Verify_Update_WithDuplicateData_Should_NotAddAndReturnOriginal() { // Arrange var entity = ProfilesMockingSetup.DoMockingSetupForProfile(1); var mockProfilesRepository = ProfilesMockingSetup.DoMockingSetupForRepository(); mockProfilesRepository.Setup(m => m.Get(It.IsAny <int>())).Returns(() => entity.Object); var businessWorkflow = new ProfilesBusinessWorkflow(mockProfilesRepository.Object, new ProfileMapper()); var model = ProfilesMockingSetup.DoMockingSetupForProfileModel(1); IProfileModel 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 static string ToDisplayPhoneNumber <TKey>(this IProfileModel <TKey> profile, string emptyResult) { if (string.IsNullOrEmpty(profile.PhoneNumber) && string.IsNullOrEmpty(profile.MobilePhoneNumber)) { return(emptyResult); } else if (!string.IsNullOrEmpty(profile.PhoneNumber)) { return(profile.PhoneNumber); } else if (!string.IsNullOrEmpty(profile.MobilePhoneNumber)) { return(profile.MobilePhoneNumber); } else { return(emptyResult); } }
public IProfileModel Create(IProfileModel 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(ProfileMapper.MapToSearchModel(model)); if (results.Any()) { return results.First(); } // Return the first that matches // Map model to a new entity var newEntity = ProfileMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it ProfilesRepository.Add(newEntity); // Try to Save Changes ProfilesRepository.SaveChanges(); // Return the new value return Get(newEntity.Id); }
public static bool AreEqual(this IProfileModel model, IProfile entity) { return(Mapper.AreEqual(model, entity)); }
public virtual IProfileSearchModel MapToSearchModel(IProfileModel model) { var searchModel = NameableEntityMapper.MapToSearchModel<IProfileModel, ProfileSearchModel>(model); // Search Properties // Return Search Model return searchModel; }
public ProfilePresenter(IProfileModel model) { this.Model = model; this.Model.Updated += Model_Updated; }
public static IProfileSearchModel MapToSearchModel(this IProfileModel model) { return(Mapper.MapToSearchModel(model)); }
public static IProfile MapToEntity(this IProfileModel model, int currentDepth = 1) { return(Mapper.MapToEntity(model, currentDepth)); }
public IProfileModel Update(IProfileModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = ProfilesRepository.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 (ProfileMapper.AreEqual(model, existingEntity)) { return ProfileMapper.MapToModel(existingEntity); } // Map model to an existing entity ProfileMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it ProfilesRepository.Update(ProfileMapper.MapToEntity(model)); // Try to Save Changes ProfilesRepository.SaveChanges(); // Return the new value return Get(existingEntity.Id); }
public static string ToDisplaySignUpDate <TKey>(this IProfileModel <TKey> profile) { return(profile.SignUpDate.ToString("D")); }
public static void MapToEntity(this IProfileModel model, ref IProfile entity, int currentDepth = 1) { Mapper.MapToEntity(model, ref entity, currentDepth); }