/// <summary> /// 初始化基本变量 /// </summary> /// <returns></returns> static bool Init() { var serverUser = GeneralProcess.GetUserByLoginName(AppConfig.ServerAccount); if (serverUser == null) { Log("通信管理员账号信息错误,请检查配置!"); return(false); } ProcessInvoke.SetupGlobalRepositoryContext(serverUser, serverUser.Domain); using (var context = new RepositoryDbContext()) { foreach (var data in AppConfig.CommandDatas) { ProduceDatas.Add(context.Set <CommandData>().First(obj => obj.DataName == data)); } foreach (var data in AppConfig.RunningTimeDatas) { RunningTimeDatas.Add(context.Set <CommandData>().First(obj => obj.DataName == data)); } _hotelGuids = context.Set <HotelRestaurant>().ToList(); } _produceEndDayHour = DateTime.Now.AddHours(-1).GetCurrentHour(); _produceEndDay = DateTime.Now.AddDays(-1).GetToday(); Log($"【{DateTime.Now:yyyy-MM-dd HH:mm:ss}】系统初始化完成。"); return(true); }
public List <HotelCleaness> GetHotelCleanessList() { using (var context = new RepositoryDbContext()) { ((IObjectContextAdapter)context).ObjectContext.CommandTimeout = 180; var checkDate = DateTime.Now.AddMinutes(-2); var commandDataId = context.Set <CommandData>().First(obj => obj.DataName == ProtocolDataName.CleanerCurrent).Id; var modelId = Guid.Parse("5306DA86-7B7C-40CF-933C-642061C24761"); var cleanNess = new List <HotelCleaness>(); foreach (var hotel in context.Set <HotelRestaurant>()) { var devs = context.Set <Device>().Where(dev => dev.ProjectId == hotel.Id).Select(item => item.Identity).ToList(); var lastProtocol = context.Set <ProtocolData>() .Where(d => devs.Contains(d.DeviceIdentity)) .OrderByDescending(dat => dat.UpdateTime) .FirstOrDefault(); if (lastProtocol != null && lastProtocol.UpdateTime >= checkDate) { var hotelData = context.Set <MonitorData>().FirstOrDefault(d => d.ProjectIdentity == hotel.Identity && d.ProtocolDataId == lastProtocol.Id && d.CommandDataId == commandDataId); if (hotelData == null) { cleanNess.Add(new HotelCleaness { DistrictGuid = hotel.DistrictId, ProjectName = hotel.ProjectName, ProjectCleaness = "无数据" }); } else { cleanNess.Add(new HotelCleaness { DistrictGuid = hotel.DistrictId, ProjectName = hotel.ProjectName, ProjectCleaness = hotelData.DoubleValue != null ? GetCleanRateByDeviceModel(hotelData.DoubleValue, modelId) : "无数据" }); } } else { cleanNess.Add(new HotelCleaness { DistrictGuid = hotel.DistrictId, ProjectName = hotel.ProjectName, ProjectCleaness = "无数据" }); } } return(cleanNess); } }
public async Task <NthChildInFamilyDTO> GetNthChildInFamily(int id) { // get mom var mom = await RepositoryDbContext.Set <Domain.PersonInRelationship>() .Where(w => w.Person1Id == id && w.Relationship.Relation == Relation.Ema) .Select(e => e.Person).FirstOrDefaultAsync(); // get dad var dad = await RepositoryDbContext.Set <Domain.PersonInRelationship>() .Where(w => w.Person1Id == id && w.Relationship.Relation == Relation.Isa) .Select(e => e.Person).FirstOrDefaultAsync(); // get children var childrenCount = await RepositoryDbContext.Set <Domain.PersonInRelationship>() .Include(i => i.Person) .Include(i => i.Person1) .Where(w => (dad != null && w.PersonId == dad.Id) && w.Relationship.Relation == Relation.Isa || (mom != null && w.PersonId == mom.Id) && w.Relationship.Relation == Relation.Ema) .Select(e => e.Person1).Distinct().CountAsync(); return(_personMapper.MapToNthChild( childrenCount, await RepositoryDbSet.Where(w => w.Id == id).FirstOrDefaultAsync())); }
/// <summary> /// 获取系统配置信息 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="exp"></param> /// <returns></returns> public static object GetConfig <T>(Expression <Func <T, bool> > exp) where T : class { using (var context = new RepositoryDbContext()) { return(context.Set <T>().Where(exp).ToList()); } }
public SignInResult PasswordSignIn(string loginName, string password, bool rememberMe, bool shouldLockout = false) { var result = new SignInResult(); using (var context = new RepositoryDbContext()) { var md5Password = Globals.GetMd5(password); var user = context.Set <WdUser>() .FirstOrDefault(obj => obj.LoginName == loginName && obj.Password == md5Password && obj.IsEnabled); if (user == null) { result.Status = SignInStatus.Failure; result.ErrorElement = "Password"; result.ErrorMessage = "无效的用户名或登陆密码"; return(result); } FormsAuthentication.SetAuthCookie(loginName, false); user.LastLoginDateTime = DateTime.Now; context.SaveChanges(); } result.Status = SignInStatus.Success; return(result); }
/// <summary> /// 获取油烟设备型号信息 /// </summary> /// <returns></returns> public static List <LampblackDeviceModel> GetDeviceModels() { using (var context = new RepositoryDbContext()) { return(context.Set <LampblackDeviceModel>().ToList()); } }
private async Task <FamilyTreeDTO> GetRelatedPeople(Person childPerson, FamilyTreeDTO familyTree) { var personsQueue = new Queue <Person>(); familyTree.Family = new List <FamilyTreeDTO>(); // get all related persons var relatedPeople = await RepositoryDbContext.Set <Domain.PersonInRelationship>() .Include(i => i.Person) .Include(i => i.Person1) .Include(i => i.Relationship) .Where(w => w.PersonId == childPerson.Id) .Select(e => e.Person1).Distinct().ToListAsync(); IdsToExclude.Add(childPerson.Id); familyTree.Id = childPerson.Id; familyTree.FirstName = childPerson.FirstName; familyTree.LastName = childPerson.LastName; familyTree.Age = childPerson.Age; foreach (var person in relatedPeople.Where(person => !IdsToExclude.Contains(person.Id))) { personsQueue.Enqueue(person); } while (personsQueue.Count != 0) { var personToCheck = personsQueue.Dequeue(); familyTree.Family.Add(await GetRelatedPeople(personToCheck, new FamilyTreeDTO())); } return(familyTree); }
private async Task GetParents(Person child, int initialPersonId) { var query = RepositoryDbContext.Set <Domain.PersonInRelationship>() .Include(i => i.Relationship) .Where(w => w.Person1 == child); var mom = await query.Where(w => w.Relationship.Relation == Relation.Ema).Select(e => e.Person) .FirstOrDefaultAsync(); var dad = await query.Where(w => w.Relationship.Relation == Relation.Isa).Select(e => e.Person) .FirstOrDefaultAsync(); if (!PersonFirstNameMissing(mom)) { RelationsCounter += 1; RelatedPersonsIds[initialPersonId].Add(mom); await GetParents(mom, initialPersonId); } if (!PersonFirstNameMissing(dad)) { RelationsCounter += 1; RelatedPersonsIds[initialPersonId].Add(dad); await GetParents(dad, initialPersonId); } }
/// <summary> /// 读取权限信息 /// </summary> public static void LoadBaseInfomations() { RefreashUserPermissionsCache(); RefreashRolePermissionsCache(); RefreashModules(); RefreashPermissions(); using (var context = new RepositoryDbContext()) { var commandDatas = context.Set <CommandData>(); CommandDataId.CleanerCurrent = commandDatas.First(obj => obj.DataName == ProtocolDataName.CleanerCurrent).Id; CommandDataId.CleanerSwitch = commandDatas.First(obj => obj.DataName == ProtocolDataName.CleanerSwitch).Id; CommandDataId.FanCurrent = commandDatas.First(obj => obj.DataName == ProtocolDataName.FanCurrent).Id; CommandDataId.FanSwitch = commandDatas.First(obj => obj.DataName == ProtocolDataName.FanSwitch).Id; CommandDataId.LampblackInCon = commandDatas.First(obj => obj.DataName == ProtocolDataName.LampblackInCon).Id; CommandDataId.LampblackOutCon = commandDatas.First(obj => obj.DataName == ProtocolDataName.LampblackOutCon).Id; } }
public async Task <PersonWithMostPredecessorsDTO> GetPersonWithMostPredecessors() { var result = new Dictionary <int, Tuple <int, Person> >(); var index = 0; var personsWithParents = await RepositoryDbContext.Set <Domain.PersonInRelationship>() .Include(i => i.Relationship) .Include(i => i.Person1) .Where(w => (w.Relationship.Relation == Relation.Ema || w.Relationship.Relation == Relation.Isa)) .Select(e => e.Person1) .Where(w => w.RelatedFrom.Any(ww => ww.Relationship.Relation == Relation.Poeg || ww.Relationship.Relation == Relation.Tütar)).ToListAsync(); foreach (var person in personsWithParents) { RelatedPersonsIds[person.Id] = new List <Person>(); await GetParents(person, person.Id); result.Add(index, new Tuple <int, Person>(RelationsCounter, person)); index += 1; RelationsCounter = new int(); } return(_personMapper.MapToPredecessorDtoFormat(result, RelatedPersonsIds)); }
/// <summary> /// 刷新权限信息缓存 /// </summary> public static void RefreashPermissions() { using (var context = new RepositoryDbContext()) { PlatformCaches.DeleteCachesByName("Permissions"); var permissions = context.Set <Permission>().ToList(); PlatformCaches.Add("Permissions", permissions, false, "System"); } }
/// <summary> /// 刷新系功能单缓存 /// </summary> public static void RefreashModules() { using (var context = new RepositoryDbContext()) { PlatformCaches.DeleteCachesByType("Modules"); var modules = context.Set <Module>().Where(obj => obj.IsEnabled).ToList(); foreach (var module in modules) { PlatformCaches.Add($"Module[{module.Id}]", module, false, "Modules"); } } }
public async Task <Product> FindProductInfoAsync(int id) { var product = await RepositoryDbContext.Set <Domain.Product>().FindAsync(id); RepositoryDbContext.Entry(product).State = EntityState.Detached; return(ProductMapper.MapFromDomain(await RepositoryDbSet.AsNoTracking().Where(a => a.Id == product.Id) .Include(aa => aa.ProductName).ThenInclude(t => t.Translations) .Include(s => s.Shop) .Include(m => m.Manufacturer) .FirstOrDefaultAsync())); }
/// <summary> /// 刷新角色权限缓存 /// </summary> public static void RefreashRolePermissionsCache() { using (var context = new RepositoryDbContext()) { PlatformCaches.DeleteCachesByType("RolePermissions"); var roles = context.Set <WdRole>().Include("Permissions").Where(obj => obj.IsEnabled).ToList(); foreach (var wdRole in roles) { PlatformCaches.Add($"Role[{wdRole.Id}]-Permissions", wdRole.Permissions.ToList(), false, "RolePermissions"); } } }
/// <summary> /// 刷新用户权限缓存 /// </summary> public static void RefreashUserPermissionsCache() { using (var context = new RepositoryDbContext()) { PlatformCaches.DeleteCachesByType("UserPermissions"); var users = context.Set <WdUser>().Include("Permissions").Where(obj => obj.IsEnabled).ToList(); foreach (var wdUser in users) { PlatformCaches.Add($"User[{wdUser.Id}]-Permissions", wdUser.Permissions.ToList(), false, "UserPermissions"); } } }
public async Task <IEnumerable <PersonDataDTO> > GetDaughtersAndSons() { return(await RepositoryDbContext.Set <Domain.PersonInRelationship>() .Include(i => i.Person) .Where(w => w.Relationship.Relation == Relation.Tütar || w.Relationship.Relation == Relation.Poeg) .Select(e => new PersonDataDTO() { Id = e.Person.Id, FirstName = e.Person.FirstName, LastName = e.Person.LastName, Age = e.Person.Age }).Distinct().ToListAsync()); }
/// <summary> /// 获取系统权限列表 /// </summary> /// <returns></returns> public static List <Permission> GetSysPeremissions() { var cache = PlatformCaches.GetCache("Permissions"); if (cache == null) { using (var context = new RepositoryDbContext()) { var sysPeremissions = context.Set <Permission>().ToList(); PlatformCaches.Add("Permissions", sysPeremissions, false, "System"); return(sysPeremissions); } } var permissions = cache.CacheItem as List <Permission>; return(permissions); }
public override async Task <Order> FindAsync(params object[] id) { var order = await RepositoryDbContext.Set <Domain.Order>().FindAsync(id); RepositoryDbContext.Entry(order).State = EntityState.Detached; return(OrderMapper.MapFromDomain(await RepositoryDbSet.Where(a => a.Id == order.Id) .Include(m => m.Description).ThenInclude(t => t.Translations) .Include(a => a.Shipper).ThenInclude(aa => aa.ShipperName).ThenInclude(t => t.Translations) .Include(a => a.Shipper).ThenInclude(aa => aa.ShipperAddress).ThenInclude(t => t.Translations) .Include(a => a.Shipper).ThenInclude(aa => aa.PhoneNumber).ThenInclude(t => t.Translations) .Include(a => a.Shop).ThenInclude(aa => aa.ShopName).ThenInclude(t => t.Translations) .Include(a => a.Shop).ThenInclude(aa => aa.ShopAddress).ThenInclude(t => t.Translations) .Include(a => a.Shop).ThenInclude(aa => aa.ShopContact).ThenInclude(t => t.Translations) .Include(a => a.Shop).ThenInclude(aa => aa.ShopContact2).ThenInclude(t => t.Translations) .Include(a => a.ProductsInOrder).ThenInclude(a => a.Product).ThenInclude(aa => aa.ProductName).ThenInclude(t => t.Translations) .Include(a => a.ProductsInOrder).ThenInclude(a => a.Product).ThenInclude(aa => aa.Length).ThenInclude(t => t.Translations) .Include(a => a.ProductsInOrder).ThenInclude(a => a.Product).ThenInclude(aa => aa.Weight).ThenInclude(t => t.Translations) .Include(a => a.ProductsInOrder).ThenInclude(a => a.Product).ThenInclude(aa => aa.ManuFacturerItemCode).ThenInclude(t => t.Translations) .Include(a => a.ProductsInOrder).ThenInclude(a => a.Product).ThenInclude(aa => aa.ShopCode).ThenInclude(t => t.Translations) .FirstOrDefaultAsync())); }
public override async Task <Product> FindAsync(params object[] id) { var product = await RepositoryDbContext.Set <Domain.Product>().FindAsync(id); RepositoryDbContext.Entry(product).State = EntityState.Detached; return(ProductMapper.MapFromDomain(await RepositoryDbSet.AsNoTracking().Where(a => a.Id == product.Id) .Include(aa => aa.ProductName).ThenInclude(t => t.Translations) .Include(aa => aa.Length).ThenInclude(t => t.Translations) .Include(aa => aa.Weight).ThenInclude(t => t.Translations) .Include(aa => aa.ManuFacturerItemCode).ThenInclude(t => t.Translations) .Include(aa => aa.ShopCode).ThenInclude(t => t.Translations) .Include(p => p.Inventory).ThenInclude(i => i.Description).ThenInclude(t => t.Translations) .Include(m => m.Manufacturer).ThenInclude(mm => mm.ManuFacturerName).ThenInclude(t => t.Translations) .Include(m => m.Manufacturer).ThenInclude(mm => mm.Aadress).ThenInclude(t => t.Translations) .Include(m => m.Manufacturer).ThenInclude(mm => mm.PhoneNumber).ThenInclude(t => t.Translations) .Include(a => a.Shop).ThenInclude(aa => aa.ShopName).ThenInclude(t => t.Translations) .Include(a => a.Shop).ThenInclude(aa => aa.ShopAddress).ThenInclude(t => t.Translations) .Include(a => a.Shop).ThenInclude(aa => aa.ShopContact).ThenInclude(t => t.Translations) .Include(a => a.Shop).ThenInclude(aa => aa.ShopContact2).ThenInclude(t => t.Translations) .Include(a => a.Comments).ThenInclude(aa => aa.CommentBody).ThenInclude(t => t.Translations) .Include(a => a.Comments).ThenInclude(aa => aa.CommentTitle).ThenInclude(t => t.Translations) .FirstOrDefaultAsync())); }
public GenericRepository() { _db = new RepositoryDbContext(); _table = _db.Set <T>(); }
public IQueryable <T> FindAll(bool trackChanges) => !trackChanges?context.Set <T>().AsNoTracking() : context.Set <T>();
public ComandaRepository(RepositoryDbContext dbContext, IUsuarioRepository usuarioRepository) : base(dbContext) { _dbSetProduto = dbContext.Set <Produto>(); _dbSetComandaPedido = dbContext.Set <ComandaPedido>(); _usuarioRepository = usuarioRepository; }
public Repository(RepositoryDbContext dbContext) { Db = dbContext; DbSet = Db.Set <TEntity>(); }
public ValueTask <T> GetByIdAsync(int id) => _dbContext.Set <T>().FindAsync(id);
public GenericRepository(RepositoryDbContext db) { _db = db; _table = _db.Set <T>(); }
public List <HotelLocations> GetHotelLocations() { var locations = new List <HotelLocations>(); using (var repo = new RepositoryDbContext()) { repo.Database.CommandTimeout = int.MaxValue; var hotels = repo.Set <HotelRestaurant>().ToList(); var checkDate = DateTime.Now.AddMinutes(-2); var commandDataId = repo.Set <CommandData>().First(obj => obj.DataName == ProtocolDataName.CleanerCurrent).Id; var modelId = Guid.Parse("5306DA86-7B7C-40CF-933C-642061C24761"); foreach (var hotel in hotels) { var locat = new HotelLocations { Name = hotel.ProjectName, Id = hotel.Id, DistrictGuid = hotel.DistrictId, Point = new LocationPoint { Latitude = $"{hotel.Latitude}", Longitude = $"{hotel.Longitude}" } }; var devs = repo.Set <Device>().Where(dev => dev.ProjectId == hotel.Id).Select(item => item.Identity).ToList(); var lastProtocol = repo.Set <ProtocolData>() .Where(d => devs.Contains(d.DeviceIdentity)) .OrderByDescending(dat => dat.UpdateTime) .FirstOrDefault(); if (lastProtocol != null && lastProtocol.UpdateTime >= checkDate) { var hotelData = repo.Set <MonitorData>() .FirstOrDefault(d => d.ProjectIdentity == hotel.Identity && d.ProtocolDataId == lastProtocol.Id && d.CommandDataId == commandDataId); if (hotelData == null) { locat.Status = "无数据"; } else { var cleanRate = GetCleanRateByDeviceModel(hotelData.DoubleValue, modelId); locat.Status = cleanRate; } } else { locat.Status = "无数据"; } locations.Add(locat); } } return(locations); }
/// <summary> /// Creates the specified entity. /// </summary> /// <param name="entity">The entity.</param> /// <returns>Generic TEntity</returns> public TEntity Create(TEntity entity) { DbContext.Set <TEntity>().Add(entity); return(entity); }