public async Task <bool> EnsureHistoryChangedAsync(string currentVersion, int departmentCount, int employeeCount) { using (var db = new ServiceDbContext(this._dbOptions)) { var latestHistory = await db.MdmDataHistories.OrderByDescending(u => u.SyncTime).FirstOrDefaultAsync(); if (latestHistory == null || latestHistory.HistoryVersion != currentVersion) { return(true); } return(false); } }
public async Task TestSearchByKeywordAsync() { var(connection, options) = OpenDb(); try { var dep1 = new Department { Id = Guid.NewGuid(), Number = "1", Name = "sclq" }; var dep2 = new Department { Id = Guid.NewGuid(), ParentId = dep1.Id, Number = "2", Name = "sclqgs" }; var dep3 = new Department { Id = Guid.NewGuid(), ParentId = dep1.Id, Number = "3", Name = "sclqjt" }; using (var db = new ServiceDbContext(options)) { await db.Departments.AddRangeAsync(dep1, dep2, dep3); await db.SaveChangesAsync(); } var target = new DepartmentAppService(statelessServiceContext, options, CreateMapper()); var result = await target.SearchByKeywordAsync("sclq"); result.Count.Should().Be(3); result = await target.SearchByKeywordAsync("gs"); result.Count.Should().Be(1); } finally { connection.Close(); } }
/// <summary> /// Construtor /// </summary> /// <param name="context">Database context</param> /// <param name="telemetry">Telemetria ApplicationInsights</param> /// <param name="tProperties">Propriedades da telemetria</param> /// <param name="tMetrics">Metricas da telemetria</param> public AdsController(ServiceDbContext context, TelemetryClient telemetry, Dictionary <string, string> tProperties, Dictionary <string, double> tMetrics) { _context = context; _telemetry = telemetry; _tMetrics = tMetrics; _tProperties = tProperties; // Telemetry Inicializacao _tProperties.Clear(); _tMetrics.Clear(); _tProperties["MicroService"] = ApiResources.AppName; _tProperties["Version"] = ApiResources.ApiVersion; _tProperties["Controller"] = "Ads"; }
public static void SeedHostDb(ServiceDbContext context) { context.SuppressAutoSetTenantId = true; // Host seed new InitialHostDbBuilder(context).Create(); // Default tenant seed (in host database). new DefaultTenantBuilder(context).Create(); new TenantRoleAndUserBuilder(context, 1).Create(); //add my creators new ProgramTypeCreator(context).Create(); }
private static Patient AddPatient(ServiceDbContext context, string firstName, string lastName, float height, DateTime dob, float weight) { Patient p = new Patient() { FirstName = firstName, LastName = lastName, Height = height, DateOfBirth = dob, Weight = weight }; context.Patients.Add(p); return(p); }
private async Task FillInManualDataAsync(ServiceDbContext db, List <Department> departments, List <Position> positions, List <Employee> employees, List <EmployeePosition> employeePositions) { var manualDepartments = await db.Departments.Where(u => u.DataSourceType == DataSourceType.Manual).ToListAsync(); var manualPositions = await db.Positions.Where(u => u.DataSourceType == DataSourceType.Manual).ToListAsync(); var manualEmployees = await db.Employees.Where(u => u.DataSourceType == DataSourceType.Manual).ToListAsync(); var manualEmployeePositions = await db.EmployeePositions.Where(u => u.DataSourceType == DataSourceType.Manual).ToListAsync(); departments.AddRange(manualDepartments); positions.AddRange(manualPositions); employees.AddRange(manualEmployees); employeePositions.AddRange(manualEmployeePositions); }
public static void Main(string[] args) { var proxyRoot = ConfigurationManager.Configuration["PROXY_ROOT"]; var restClient = new RestClient(); var serviceDbContext = new ServiceDbContext(); var salesAccountsRepository = new SalesAccountRepository(serviceDbContext); var transactionManager = new TransactionManager(serviceDbContext); var growthPartnerLoader = new GrowthPartnerLoader( restClient, proxyRoot, transactionManager, salesAccountsRepository); growthPartnerLoader.Load(); }
public async Task <EmployeeDto> FindByUserNumberAsync(string userNumber) { Employee employee = null; using (var db = new ServiceDbContext(this._dbOption)) { employee = await db.Employees.FirstOrDefaultAsync(u => u.Number == userNumber); if (employee == null) { return(null); } } return(await this.FindByUserNameAsync(employee.UserName)); }
public async Task Consume(ConsumeContext <FullOrgData> context) { //sort: department,position,employee var message = context.Message; if (message.Contacts == null || message.Contacts.Count == 0 || message.OrgUnits == null || message.OrgUnits.Count == 0) { return; } if (!await this.EnsureHistoryChangedAsync(message.DataVersion, message.OrgUnits.Count, message.Contacts.Count)) { return; } var departments = this._mapper.Map <List <Department> >(message.OrgUnits); var positions = departments.SelectMany(u => u.Positions).ToList(); var employees = this._mapper.Map <List <Employee> >(message.Contacts); var employeePositions = employees.SelectMany(u => u.Positions).ToList(); employeePositions = this.RemoveRepeatAndNull(employeePositions); using (var db = new ServiceDbContext(_dbOptions)) { try { await this.FillInManualDataAsync(db, departments, positions, employees, employeePositions); await db.BulkInsertOrUpdateOrDeleteAsync(departments); await db.BulkInsertOrUpdateOrDeleteAsync(positions); await db.BulkInsertOrUpdateOrDeleteAsync(employees); await db.BulkInsertOrUpdateOrDeleteAsync(employeePositions); await db.SaveChangesAsync(); await db.SaveChangesAsync(); } catch (Exception ex) { throw; } } }
public async Task TestDeleteAsync_Success() { var(connection, options) = OpenDb(); try { var gp1 = new Group { Id = Guid.NewGuid(), Name = "aaa", Type = GroupType.CustomChat, CreatedBy = Guid.NewGuid(), Created = DateTimeOffset.UtcNow, Updated = DateTimeOffset.UtcNow, }; using (var db = new ServiceDbContext(options)) { await db.Groups.AddRangeAsync(gp1); await db.SaveChangesAsync(); } var target = new GroupAppService(statelessServiceContext, options, CreateMapper(), CreateMockSimpleKeyValueService(), Substitute.For <IBusControl>()); var result = await target.DeleteAsync(new GroupInput { Id = gp1.Id, CurrentUserId = gp1.CreatedBy, }); result.IsSuccess.Should().BeTrue(); using (var db = new ServiceDbContext(options)) { var entity = await db.Groups.FindAsync(gp1.Id); entity.Should().BeNull(); } } finally { connection.Close(); } }
/// <summary> /// Get the last used context, or a new one if needed. /// </summary> /// <returns></returns> public static ServiceDbContext GetLastOrNew() { if (context == null) { //Since a lot of old code generates a new context, this helps minimize refactoring if (ServiceDbContext.LastContext == null) { context = new ServiceDbContext(); } else { context = ServiceDbContext.LastContext; } } return(context); }
public async Task DeleteFileItemAsync(Guid fileId) { using (var db = new ServiceDbContext(_dbContextOptions)) { try { var result = db.FileItems.FirstOrDefault(fi => fi.Id.Equals(fileId)); if (result != null) { db.FileItems.Remove(result); await db.SaveChangesAsync(); } } catch (Exception e) { ServiceEventSource.Current.Message("DeleteFileItemAsync try delete file:{0},but do not found!,exception:{1}", fileId, e.ToString()); } } }
public async Task TestGetListByIdsAsync() { var(connection, options) = OpenDb(); try { var gp1 = new Group { Id = Guid.NewGuid(), Name = "aaa", Type = GroupType.CustomChat, Created = DateTimeOffset.UtcNow, Updated = DateTimeOffset.UtcNow, }; var gp2 = new Group { Id = Guid.NewGuid(), Name = "bbb", Type = GroupType.CustomChat, Created = DateTimeOffset.UtcNow, Updated = DateTimeOffset.UtcNow, }; using (var db = new ServiceDbContext(options)) { await db.Groups.AddRangeAsync(gp1, gp2); await db.SaveChangesAsync(); } var target = new GroupAppService(statelessServiceContext, options, CreateMapper(), CreateMockSimpleKeyValueService(), Substitute.For <IBusControl>()); var result = await target.GetListByIdsAsync(new List <Guid> { gp1.Id, gp2.Id }); result.Count.Should().Be(2); } finally { connection.Close(); } }
public void AddSeed(ServiceDbContext serviceDbContext) { serviceDbContext.DatacenterNode.Add(new DatacenterNode() { Name = "node01" }); serviceDbContext.DatacenterNode.Add(new DatacenterNode() { Name = "node02" }); serviceDbContext.DatacenterNode.Add(new DatacenterNode() { Name = "node03" }); serviceDbContext.DatacenterNode.Add(new DatacenterNode() { Name = "node04" }); serviceDbContext.SaveChanges(); }
public async Task <FileItemDto> UploadFileAsync(UploadInput param, Guid uploaderId) { using (var db = new ServiceDbContext(_dbContextOptions)) { var fileItem = new FileItem { Id = Guid.NewGuid(), DownloadAmount = 0, GroupId = param.GroupId, Name = param.FileName, StoreId = param.StoreId, UpdatedOn = DateTimeOffset.UtcNow, UploaderId = uploaderId, }; await db.FileItems.AddAsync(fileItem); await db.SaveChangesAsync(); return(_mapper.Map <FileItemDto>(fileItem)); } }
public AccomodationControllerTest() { var optionsBuilder = new DbContextOptionsBuilder <ServiceDbContext>(); optionsBuilder.UseSqlServer("server= DESKTOP-S9S847J\\SQLEXPRESS; database=JourneyService; integrated security=SSPI"); serviceDbContext = new ServiceDbContext(optionsBuilder.Options); unitOfWork = new UnitOfWork(serviceDbContext); accomodationRepository = new AccomodationRepository(serviceDbContext); accomodationResource = new AccomodationResource { Name = "AcomodationName_1", Description = "AccomodationDesciption_1", Location = new Location { MapPositionLatitude = 90.4, MapPositionLongitude = 128.123, }, Type = "AccomodationType_1", }; }
public async Task <string> DownloadFileAsync(Guid fileId) { using (var db = new ServiceDbContext(_dbContextOptions)) { try { var result = db.FileItems.FirstOrDefault(fi => fi.Id.Equals(fileId)); if (result != null) { result.DownloadAmount++; await db.SaveChangesAsync(); return(result.StoreId); } } catch (Exception e) { ServiceEventSource.Current.Message("DownloadFileAsync try download file:{0},but do not found!,exception:{1}", fileId, e.ToString()); } return(null); } }
protected static (SqliteConnection, DbContextOptions <ServiceDbContext>) OpenDb() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <ServiceDbContext>() //.UseLazyLoadingProxies() .EnableDetailedErrors() .EnableSensitiveDataLogging() .UseLoggerFactory(TestLoggerFactory) .UseSqlite(connection) .Options; // Create the schema in the database using (var context = new ServiceDbContext(options)) { context.Database.EnsureCreated(); } return(connection, options); }
public Task <List <FileItemDto> > GetFileItemsAsync(Guid groupId, int page, int pageCount = 20) { if (page <= 0) { throw new ArgumentOutOfRangeException("page", "page must > 0"); } using (var db = new ServiceDbContext(_dbContextOptions)) { var skip = (page - 1) * pageCount; var datas = db.FileItems.Where((item) => item.GroupId.Equals(groupId)).OrderByDescending(f => f.UpdatedOn).Skip(skip).Take(pageCount).ToList(); var result = new List <FileItemDto>(); if (datas != null) { foreach (var item in datas) { var data = _mapper.Map <FileItemDto>(item); result.Add(data); } } return(Task.FromResult(result)); } }
public void AddSeed(ServiceDbContext serviceDbContext) { serviceDbContext.Cluster.Add(new Cluster() { Name = "k3s-01", Id = "testId01", OrderId = 3000, State = "Ready" }); serviceDbContext.Cluster.Add(new Cluster() { Name = "k3s-02", Id = "testId02", OrderId = 3010, State = "Ready", DeleteAt = DateTime.UtcNow.AddDays(-1) }); serviceDbContext.Cluster.Add(new Cluster() { Name = "k3s-03", Id = "testId03", OrderId = 3020, State = "Ready" }); serviceDbContext.Cluster.Add(new Cluster() { Name = "k3s-04", Id = "testId04", OrderId = 3030, State = "Waiting", Cpu = 2, Node = 4 }); serviceDbContext.SaveChanges(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ServiceDbContext dbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseCors( builder => builder.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() ); app.UseWebSockets(); app.UseGraphQLWebSockets <AppSchema>("/graphql"); app.UseGraphQL <AppSchema>(); app.UseGraphQLPlayground(new GraphQLPlaygroundOptions()); app.UseHttpsRedirection(); app.UseMvc(); }
/// <summary> /// Gets a page of ads that are within a location. /// </summary> /// <returns></returns> public IList <Ad> GetAdsWithinLocation(int skip, int amount, string location) { if (amount > Throttle) { amount = Throttle; } IList <string> possibleLocationNames = GetPossibleLocationNames(location); ServiceDbContext db = DbContextControl.GetLastOrNew(); IQueryable <Ad> query = db.Ads.Include("Location") .Where(a => a.Location != null && possibleLocationNames.Contains(a.Location.Name)); var pagedQuery = query .OrderByDescending(a => a.DatePosted) .Skip(skip) .Take(amount) .Include(a => a.Author) .ToList(); return(pagedQuery); }
protected async virtual Task <T> InitializeViewModel <T>(ServiceDbContext context) where T : ViewModelBase, new() { var nurse = context.Nurses.Find(Guid.Parse(User.Claims.FirstOrDefault().Value)); T model = new T(); var patients = await context.Patients.Select(P => new NavbarPatientModel() { FirstName = P.FirstName, LastName = P.LastName, PatientId = P.Id }) .ToListAsync(); model.NavbarModel = new NavbarPartialModel() { NurseFirstName = nurse.FirstName, NurseLastName = nurse.LastName, Patients = patients }; return(model); }
private void ConvertToDbConnect(List <ContactEntityMsg> contacts) { var employees = new List <Employee>(); foreach (var contact in contacts) { var employee = new Employee() { Id = contact.ContactId, UserName = contact.UserName, UserId = contact.UserId, Name = contact.Name, Number = contact.Number, IdCardNo = contact.IdCardNo, Gender = contact.Gender, }; employees.Add(employee); } using (var db = new ServiceDbContext(_dbOptions)) { db.BulkInsertOrUpdateOrDelete(employees); } }
public async Task <List <EmployeeDto> > FindByUserNamesAsync(string[] userNames) { Check.NotNull(userNames); var emptyEmployees = new List <EmployeeDto>(); if (userNames.Length == 0) { return(emptyEmployees); } var names = this.ProcessUserNameIfContainsAt(userNames); using (var db = new ServiceDbContext(this._dbOption)) { var employees = await db.Employees.Where(u => names.Contains(u.UserName)).ToListAsync(); if (employees.Count == 0) { return(emptyEmployees); } var numbers = employees.Select(u => u.Number).ToList(); var auths = await db.EmployeeAuths.Where(u => numbers.Contains(u.Number)).ToListAsync(); foreach (var item in employees) { var auth = auths.FirstOrDefault(u => u.Number == item.Number); var employee = this._mapper.Map <EmployeeDto>(item); if (auth != null) { employee.Password = auth.Password.DecodeBase64(); } employee.Account = employee.UserName + "@scrbg.com"; emptyEmployees.Add(employee); } } return(emptyEmployees); }
public ImportBookTransportCodeRepository(ServiceDbContext serviceDbContext) { this.serviceDbContext = serviceDbContext; }
public SernosSequenceRepository(ServiceDbContext serviceDbContext) { this.serviceDbContext = serviceDbContext; }
public EmployeeRepository(ServiceDbContext serviceDbContext) { this.serviceDbContext = serviceDbContext; }
public HomeController(IServerRenderService serverRenderService, IMailService mailService, ICalendarService calendarService, ServiceDbContext db, IIdentityService identityService, IEmployeeService employeeService) { this._serverRenderService = serverRenderService; this._mailService = mailService; _calendarService = calendarService; _db = db; _identityService = identityService; _employeeService = employeeService; }
public EmployeeRepository(ServiceDbContext context) { _context = context; }