public FileService(IPosDataService posDataService, IPosColumnMapService posColumnMapService, IUploadLogService uploadLogSerivice, ILoginService loginService, FileAdapterFactory fileAdapterFactory, IPosService posService, ICommonFileService commonFileService) { this._posDataService = posDataService; this._posColumnMapService = posColumnMapService; this._uploadLogService = uploadLogSerivice; this._loginService = loginService; this._fileAdapterFactory = fileAdapterFactory; this._posService = posService; this._commonFileService = commonFileService; }
public async Task <Tuple <Terminal, Employee> > ReserveEmployeeAndTerminal(Job job, Guid clientId) { IPosDataService posDataService = null; // Get free tenant for this job var tenant = await _db.Tenants.AsNoTracking().FirstOrDefaultAsync(t => t.JobId == job.JobId); if (tenant == null) { tenant = await _db.Tenants.FirstOrDefaultAsync(t => t.ServerId == job.ServerId && t.JobId == null); if (tenant != null) { tenant.JobId = job.JobId; await _db.SaveChangesAsync(); } else { if (posDataService == null) { posDataService = CreatePosfDatService(job.Server, tenant); } // TODO: create new tenant throw new NotImplementedException(); } } // Get free store for this tenant var stores = await _db.Stores.AsNoTracking().Where(s => s.TenantId == tenant.TenantId && s.JobId == job.JobId).ToListAsync(); var storeIds = stores.Select(s => s.StoreId).ToArray(); if (!stores.Any()) { if (posDataService == null) { posDataService = CreatePosfDatService(job.Server, tenant); } // TODO: create new store throw new NotImplementedException(); } // get free terminal and employee var terminal = await _db.Terminals.Include(p => p.Tenant).FirstOrDefaultAsync(t => storeIds.Contains(t.StoreId) && t.ClientId == null); if (terminal == null) { if (posDataService == null) { posDataService = CreatePosfDatService(job.Server, tenant); } terminal = await posDataService.CreateNewTerminal(tenant.TenantId, storeIds.Random()); } var employee = await _db.Employees.FirstOrDefaultAsync(e => storeIds.Contains(e.StoreId.Value) && e.ClientId == null); if (employee == null) { if (posDataService == null) { posDataService = CreatePosfDatService(job.Server, tenant); } employee = await posDataService.CreateNewEmployee(tenant.TenantId, storeIds.Random()); } terminal.ClientId = clientId; employee.ClientId = clientId; await _db.SaveChangesAsync(); _db.Entry(terminal).State = EntityState.Detached; _db.Entry(employee).State = EntityState.Detached; terminal.Tenant = tenant; return(new Tuple <Terminal, Employee>(terminal, employee)); }