public async Task <IActionResult> PutSettingEntity([FromRoute] int id, [FromBody] SettingEntity settingEntity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != settingEntity.Id) { return(BadRequest()); } _context.Entry(settingEntity).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SettingEntityExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Given_BasicTypeSettingWithDescriminator_When_MultiDescriminatorKeyInValid_Then_SettingNotRetrieved() { var context = this.Fixture.GetContext <ConfigurationContext>(); var section = new SectionEntity() { ApplicationName = "EFConfigurationProviderTests", SectionName = "appSettings4", Aspect = "Application", Discriminator = @"{""Environment"":""Testing""}", ModifiedUser = "******" }; context.Sections.Add(section); context.SaveChanges(); var setting = new SettingEntity() { SectionId = section.Id, Key = "TestSetting4", Json = @"""Test Value""", ModifiedUser = "******" }; setting.ValueType = null; context.Settings.Add(setting); context.SaveChanges(); this.Fixture.ClearChangeTracker(); var builder = new ConfigurationBuilder().AddEntityFrameworkConfig(context, "EFConfigurationProviderTests", @"{""Environment"":""Testing"", ""Username"":""Patrick""}"); var configuration = builder.Build(); var value = configuration.GetValue <string>("TestSetting4"); Assert.Null(value); }
/// <summary> /// Сохранить все настройки /// </summary> /// <param name="repository"></param> public virtual async Task Save(IRepository <SettingEntity> repository) { var spec = new SettingsBaseSpecification(_name); // 5 load existing settings for this type var settings = await repository.GetAsync(spec); foreach (var propertyInfo in _properties) { var propertyValue = propertyInfo.GetValue(this, null); var value = propertyInfo.PropertyType.Name switch { "IEnumerable`1" => JsonConvert.SerializeObject(propertyValue), "DateTime" => Convert.ToDateTime(propertyValue).ToString("s"), _ => propertyValue?.ToString() ?? string.Empty, }; var setting = settings.SingleOrDefault(s => s.Name == propertyInfo.Name); if (setting != null) { // 6 update existing value setting.Value = value; await repository.UpdateAsync(setting); } else { // 7 create new setting var newSetting = new SettingEntity { Name = propertyInfo.Name, Type = _name, Value = value, }; await repository.CreateAsync(newSetting); } } }
private static async Task CreateDefaultSetting(DatabaseContext context) { var entity = context.Set <SettingEntity>(); var settings = await entity.ToListAsync(); if (settings.Count == 0) { var setting = new SettingEntity() { MoneyToPoint = 1000000, PointToMoney = 10000, CompanyEmail = "*****@*****.**", CompanyAddress = "123 Phạm Văn Đồng,P.13, Q.Bình Thạnh, Tp. Hồ Chí Minh", CompanyFax = "08.5556677", CompanyName = "Công ty TNHH TMDV Michelin", CompanyPhone = "08.5556677", CompanyWebsite = "michelin.vn", OldTruckTireWarmingDays = 100, OldProductWarmingDays = 100, OldTravelTireWarmingDays = 100, IsAllowNegativeInventoryBill = true, IsOnlyDestroyBillOnSameDay = true, CompanyDescription = "Trung tâm vỏ xe ô tô -cân chỉnh thước lại - phụ tùng ô tô", IsAllowUsingPoint = false, CanSaleWithDebtForRetailBill = true }; await entity.AddAsync(setting); await context.SaveChangesAsync(); } }
public void SetCtls(SettingEntity entity) { if (InvokeRequired) { this.Invoke(new Action(() => { SetCtls(entity); })); return; } LV_Setting.Items.Clear(); var properties = entity.GetType().GetProperties(); foreach (var p in properties) { var attr = Attribute.GetCustomAttribute(p, typeof(DescriptionAttribute)); if (null != attr) { var desc = (DescriptionAttribute)attr; if (Convert.ToBoolean(p.GetValue(entity))) { LV_Setting.Items.Add(new ListViewItem(new string[] { desc.Name, string.Format("{0}{1}", p.GetValue(entity), desc.Unit) })); } } } }
public async Task ConfigurationValueShouldNotChangeAfterChangeOnDb() { //Arrange DbConnection connection = new SqlConnection(_fixture.TestSettings.MssqlConnectionString); ConfigurationBuilder configuration = new ConfigurationBuilder(); configuration.Sources.Clear(); configuration.AddEFCoreConfiguration <PersonDbContext>( options => options.UseSqlServer(connection), reloadOnChange: true, pollingInterval: 500); //Act IConfigurationRoot configurationRoot = configuration.Build(); IChangeToken reloadToken = configurationRoot.GetReloadToken(); using var transaction = Connection.BeginTransaction(); using var context = CreateContext(transaction); SettingEntity setting = context.Find <SettingEntity>("TheValueWillBeChanged", "", ""); setting.Value = "This is the way!"; context.Update(setting); context.SaveChanges(); transaction.Commit(); await Task.Delay(1000); //Assert Assert.False(reloadToken.HasChanged); Assert.Equal("This is the way!", configurationRoot.GetValue <string>("TheValueWillBeChanged")); }
public void Given_AddSetting_When_ValueIsComplexType_Then_SettingIsPersisted() { var context = this.Fixture.GetContext <ConfigurationContext>(); var section = new SectionEntity() { ApplicationName = "DbContextSettingTests", SectionName = "TestSection1", ModifiedUser = "******" }; context.Sections.Add(section); context.SaveChanges(); var setting = new SettingEntity() { SectionId = section.Id, Key = "default", ModifiedUser = "******" }; setting.SetValue(new TestSection() { Id = Guid.NewGuid(), Name = "Test" }); context.Settings.Add(setting); context.SaveChanges(); var retrieved = context.Settings.FirstOrDefault(s => s.SectionId == section.Id && s.Key == "default"); Assert.NotNull(retrieved); Assert.NotNull(retrieved.GetValue <TestSection>()); }
public void Given_BasicTypeSetting_When_IsValid_Then_SettingRetrieved() { var context = this.Fixture.GetContext <ConfigurationContext>(); var section = new SectionEntity() { ApplicationName = "EFConfigurationProviderTests", SectionName = "appSettings", Aspect = "Application", ModifiedUser = "******" }; context.Sections.Add(section); context.SaveChanges(); var setting = new SettingEntity() { SectionId = section.Id, Key = "TestSetting", Json = @"Test Value", ModifiedUser = "******" }; setting.ValueType = null; context.Settings.Add(setting); context.SaveChanges(); this.Fixture.ClearChangeTracker(); var builder = new ConfigurationBuilder().AddEntityFrameworkConfig(context, "EFConfigurationProviderTests"); var configuration = builder.Build(); var value = configuration.GetValue <string>("TestSetting"); Assert.True(value == "Test Value"); }
public Task <int> UpdateForm(SettingEntity entity, bool isPartialUpdate = false) { //if (entity.F_EnabledMark == null) //{ // entity.F_EnabledMark = true; //} return(_service.UpdateAsync(entity, isPartialUpdate)); }
private static void WriteBaseSettingModelValues(BaseSettingModel model, SettingEntity entity) { model.Name = entity.Name; model.Guid = entity.Guid; model.SettingKey = entity.SettingKey; model.Value = entity.Value; model.IsImmutable = entity.IsImmutable; }
public SettingDTO Entity2DTO(SettingEntity a) { return(new SettingDTO() { CreateDateTime = a.CreateDateTime, Id = a.Id, Name = a.Name, Value = a.Value }); }
private SettingDTO ToDTO(SettingEntity entity) { SettingDTO dto = new SettingDTO(); dto.Id = entity.Id; dto.Parm = entity.Parm; dto.Name = entity.Name; dto.TypeId = entity.TypeId; return(dto); }
public Task <int> InsertForm(SettingEntity entity) { if (entity.F_EnabledMark == null) { entity.F_EnabledMark = true; } entity.F_CreatorUserId = _usersService.GetCurrentUserId(); return(_service.InsertAsync(entity)); }
public Setting() { InitializeComponent(); SettingDAO settingDAO = new SettingDaoImpl(); SettingEntity entity = settingDAO.Find(); this.ComicTxt.Text = entity.ComicUrl; }
private SettingDTO ToDTO(SettingEntity setting) { SettingDTO dto = new SettingDTO(); dto.Id = setting.Id; dto.Name = setting.Name; dto.Value = setting.Value; dto.CreateDateTime = setting.CreateDateTIme; return(dto); }
private SettingDTO TODTO(SettingEntity entity) { SettingDTO dto = new SettingDTO(); dto.CreateTime = entity.CreateTime; dto.Id = entity.Id; dto.Key = entity.Key; dto.KeyPari = entity.KeyPari; dto.Value = entity.Value; return(dto); }
/// <inheritdoc /> public async Task DeleteAsync(SettingType type) { SettingEntity settingEntity = await _settingsRepository.GetByTypeAsync(type); if (settingEntity == null) { throw new NotFoundException(); } await _settingsRepository.DeleteAsync(settingEntity); }
public void Given_ComplexTypeSectionWithChildren_When_IsValid_Then_SectionRetrieved() { var context = this.Fixture.GetContext <ConfigurationContext>(); var section = new SectionEntity() { ApplicationName = "EFConfigurationProviderTests", SectionName = "TestSection3", Aspect = "Application", ModifiedUser = "******" }; context.Sections.Add(section); context.SaveChanges(); var value = new TestSectionWithChildren() { Id = Guid.NewGuid(), Name = "Test1" }; value.Children = new Collection <TestSectionChild>(); value.Children.Add ( new TestSectionChild() { Id = Guid.NewGuid(), Name = "Test1" } ); var setting = new SettingEntity() { SectionId = section.Id, Key = "default", ModifiedUser = "******" }; setting.SetValue(value); context.Settings.Add(setting); context.SaveChanges(); this.Fixture.ClearChangeTracker(); var builder = new ConfigurationBuilder().AddEntityFrameworkConfig(context); var configuration = builder.Build(); var configSection = configuration.GetSection <TestSectionWithChildren>("TestSection3", false); Assert.NotNull(configSection); Assert.NotNull(configSection.Children); var child = configSection.Children.FirstOrDefault(); Assert.NotNull(child); Assert.Equal(value.Children.First().Id, child.Id); Assert.Equal(value.Children.First().Name, child.Name); }
public async Task <IActionResult> PostSettingEntity([FromBody] SettingEntity settingEntity) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Settings.Add(settingEntity); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSettingEntity", new { id = settingEntity.Id }, settingEntity)); }
public async Task GetByTypeAsync_FiltersByUserIdAndType() { var userId = _settingsData.First().UserId; SettingType type = _settingsData.First().Type; _userHelperMock.SetupGet(p => p.UserId).Returns(userId); SettingEntity expectedResult = _settingsData.Single(s => s.UserId == userId && s.Type == type); SettingEntity actualResult = await _settingsRepository.GetByTypeAsync(type); Assert.AreEqual(expectedResult, actualResult); }
private void OnSave(object sender, EventArgs e) { SettingEntity entity = new SettingEntity(); entity.StationName = txtStationName.Text; //entity.Address = txtAddress.Text; entity.PortNo = txtPortNo.Text; if (ChangeEvent != null) { this.ChangeEvent(entity); } }
public void BindSettings() { SettingEntity setting = settingHelper.GetSettings(); txtMonthlyTarget.Text = setting.MaxTarget; txtEmails.Text = setting.AdminEmails; txtProcEmail.Text = setting.ProcessedEmails; txtVoidedEmail.Text = setting.VoidedEmails; txtRefundEmail.Text = setting.RefundEmails; txtMobLog1.Text = setting.Mob_login_text1; txtMobLog2.Text = setting.Mob_login_text2; }
public async Task <SettingDTO> GetModelAsync(long id) { using (MyDbContext dbc = new MyDbContext()) { SettingEntity entity = await dbc.GetAll <SettingEntity>().AsNoTracking().SingleOrDefaultAsync(g => g.Id == id); if (entity == null) { return(null); } return(ToDTO(entity)); } }
private SettingDTO ToDTO(SettingEntity entity) { SettingDTO dto = new SettingDTO(); dto.Id = entity.Id; dto.LevelId = entity.LevelId; dto.Name = entity.Name; dto.Param = entity.Param; dto.Remark = entity.Remark; dto.TypeId = entity.TypeId; dto.TypeName = entity.TypeName; return(dto); }
public SettingEntity Update(SettingEntity entity) { try { _settingRepository.Update(entity); return(entity); } catch (Exception e) { _log.Error(e, "数据库操作出错"); return(null); } }
public bool Delete(SettingEntity entity) { try { _settingRepository.Delete(entity); return(true); } catch (Exception e) { _log.Error(e, "数据库操作出错"); return(false); } }
private SettingDTO ToDTO(SettingEntity entity) { SettingDTO dto = new SettingDTO(); dto.CreateTime = entity.CreateTime; dto.Id = entity.Id; dto.Name = entity.Name; dto.Description = entity.Description; dto.TypeName = entity.SettingType.Name; dto.TypeDescription = entity.SettingType.Description; dto.Parm = entity.Parm; return(dto); }
public async Task <SettingDTO> GetModelByNameAsync(string name) { using (MyDbContext dbc = new MyDbContext()) { SettingEntity entity = await dbc.GetAll <SettingEntity>().Include(s => s.Type).AsNoTracking().SingleOrDefaultAsync(g => g.Name == name); if (entity == null) { return(null); } return(ToDTO(entity)); } }
/// <summary> /// Patch CatalogBase type /// </summary> /// <param name="source"></param> /// <param name="target"></param> public static void Patch(this SettingEntity source, SettingEntity target) { if (target == null) { throw new ArgumentNullException("target"); } if (!source.SettingValues.IsNullCollection()) { var comparer = AnonymousComparer.Create((SettingValueEntity x) => x.ToString(CultureInfo.InvariantCulture)); source.SettingValues.Patch(target.SettingValues, comparer, (sourceSetting, targetSetting) => { }); } }
/// <summary> /// The get value. /// </summary> /// <param name="key"> /// The key. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public string GetValue(string key) { string value = null; SettingEntity setting = this.SettingTable.SingleOrDefault(s => s.KeyName == key); if (setting != null) { value = setting.KeyValue; } return(value); }
/// <summary> /// Create a new SettingEntity object. /// </summary> /// <param name="id">Initial value of Id.</param> /// <param name="uuid">Initial value of Uuid.</param> /// <param name="owner">Initial value of Owner.</param> /// <param name="entryKey">Initial value of EntryKey.</param> public static SettingEntity CreateSettingEntity(int id, global::System.Guid uuid, string owner, string entryKey) { SettingEntity settingEntity = new SettingEntity(); settingEntity.Id = id; settingEntity.Uuid = uuid; settingEntity.Owner = owner; settingEntity.EntryKey = entryKey; return settingEntity; }
/// <summary> /// There are no comments for SettingEntitySet in the schema. /// </summary> public void AddToSettingEntitySet(SettingEntity settingEntity) { base.AddObject("SettingEntitySet", settingEntity); }