示例#1
0
        public Home()
        {
            InitializeComponent();

            db.kullanicilar.Where(s => s.ID == bilgilerim.ID).FirstOrDefault().durum = true;
            db.SaveChanges();     // Çevrimiçi ol!

            IOrderedQueryable <mesajlar> mesajlarIQ = db.mesajlar.Where(s => s.aliciID == bilgilerim.ID).OrderByDescending(s => s.ID);

            sonMesajID = mesajlarIQ.FirstOrDefault() != null?mesajlarIQ.FirstOrDefault().ID : 0;
        }
示例#2
0
        /// <summary>
        /// Get the first or default item using a predicate, order items, load related object using navigationProperties
        /// </summary>
        /// <param name="predicate"></param>
        /// <param name="orderby"></param>
        /// <param name="navigationProperties"></param>
        /// <returns></returns>
        public T FirstOrDefault(Expression <Func <T, bool> > predicate, IGenericDataOrder <T> orderby, params Expression <Func <T, object> >[] navigationProperties)
        {
            T ret = null;

            using (var context = (DbContext)Activator.CreateInstance(ContextType, ContextParameters))
            {
                IQueryable <T> dbQuery = context.Set <T>();
                //apply eager loading
                foreach (Expression <Func <T, object> > navigationProperty in navigationProperties)
                {
                    dbQuery = dbQuery.Include <T, object>(navigationProperty);
                }

                //set the predicate
                if (predicate != null)
                {
                    dbQuery = dbQuery.AsNoTracking().Where(predicate);
                }

                if (orderby != null)
                {
                    //apply order
                    IOrderedQueryable <T> dbQueryOrdered = orderby.ApplyOrders(dbQuery);

                    ret = dbQueryOrdered.FirstOrDefault();
                }
                else
                {
                    ret = dbQuery.FirstOrDefault();
                }
            }
            return(ret);
        }
        public virtual string LastRegister()
        {
            var keyNames   = GetprimarykeyColumns();
            var enumerable = keyNames as string[] ?? keyNames.ToArray();
            var query      = enumerable.All(f => f != "empresa") ? _db.Set <TPersistencia>() : _db.Set <TPersistencia>().Where(CreateWhereClause <TPersistencia>("empresa", Empresa));

            var flagFirst = true;
            IOrderedQueryable <TPersistencia> orderedQuery = null;

            foreach (var item in enumerable)
            {
                orderedQuery = flagFirst ? query.OrderByDescending(item) : orderedQuery.ThenByDescending(item);
                flagFirst    = false;
            }
            var obj = orderedQuery.FirstOrDefault();

            if (obj == null)
            {
                return(string.Empty);
            }

            var modelObj = _converterModel.GetModelView(obj);

            return(modelObj.GetPrimaryKey());
        }
示例#4
0
        public override string LastRegister()
        {
            var keyNames   = GetprimarykeyColumns();
            var enumerable = keyNames as string[] ?? keyNames.ToArray();
            var query      = _db.Set <Usuarios>();

            var flagFirst = true;
            IOrderedQueryable <Usuarios> orderedQuery = null;

            foreach (var item in enumerable)
            {
                orderedQuery = flagFirst ? query.OrderByDescending(item) : orderedQuery.ThenByDescending(item);
                flagFirst    = false;
            }
            var obj = orderedQuery.FirstOrDefault(f => f.id != Guid.Empty);

            if (obj == null)
            {
                return(string.Empty);
            }

            var modelObj = _converterModel.GetModelView(obj);

            return(modelObj.GetPrimaryKey());
        }
示例#5
0
        public ViewResult Details(int id)
        {
            Student student = db.Students.Find(id);
            //ViewBag.testCompletedCoreCourses = (from o in student where o.enrollment)

            int totalCoresPassed = db.Enrollments.Count(s => s.StudentID == id &&
                                                        s.Grade == "Credit Received" &&
                                                        s.Course.Elective == false);

            int totalElectivesPassed = db.Enrollments.Count(s => s.StudentID == id &&
                                                            s.Grade == "Credit Received" &&
                                                            s.Course.Elective);

            int totalCoresNeeded     = db.CommissioningRequirements.Find(1).CoreCoursesRequired;
            int totalElectivesNeeded = db.CommissioningRequirements.Find(1).ElectiveCoursesRequired;

            ViewBag.coresPassed     = totalCoresPassed;
            ViewBag.electivesPassed = totalElectivesPassed;
            ViewBag.coresNeeded     = totalCoresNeeded;
            ViewBag.electivesNeeded = totalElectivesNeeded;

            IOrderedQueryable <ApplicationCommissioning> usersCommissionings =
                db.ApplicationCommissionings.Where(o => o.Student.UserName == student.UserName && o.Approved).
                OrderByDescending(m => m.DateApproved);
            ApplicationCommissioning usersMostRecentCommissioning = usersCommissionings.FirstOrDefault();

            if (usersMostRecentCommissioning != null)
            {
                ViewBag.mostRecentCommissioningCertificateID = usersMostRecentCommissioning.Id;
            }

            return(View(student));
        }
示例#6
0
        public override string LastRegister()
        {
            var keyNames   = GetprimarykeyColumns();
            var enumerable = keyNames as string[] ?? keyNames.ToArray();
            var modoint    = (int)Modo;
            var query      = _db.Albaranes.Where(f => f.empresa == Empresa && f.modo == modoint);

            var flagFirst = true;
            IOrderedQueryable <Albaranes> orderedQuery = null;

            foreach (var item in enumerable)
            {
                orderedQuery = flagFirst ? query.OrderByDescending(item) : orderedQuery.ThenByDescending(item);
                flagFirst    = false;
            }
            var obj = orderedQuery.FirstOrDefault();

            if (obj == null)
            {
                return(string.Empty);
            }

            var modelObj = _converterModel.GetModelView(obj);

            return(modelObj.GetPrimaryKey());
        }
        public IActionResult Rate()
        {
            Guid currentUserGuid = Guid.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "guid").Value);
            IOrderedQueryable <Commission> commissionQuery = from commission in sellerContext.Commission
                                                             where commission.UserGuid == currentUserGuid
                                                             orderby commission.Mtime descending
                                                             select commission;
            double targetRate = commissionQuery.FirstOrDefault()?.Rate ?? 0.5;

            return(Ok(targetRate));
        }
示例#8
0
        /// <summary>
        /// Получает группу по-имени(в том числе и невидимую)
        /// </summary>
        /// <param name="context">Контекст</param>
        /// <param name="name">имя группы</param>
        /// <param name="groupType">тип группы</param>
        /// <returns>найденная группа или null</returns>
        private Group GetGroupByName(StudyLanguageContext context, string name, GroupType groupType)
        {
            var parsedType = (int)groupType;
            IOrderedQueryable <Group> wordsWithTranslationsQuery = (from g in context.Group
                                                                    where
                                                                    g.Name == name && g.Type == parsedType &&
                                                                    g.LanguageId == _languageId
                                                                    orderby g.Rating descending, g.Name
                                                                    select g);

            return(wordsWithTranslationsQuery.FirstOrDefault());
        }
示例#9
0
        private Issue SearchIssueByKey(int issueKey)
        {
            IOrderedQueryable <Issue> issues = from i in _jira.Issues.Queryable
                                               where i.Key == _project.Key + "-" + issueKey
                                               orderby i.Created
                                               select i;

            try {
                return(issues.FirstOrDefault());
            } catch (Exception) {
                return(null);
            }
        }
示例#10
0
 public static T FirstOrDefaultNoLock <T>(this IOrderedQueryable <T> query, Expression <Func <T, bool> > predicate)
 {
     using (
         var scope = new TransactionScope(TransactionScopeOption.Required,
                                          new TransactionOptions()
     {
         IsolationLevel = IsolationLevel.ReadUncommitted
     },
                                          TransactionScopeAsyncFlowOption.Enabled))
     {
         var toReturn = query.FirstOrDefault(predicate);
         scope.Complete();
         return(toReturn);
     }
 }
示例#11
0
        /// <summary>
        /// Gets a search term record by keyword
        /// </summary>
        /// <param name="keyword">Search term keyword</param>
        /// <param name="storeId">Store identifier</param>
        /// <returns>Search term</returns>
        public virtual SearchTerm GetSearchTermByKeyword(string keyword, int storeId)
        {
            if (string.IsNullOrEmpty(keyword))
            {
                return(null);
            }

            IOrderedQueryable <SearchTerm> query = from st in _searchTermRepository.Table
                                                   where st.Keyword == keyword
                                                   orderby st.Id
                                                   select st;
            SearchTerm searchTerm = query.FirstOrDefault();

            return(searchTerm);
        }
示例#12
0
 public static T FirstOrDefaultNoLock <T>(this IOrderedQueryable <T> query)
 {
     using (
         var scope = new TransactionScope(TransactionScopeOption.Required,
                                          new TransactionOptions()
     {
         IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
     },
                                          TransactionScopeAsyncFlowOption.Enabled))
     {
         var toReturn = query.FirstOrDefault();
         scope.Complete();
         return(toReturn);
     }
 }
示例#13
0
        public ActionResult Profile()
        {
            ProfileViewModel model = PreloadProfileViewModelWithCurrentUsersProfileData();
            MembershipUser   u     = Membership.GetUser(User.Identity.Name);

            if (u != null)
            {
                ViewBag.Email = u.Email;
            }
            IOrderedQueryable <ApplicationCommissioning> usersCommissionings =
                db.ApplicationCommissionings.Where(o => o.Student.UserName == User.Identity.Name && o.Approved).
                OrderByDescending(m => m.DateApproved);
            ApplicationCommissioning usersMostRecentCommissioning = usersCommissionings.FirstOrDefault();

            if (usersMostRecentCommissioning != null)
            {
                ViewBag.mostRecentCommissioningCertificateID = usersMostRecentCommissioning.Id;
            }
            return(View(model));
        }
示例#14
0
        public List <string> GetLastRetrievedKeys()
        {
            List <string> list = new List <string>();

            try
            {
                using (SDACloudEntities sDACloudEntities = new SDACloudEntities())
                {
                    using (sDACloudEntities)
                    {
                        IOrderedQueryable <EtilizeKey> source = from x in sDACloudEntities.EtilizeKeys
                                                                orderby x.LastRetrievedDT
                                                                select x;
                        EtilizeKey etilizeKey = source.FirstOrDefault <EtilizeKey>();
                        etilizeKey.LastRetrievedDT = DateTime.UtcNow;
                        sDACloudEntities.SaveChanges();
                        if (etilizeKey != null)
                        {
                            list.Add(etilizeKey.EtilizeKeyID.ToString());
                            list.Add(etilizeKey.EtilizeSiteID.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string item = string.Concat(new object[]
                {
                    "Error: ",
                    ex.Message,
                    " ",
                    ex.InnerException
                });
                list.Add(item);
            }
            return(list);
        }
        public IActionResult Calculator(string type = "Basic")
        {
            //查询当前用户的UserGuid
            Guid currentUserGuid = Guid.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "guid").Value);

            IQueryable <QrcodeSellerList> currentIds = from seller in sellerContext.QrcodeSellerList
                                                       where seller.UserGuid == currentUserGuid
                                                       where type == "Any" || seller.Type == type
                                                       where seller.IsEnable == true
                                                       select seller;

            IQueryable <SellerUserMapping> relatedCostumers = from id in currentIds
                                                              from sum in sellerContext.SellerUserMapping
                                                              where sum.SellerId == id.SellerId
                                                              select sum;

            IEnumerable <LitemallOrder> relatedOrders = from sum in relatedCostumers.ToArray()
                                                        from order in litemallContext.LitemallOrder
                                                        where order.UserId == sum.CostumerId
                                                        where order.ConfirmTime != null
                                                        select order;

            IOrderedQueryable <Commission> commissionQuery = from commission in sellerContext.Commission
                                                             where commission.UserGuid == currentUserGuid
                                                             orderby commission.Mtime descending
                                                             select commission;
            decimal price = 0m;

            foreach (LitemallOrder item in relatedOrders)
            {
                double targetRate = commissionQuery.FirstOrDefault(x => x.Mtime <= item.ConfirmTime)?.Rate ?? 0.5;

                price += item.ActualPrice * (decimal)targetRate;
            }
            return(Ok(Math.Round(price, 2)));
        }
示例#16
0
文件: Service.cs 项目: sekeys/Phyah
 public T Single(IOrderedQueryable <T> queryable) => queryable.FirstOrDefault();
示例#17
0
 public static User GetUserById(this IOrderedQueryable <User> collection, int id)
 {
     return(collection.FirstOrDefault(x => x.Id == id));
 }