Exemplo n.º 1
0
        public List <Advice> GetRandomAdvices()
        {
            var context = new SpecialistDataContext();

            return(context.GetTable <Advice>().IsActive()
                   .OrderBy(x => context.GetNewID()).Take(CommonConst.AdviceCount).ToList());
        }
Exemplo n.º 2
0
        public OrgResponse GetOrgRandomResponseForMainPage()
        {
            var context = new SpecialistDataContext();

            return(context.GetTable <OrgResponse>().Where(x => x.ShortDescription != null)
                   .OrderBy(x => context.GetNewID()).FirstOrDefault());
        }
Exemplo n.º 3
0
        public List <Response> GetRandomForWebinar()
        {
            var context = new SpecialistDataContext();

            return(context.GetTable <Response>().IsActive()
                   .Where(x => x.IsWebinar)
                   .OrderBy(x => context.GetNewID()).Take(15).ToList());
        }
Exemplo n.º 4
0
        public Response GetRandomForMainPage(List <string> courseTCs)
        {
            var context  = new SpecialistDataContext();
            var response =
                context.GetTable <Response>().IsActive()
                .Where(x => x.Rating == ResponseRating.ForMain &&
                       courseTCs.Contains(x.Course_TC))
                .OrderBy(x => context.GetNewID()).FirstOrDefault();

            if (response != null)
            {
                return(response);
            }
            return(context.GetTable <Response>().IsActive()
                   .Where(x => x.Rating == ResponseRating.ForMain)
                   .OrderBy(x => context.GetNewID()).FirstOrDefault());
        }
Exemplo n.º 5
0
        public List <Response> GetRandomResponsesByCourse(string CourseTC, int rows)
        {
            var context = new SpecialistDataContext();

            return(context.GetTable <Response>().IsActive()
                   .Where(x => x.Type == RawQuestionnaireType.CourseComment).Where(r => r.Course_TC == CourseTC)
                   .OrderBy(x => context.GetNewID()).Take(rows).ToList());
        }
Exemplo n.º 6
0
 public static HashSet <DateTime> DayOffList()
 {
     return(MethodBase.GetCurrentMethod().CacheDay(() => {
         var start = DateTime.Today.AddYears(-3);
         var end = DateTime.Today.AddYears(3);
         var context = new SpecialistDataContext();
         var workDays = _.List('В', 'П');
         return new HashSet <DateTime>(context.GetTable <Calendar>().Where(x =>
                                                                           x.DateValue >= start && x.DateValue <= end && workDays.Contains(x.WorkDay))
                                       .Select(x => x.DateValue).ToList());
     }));
 }
Exemplo n.º 7
0
//		public List<EntityWithList<IEntityCommonInfo, IEntityCommonInfo>> GetMenuTree(object entity) {
//			var context = new SpecialistDataContext();
//			var allForMenu = GetAllForMenu();
//			var relations = allForMenu.GetValueOrDefault(Tuple.Create(entity.GetType(),
//				(int)LinqToSqlUtils.GetPK(entity))) ?? new List<SiteObjectRelation>();
//			if(!relations.Any())
//				return new List<EntityWithList<IEntityCommonInfo, IEntityCommonInfo>>();
//			var tableNames = types.Select(x => SiteObject.TypeTableNames.GetValueOrDefault(x)) ;
//			var tree = relations.Where(x => tableNames.Contains(x.RelationObjectType)).Select(x => EntityWithList.New(x,
//				allForMenu.GetValueOrDefault(Tuple.Create(SiteObject.TableNameTypes[x.RelationObjectType], (int)x.RelationObject_ID))));
//			var allrelations = tree.SelectMany(x => x.List.Concat(_.List(x.Entity)))
//				.ToList();
//			var entityByType = new Dictionary<Type, Dictionary<object, IEntityCommonInfo>>();
//			entityByType.Add(typeof (Section),
//				GetEntities<Section>(context, allrelations, x => x.Section_ID));
//			entityByType.Add(typeof (Vendor),
//				GetEntities<Vendor>(context, allrelations, x => x.Vendor_ID));
//			entityByType.Add(typeof (Product),
//				GetEntities<Product>(context, allrelations, x => x.Product_ID));
//			entityByType.Add(typeof (SiteTerm),
//				GetEntities<SiteTerm>(context, allrelations, x => x.SiteTerm_ID));
//			entityByType.Add(typeof (Profession),
//				GetEntities<Profession>(context, allrelations, x => x.Profession_ID));
//			entityByType.Add(typeof (Course),
//				GetEntities<Course>(context, allrelations, x => x.Course_TC));
//
//
//			Func<SiteObjectRelation, IEntityCommonInfo> getEntity = x =>
//				entityByType[SiteObject.TableNameTypes[x.RelationObjectType]]
//				[x.RelationObject_ID];
//			var entityWithTags = tree.Select(x => EntityWithList.New(getEntity(x.Entity),
//				x.List.Select(getEntity)/*.OrderBy(e => e.WebSortOrder)*/)).ToList();
//			return entityWithTags;
//		}



        Dictionary <object, IEntityCommonInfo> GetEntities <T>(SpecialistDataContext context,
                                                               List <SiteObjectRelation> allrelations,
                                                               Func <T, object> idSelector) where T : class, IEntityCommonInfo
        {
            var ids = GetEntityIds(typeof(T), allrelations);

            if (!ids.Any())
            {
                return(new Dictionary <object, IEntityCommonInfo>());
            }
            return(Repository2 <T> .GetByPKList(context.GetTable <T>(), ids)
                   .ToDictionary(idSelector, x => (IEntityCommonInfo)x));
        }
Exemplo n.º 8
0
        public void Update()
        {
            var context = new PassportDataContext();
            var photos  = context.UserContacts.Where(x => x.ContactTypeID == ContactTypes.VKontakte &&
                                                     x.User.Student_ID > 0)
                          .Select(x => new { x.User.Student_ID, x.Contact })
                          .ToDictionary(x => x.Student_ID.Value, x => GetVkUrl(x.Contact));
            var students    = photos.Keys.ToList();
            var specContext = new SpecialistDataContext();
            var responses   = specContext.GetTable <Response>().Select(x => new { x.RawQuestionnaire.Questionnaire.Student_ID, Response = x })
                              .Where(x => students.Contains(x.Student_ID)).ToList();

            foreach (var response in responses)
            {
                var vkUrl = photos[response.Student_ID];
                if (vkUrl != null)
                {
                    response.Response.PhotoUrl  = vkUrl.Item1;
                    response.Response.SocialUrl = vkUrl.Item2;
                }
            }
            specContext.SubmitChanges();
        }
Exemplo n.º 9
0
        public IQueryable <T> GetDoubleRelation <T>(Type objectType, object id) where T : class
        {
            var type = LinqToSqlUtils.GetTableName(objectType);
            var requiredObjectType = LinqToSqlUtils.GetTableName(typeof(T));
            var requiredRelations  = GetRequiredRelationsByDoubleLink(
                id, type, requiredObjectType);
            var requiredIds = requiredRelations.Select(sor => sor.Object.ID);

            return(context.GetTable <T>().Where(LinqToSqlUtils.WhereContains <T>(requiredIds)));
        }