Exemplo n.º 1
0
        public List <Service> GetAllInclude(params Expression <Func <Service, object> >[] includes)
        {
            using (var scope = _dbContextScopeFactory.CreateReadOnly())
            {
                var dbContext = scope.DbContexts.Get <ApplicationDbContext>();

                var query = dbContext.Set <Service>().AsQueryable();

                if (includes != null)
                {
                    query = includes.Aggregate(query, (curr, incl) => curr.Include(incl));
                }

                return(query.ToList());
            }
        }
Exemplo n.º 2
0
        public Technology GetById(int id)
        {
            using (var scope = _dbContextScopeFactory.CreateReadOnly())
            {
                var dbContext = scope.DbContexts.Get <ApplicationDbContext>();

                var query = dbContext.Set <Technology>().AsQueryable();

                if (Includes != null)
                {
                    query = Includes.Aggregate(query, (curr, incl) => curr.Include(incl));
                }

                return(query.SingleOrDefault(c => c.ID == id));
            }
        }
Exemplo n.º 3
0
 public IReadOnlyList <GroupDto> GetGroups(int pageIndex, int pageSize, string filterKeyword)
 {
     // lock for updating caching
     //lock (_allUserDtos)
     using (_dbContextScopeFactory.CreateReadOnly())
     {
         var allGroupModels = _groupRepository.GetAll();
         if (!string.IsNullOrEmpty(filterKeyword))
         {
             allGroupModels = allGroupModels.Where(e => e.Name.Contains(filterKeyword));
         }
         allGroupModels = allGroupModels.OrderBy(e => e.Name).Skip(pageSize * (pageIndex - 1)).Take(pageSize);
         _allGrouprDtos = _mapper.Map <List <GroupDto> >(allGroupModels.ToList());
     }
     return(_allGrouprDtos.AsReadOnly());
 }
Exemplo n.º 4
0
        public IEnumerable <StudentForGridView> GetAll()
        {
            var result = new List <StudentForGridView>();

            try
            {
                using (var ctx = _dbContextScopeFactory.CreateReadOnly())
                {
                    result = _studentRepository.GetAll(x => x.StudentPerCourses, x => x.CreatedUser)
                             .Select(x => new StudentForGridView
                    {
                        Id              = x.Id,
                        Name            = x.Name,
                        Email           = x.Email,
                        Birthday        = x.Birthday,
                        CurrentStatus   = x.CurrentStatus == Enums.Status.Enable ? "Active" : "Disabled",
                        NumberOfCourses = x.StudentPerCourses.Count(),
                        CreatedBy       = x.CreatedUser.UserName
                    }).ToList();
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
            }

            return(result);
        }
 public async Task <IReadOnlyList <DepartmentDto> > GetDepartmentsAsync(bool clearCache = false)
 {
     if (_departments == null || clearCache)
     {
         using (_dbContextScopeFactory.CreateReadOnly())
         {
             _departments = await _deparmentRepository
                            .GetAll()
                            .AsNoTracking()
                            .OrderBy(d => d.OrderNumber)
                            .ProjectTo <DepartmentDto>(_mapper.ConfigurationProvider)
                            .ToListAsync();
         }
     }
     return(_departments);
 }
Exemplo n.º 6
0
            public Task <Result> Handle(Query message, CancellationToken cancellationToken)
            {
                using (var scope = _scopeFactory.CreateReadOnly())
                {
                    var result = new Result();

                    var context = scope.DbContexts.Get <MainContext>();

                    var item =
                        context.Set <Movie>()
                        .Where(w => w.StatusId == true && w.Id == message.Id).FirstOrDefault();


                    if (item != null)
                    {
                        result.IsSuccessful = true;
                        result.Data         = Mapper.Map <NestedModel.MovieModel>(item);
                    }
                    else
                    {
                        result.Messages.Add("Item not found");
                    }

                    return(Task.FromResult(result));
                }
            }
Exemplo n.º 7
0
            public Task <Result> Handle(Query message, CancellationToken cancellationToken)
            {
                using (var scope = _scopeFactory.CreateReadOnly())
                {
                    var context = scope.DbContexts.Get <MainContext>();

                    var query = context.Set <Chapter>()
                                .Where(w => w.StatusId == true && w.StoryId == message.StoryId);

                    if (!string.IsNullOrEmpty(message.Keyword))
                    {
                        query = query.Where(f => f.Title.Contains(message.Keyword) || f.Content.Contains(message.Keyword));
                    }

                    var count = query.Count();
                    var items = query.Select(s => new NestedModel.QueryModel()
                    {
                        Chapter = s,
                        Story   = s.Story,
                        Author  = s.Story.Author
                    }).OrderByDescending(o => o.Chapter.NumberChapter.Value).Skip(message.Skip).Take(message.Take).ProjectTo <NestedModel.ChapterModel>().ToList();

                    var result = new Result()
                    {
                        Count        = count,
                        Data         = items,
                        IsSuccessful = true
                    };

                    return(Task.FromResult(result));
                }
            }
Exemplo n.º 8
0
 public async Task <IEnumerable <ScanResult> > ScanForNearbyShips(Reference <Ship> ship)
 {
     using (dbContextScopeFactory.CreateReadOnly())
     {
         return(await queryShipLocations.ScanForNearbyShips(ship));
     }
 }
Exemplo n.º 9
0
            public Task <Result> Handle(Query message, CancellationToken cancellationToken)
            {
                using (var scope = _scopeFactory.CreateReadOnly())
                {
                    var result = new Result();

                    var context = scope.DbContexts.Get <MainContext>();

                    var item = (from author in context.Set <Author>()
                                where author.Id == message.Id
                                select new NestedModel.AuthorQueryModel()
                    {
                        Id = author.Id,
                        Name = author.Name,
                        Link = author.Link,
                        Stories = author.Stories
                    }).ProjectTo <NestedModel.AuthorModel>().FirstOrDefault();


                    if (item != null)
                    {
                        result.IsSuccessful = true;
                        result.Data         = item;
                    }
                    else
                    {
                        result.Messages.Add("Author not found");
                    }

                    return(Task.FromResult(result));
                }
            }
Exemplo n.º 10
0
 internal List <Order> GetAll(List <string> include = null)
 {
     using (var contextScope = _dbContextScopeFactory.CreateReadOnly())
     {
         return(OrderRepository.GetAll(include).ToList());
     }
 }
Exemplo n.º 11
0
        public OrderTotal CalculateTotal(Guid workshopId, ICollection <AnchorQuantity> seatItems)
        {
            using (var scope = factory.CreateReadOnly())
            {
                var seatTypes = workshopDao.GetPublishedAnchorTypes(workshopId);
                var lineItems = new List <OrderLine>();
                foreach (var item in seatItems)
                {
                    var seatType = seatTypes.FirstOrDefault(x => x.ID == item.AnchorType);
                    if (seatType == null)
                    {
                        throw new InvalidDataException(string.Format(CultureInfo.InvariantCulture, "Invalid anchor type ID '{0}' for workshop with ID '{1}'", item.AnchorType, workshopId));
                    }

                    lineItems.Add(new SeatOrderLine {
                        SeatType = item.AnchorType, Quantity = item.Quantity, UnitPrice = seatType.Price, LineTotal = Math.Round(seatType.Price * item.Quantity, 2)
                    });
                }

                return(new OrderTotal
                {
                    Total = lineItems.Sum(x => x.LineTotal),
                    Lines = lineItems
                });
            }
        }
Exemplo n.º 12
0
            public Task <Result> Handle(Query message, CancellationToken cancellationToken)
            {
                using (var scope = _scopeFactory.CreateReadOnly())
                {
                    var context = scope.DbContexts.Get <MainContext>();

                    var query =
                        context.Set <Blood>()
                        .Where(w => w.StatusId == true);

                    if (!string.IsNullOrEmpty(message.Name))
                    {
                        query = query.Where(f => f.Name.Contains(message.Name));
                    }

                    var count = query.Count();
                    var items = query.OrderBy(s => s.Name).Skip(message.Skip).Take(message.Take).ProjectTo <NestedModel.BloodModel>().ToList();

                    var result = new Result()
                    {
                        Count             = count,
                        SearchResultItems = items
                    };

                    return(Task.FromResult(result));
                }
            }
Exemplo n.º 13
0
        public async Task <UserSignatureDto> GetSignatureById(Guid signatureId)
        {
            using (_dbContextScopeFactory.CreateReadOnly())
            {
                var model = await _signatureRepository.GetSignatureById(signatureId);

                return(_mapper.Map <UserSignatureDto>(model));
            }
        }
Exemplo n.º 14
0
        public AnexGRIDResponde GetAll(AnexGRID grid)
        {
            grid.Inicializar();

            try
            {
                using (var ctx = _dbContextScopeFactory.CreateReadOnly())
                {
                    var user        = ctx.GetEntity <ApplicationUser>();
                    var roles       = ctx.GetEntity <ApplicationRole>();
                    var userRoles   = ctx.GetEntity <ApplicationUserRole>();
                    var courses     = ctx.GetEntity <Course>();
                    var userCourses = ctx.GetEntity <UsersPerCourse>();

                    var queryRoles = (
                        from r in roles
                        from ur in userRoles.Where(x => x.RoleId == r.Id)
                        select new {
                        UserId = ur.UserId,
                        Role = r.Name
                    }
                        ).AsQueryable();

                    var query = (
                        from u in user
                        select new UserForGridView
                    {
                        Id = u.Id,
                        FullName = u.Name + " " + u.LastName,
                        Email = u.Email,
                        CoursesCreated = courses.Where(x => x.AuthorId == u.Id).Count(),
                        CoursesTaken = userCourses.Where(x => x.UserId == u.Id).Count(),
                        Roles = queryRoles.Where(x => x.UserId == u.Id).Select(x => x.Role).ToList()
                    }
                        ).AsQueryable();

                    // Order by
                    if (grid.columna == "FullName")
                    {
                        query = grid.columna_orden == "DESC" ? query.OrderByDescending(x => x.FullName)
                                                             : query.OrderBy(x => x.FullName);
                    }

                    var data = query.Skip(grid.pagina)
                               .Take(grid.limite)
                               .ToList();

                    var total = query.Count();

                    grid.SetData(data, total);
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
            }

            return(grid.responde());
        }
        public Client ConnectClient(Client client)
        {
            using (_dbContextScopeFactory.CreateReadOnly())
            {
                // get clients by email, we dont have Ids here
                var foundClientObject = _clientRepository.GetClient(client.Email);

                if (foundClientObject != null && foundClientObject.DoEncyptedPassowrdsMacth(client.Password) && foundClientObject.IsBlocked)
                {
                    return(foundClientObject);
                }
                else
                {
                    return(null);
                }
            }
        }
 /// <summary>
 /// 获取所有的订阅人员
 /// </summary>
 /// <returns></returns>
 public IList <string> GetAll()
 {
     using (var scope = _dbContextScopeFactory.CreateReadOnly())
     {
         var db = scope.DbContexts.Get <JuCheapContext>();
         return(db.EmailSubscribes.Select(x => x.Email).ToList());
     }
 }
Exemplo n.º 17
0
 public async Task <List <TaskItemProcessHistory> > GetProcessHistoryByTaskItem(Guid taskItemId)
 {
     using (var scope = _dbContextScopeFactory.CreateReadOnly())
     {
         var asdfas = _taskItemProcessHistoryRepository.GetAll().ToList();
         return(_taskItemProcessHistoryRepository.GetAll().Where(tfd => tfd.TaskItemAssignId == null && tfd.TaskItemId.HasValue && tfd.TaskItemId == taskItemId).OrderBy(tfd => tfd.CreatedDate).ToList());
     }
 }
Exemplo n.º 18
0
        public IEnumerable <InstructorCourseForGridView> GetAll(string userId)
        {
            var result = new List <InstructorCourseForGridView>();

            try {
                using (var ctx = _dbContextScopeFactory.CreateReadOnly()) {
                    var courses         = ctx.GetEntity <Course>();
                    var usersPerCourses = ctx.GetEntity <UsersPerCourses>();
                    var incomes         = ctx.GetEntity <Incomes>();

                    var queryIncome = incomes.Where(x =>
                                                    x.EntityType == Enums.EntityType.Courses &&
                                                    x.IncomeType == Enums.IncomeType.TeacherTotal
                                                    );

                    var currentYear  = DateTime.Now.Year;
                    var currentMonth = DateTime.Now.Month;

                    result = (
                        from c in courses.Where(x => x.AuthorId == userId)
                        select new InstructorCourseForGridView
                    {
                        Id = c.Id,
                        Name = c.Name,
                        Description = c.Description,
                        Image = c.Image2,
                        Students = usersPerCourses.Count(x => x.CourseId == c.Id),
                        Total = queryIncome.Where(
                            x => x.EntityID == c.Id
                            ).Select(x => x.Total).DefaultIfEmpty().Sum(),

                        TotalPerMonth = queryIncome.Where(
                            x => x.EntityID == c.Id &&
                            x.CreatedAt.Value.Year == currentYear &&
                            x.CreatedAt.Value.Month == currentMonth
                            ).Select(x => x.Total).DefaultIfEmpty().Sum(),
                    }
                        ).ToList();
                }
            } catch (Exception e) {
                logger.Error(e.Message);
            }

            return(result);
        }
Exemplo n.º 19
0
        /// <summary>
        /// 分页搜索
        /// </summary>
        /// <param name="filters">查询过滤参数</param>
        /// <returns></returns>
        public async Task <PagedResult <MenuDto> > Search(MenuFilters filters)
        {
            if (filters == null)
            {
                return(new PagedResult <MenuDto>());
            }

            using (var scope = _dbContextScopeFactory.CreateReadOnly())
            {
                var db    = scope.DbContexts.Get <JuCheapContext>();
                var query = db.Menus
                            .WhereIf(filters.keywords.IsNotBlank(), x => x.Name.Contains(filters.keywords))
                            .WhereIf(filters.ExcludeType.HasValue, x => x.Type != (byte)filters.ExcludeType.Value);

                return(await query.OrderByCustom(filters.sidx, filters.sord)
                       .Select(item => new MenuDto
                {
                    Id = item.Id,
                    ParentId = item.ParentId,
                    Name = item.Name,
                    Url = item.Url,
                    Order = item.Order,
                    Type = (MenuType)item.Type,
                    Icon = item.Icon,
                    CreateDateTime = item.CreateDateTime
                }).PagingAsync(filters.page, filters.rows));
            }
        }
Exemplo n.º 20
0
 public IEnumerable <SysMenu> GetMemberMenuByMemberID(int memberID)
 {
     using (var dbScope = _dbScopeFactory.CreateReadOnly())
     {
         var db = dbScope.DbContexts.Get <WebDbContext>();
         if (!SysConfig.Current.SC_SYS_OPENPOWER) //是否开启权限
         {
             return(db.SysMenus.Where(p => p.IsEnabled == false).ToList());
         }
         else
         {
             var query = from t in db.SysAccountRoles
                         join pp in db.SysRoles on t.RoleId equals pp.Id into tempP
                         from p in tempP.DefaultIfEmpty()
                         join aa in db.SysRoleMenus on p.Id equals aa.RoleId into tempA
                         from a in tempA.DefaultIfEmpty()
                         join bb in db.SysMenus on a.MenuId equals bb.Id into tempB
                         from b in tempB.DefaultIfEmpty()
                         where !b.IsEnabled && t.UserId == CurrentUser.User.UserId
                         orderby b.Sort ascending
                         select b;
             return(query.Distinct().ToList());
         }
     }
 }
        public List <Blogpost> GetAllByService(int serviceId)
        {
            using (var scope = _dbContextScopeFactory.CreateReadOnly())
            {
                var dbContext = scope.DbContexts.Get <ApplicationDbContext>();

                var query = dbContext.Set <Blogpost>().AsQueryable();

                if (Includes != null)
                {
                    query = Includes.Aggregate(query, (curr, incl) => curr.Include(incl));
                }

                return(query
                       .Where(b => b.ServiceId == serviceId)
                       .ToList());
            }
        }
Exemplo n.º 22
0
        private void GetCurrentChapter(StoryModel story, List <ChapterModel> list)
        {
            var linkNextChapter = string.Empty;

            using (var scope = _scopeFactory.CreateReadOnly())
            {
                var context = scope.DbContexts.Get <MainContext>();

                var currentChapter = context.Set <Chapter>().Where(f => f.StoryId == story.Id).OrderByDescending(o => o.NumberChapter).FirstOrDefault();

                if (currentChapter != null)
                {
                    HtmlDocument document = htmlWeb.Load(currentChapter.Link);

                    var chapterQuery = document.DocumentNode.QuerySelectorAll("main.truyencv-main").FirstOrDefault();

                    if (chapterQuery == null)
                    {
                        Task.Delay(30000);

                        chapterQuery = document.DocumentNode.QuerySelectorAll("main.truyencv-main").FirstOrDefault();

                        if (chapterQuery != null)
                        {
                            var linkNextQuery = chapterQuery.QuerySelector("div.truyencv-read-navigation a[title='Chương sau']");

                            if (linkNextQuery != null)
                            {
                                linkNextChapter = linkNextQuery.Attributes["href"].Value;
                            }
                        }
                        else
                        {
                            logger.Error("Cannot get chapter - link error");
                        }
                    }
                    else
                    {
                        var linkNextQuery = chapterQuery.QuerySelector("div.truyencv-read-navigation a[title='Chương sau']");

                        if (linkNextQuery != null)
                        {
                            linkNextChapter = linkNextQuery.Attributes["href"].Value;
                        }
                    }

                    if (!string.IsNullOrEmpty(linkNextChapter))
                    {
                        ProcessChapters(list, linkNextChapter);
                    }
                    else
                    {
                        logger.Info("This chapter is latest");
                    }
                }
            }
        }
Exemplo n.º 23
0
        public Course Get(int id)
        {
            var result = new Course();

            try
            {
                using (var ctx = _dbContextScopeFactory.CreateReadOnly())
                {
                    result = _courseRepo.Single(x => x.Id == id);
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
            }

            return(result);
        }
        public IEnumerable <Category> GetAll()
        {
            var result = new List <Category>();

            try
            {
                using (var ctx = _dbContextScopeFactory.CreateReadOnly())
                {
                    result = _categoryRepo.GetAll().OrderBy(x => x.Name).ToList();
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message);
            }

            return(result);
        }
Exemplo n.º 25
0
        public DictionaryDto GetDictionaryById(int id)
        {
            using (var dbScope = _dbScopeFactory.CreateReadOnly())
            {
                var db   = dbScope.DbContexts.Get <FireProjDbContext>();
                var data = db.Dictionary.Where(r => r.Id == id).Select(r => new DictionaryDto()
                {
                    Id          = r.Id,
                    Name        = r.Name,
                    Value       = r.Value,
                    Description = r.Description,
                    Status      = r.Status,
                    ParentId    = r.ParentId,
                }).FirstOrDefault();

                return(data);
            }
        }
        public async Task <TDto> Get(int id)
        {
            _logger.Inform(string.Format(DEF_GET_OBJECT_LOG_TEMPLATE, typeof(TDto).Name, id));

            using (var dbScope = _dbContextScopeFactory.CreateReadOnly())
            {
                return(Mapper.Map <TDto>(await dbScope.GetRepository <User>().GetByIdAsync(id)));
            }
        }
Exemplo n.º 27
0
        public IEnumerable <Course> GetAll()
        {
            var courses = new List <Course>();

            using (var ctx = _dbContextScopeFactory.CreateReadOnly()) {
                courses = _coursePero.GetAll(x => x.StudentPerCourses).ToList();
            }

            return(courses);
        }
Exemplo n.º 28
0
        public Customer LoginCustomer(Customer customerToLogin)
        {
            using (_dbContextScopeFactory.CreateReadOnly())
            {
                var foundCustomer = _customerRepository.FindByEmail(customerToLogin.Email);


                if (foundCustomer != null &&
                    foundCustomer.IsCorrectPassword(customerToLogin.Password) &&
                    foundCustomer.IsActive)
                {
                    return(foundCustomer);
                }
                else    //TODO: WrongEmailOrPasswordException
                {
                    return(null);
                }
            }
        }
Exemplo n.º 29
0
        public IEnumerable <AutobrandViewModel> Get(CarClassification autoType)
        {
            using (var dbContext = dbContextScope.CreateReadOnly())
            {
                var autoBrandsData = autobrandRepository.GetAutoBrands(autoType);
                var output         = Mapper.Map <IEnumerable <AutobrandViewModel> >(autoBrandsData);

                return(output);
            }
        }
Exemplo n.º 30
0
        public ICollection <CoffeeMenu> GetAll()
        {
            ICollection <CoffeeMenu> drinkCostList;

            using (var context = _contextScopeFactory.CreateReadOnly())
            {
                drinkCostList = _contextLocator.Get <DataContext>().CoffeeMenu.ToList();
            }

            return(drinkCostList);
        }