public async Task <long> TotalCountAsync() { using (OtherContext ctx = new OtherContext()) { BaseService <SettingEntity> bs = new BaseService <SettingEntity>(ctx); return(await bs.TotalCountAsync()); } }
public async Task MarkDeleteAsync(long id) { using (OtherContext ctx = new OtherContext()) { BaseService <SettingEntity> bs = new BaseService <SettingEntity>(ctx); await bs.MarkDeleteAsync(id); } }
public async Task <SettingDTO> GetByIdAsync(long id) { using (OtherContext ctx = new OtherContext()) { BaseService <SettingEntity> bs = new BaseService <SettingEntity>(ctx); var setting = await bs.GetAll().AsNoTracking().SingleOrDefaultAsync(e => e.Id == id); return(setting == null ? null : TODTO(setting)); } }
public async Task <SettingDTO> GetByKeyAsync(string keyPari) { using (OtherContext ctx = new OtherContext()) { BaseService <SettingEntity> bs = new BaseService <SettingEntity>(ctx); var setting = await bs.GetAll().AsNoTracking().SingleOrDefaultAsync(e => e.KeyPari == keyPari); return(setting == null ? null : TODTO(setting)); } }
public async Task <AppInfoDTO> GetByAppKeyAsync(string appKey) { using (OtherContext ctx = new OtherContext()) { BaseService <AppInfoEntity> bs = new BaseService <AppInfoEntity>(ctx); var res = await bs.GetAll().AsNoTracking().SingleOrDefaultAsync(e => e.AppKey == appKey); return(res == null ? null : TODTO(res)); } }
public async Task UpdateAsync(long id, string keyPari, string key, string value) { using (OtherContext ctx = new OtherContext()) { BaseService <SettingEntity> bs = new BaseService <SettingEntity>(ctx); var en = await bs.GetAll().SingleAsync(e => e.Id == id); en.KeyPari = keyPari; en.Key = key; en.Value = value; await ctx.SaveChangesAsync(); } }
public async Task <long> AddNewAsync(string keyPari, string key, string value) { SettingEntity entity = new SettingEntity(); entity.Key = key; entity.KeyPari = keyPari; entity.Value = value; using (OtherContext ctx = new OtherContext()) { await ctx.Settings.AddAsync(entity); await ctx.SaveChangesAsync(); return(entity.Id); } }
public static void SeedData() { using (var context = new OtherContext()) { context.Database.EnsureCreated(); if (context.Tours.Any()) { return; } var countries = new Faker <Country>() .RuleFor(x => x.Name, x => x.Address.Country()) .Generate(100); var cities = new Faker <City>() .RuleFor(x => x.Name, x => x.Address.City()) .RuleFor(x => x.Country, x => x.PickRandom(countries)) .Generate(300); var dateNow = DateTime.Now; var hotels = new Faker <Hotel>() .RuleFor(x => x.Address, x => $"{x.Address.StreetAddress()}, {x.Address.BuildingNumber()}") .RuleFor(x => x.Name, x => x.Company.CompanyName()) .RuleFor(x => x.City, x => x.PickRandom(cities)) .RuleFor(x => x.YearOfCreation, x => x.Date.Past(50, dateNow).Year) .Generate(6000); var apartmentTypes = new[] { "standard", "luxe", "deluxe" }; var tours = new Faker <Tour>() .RuleFor(x => x.Provider, "Other") .RuleFor(x => x.ApartmentType, x => x.PickRandom(apartmentTypes)) .RuleFor(x => x.DateDeparture, x => x.Date.Future()) .RuleFor(x => x.DateArrival, (x, y) => x.Date.Soon(4, y.DateDeparture)) .RuleFor(x => x.DateRegistration, (x, y) => x.Date.Soon(1, y.DateArrival)) .RuleFor(x => x.NightCount, x => x.Random.Number(1, 20)) .RuleFor(x => x.PricePerPerson, x => x.Random.Decimal(100, 1000)) .RuleFor(x => x.AirlineName, x => x.Company.CompanyName()) .RuleFor(x => x.RoomCapacity, x => x.Random.Number(1, 8)) .RuleFor(x => x.CityDeparture, x => x.PickRandom(cities)) .RuleFor(x => x.CityArrival, x => x.PickRandom(cities)) .RuleFor(x => x.Hotel, x => x.PickRandom(hotels)) .Generate(10000); context.Tours.AddRange(tours); context.SaveChanges(); } }
public async Task <List <SettingDTO> > GetPageDataAsync(int pageIndex = 1, int pageDataCount = 10) { using (OtherContext ctx = new OtherContext()) { BaseService <SettingEntity> bs = new BaseService <SettingEntity>(ctx); List <SettingDTO> list = new List <SettingDTO>(); await bs.GetAll().AsNoTracking() .OrderByDescending(e => e.CreateTime) .Skip((pageIndex - 1) * pageDataCount) .Take(pageDataCount) .ForEachAsync(e => { list.Add(TODTO(e)); }); return(list); } }
public async Task <long> AddNewAsync(AddAppInfoDTO dot) { AppInfoEntity entity = new AppInfoEntity(); entity.AppKey = dot.AppKey; entity.AppSecret = dot.AppSecret; entity.Email = dot.Email; using (OtherContext ctx = new OtherContext()) { BaseService <AppInfoEntity> bs = new BaseService <AppInfoEntity>(ctx); var appinfo = await bs.GetAll().SingleOrDefaultAsync(e => e.Email == dot.Email); if (appinfo != null) { throw new Exception("邮箱已存在"); } await ctx.AppInfos.AddAsync(entity); await ctx.SaveChangesAsync(); return(entity.Id); } }
// Uses dependency injection public DbContextFactory(TodoContext todoContext, OtherContext otherContext) { this.todoContext = todoContext; this.otherContext = otherContext; }
public OtherSearchService(OtherContext otherContext) { _otherContext = otherContext ?? throw new ArgumentNullException(nameof(otherContext)); }
private void OtherButton_Click(object sender, EventArgs e) { OtherContext.Show(OtherButton, new Point(1, OtherButton.Height - 1)); }