Beispiel #1
0
        /// <summary>
        /// Sorts IQueryable source according to provided sort criteria
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source">Source IQueryable to sort</param>
        /// <param name="sortCriteria">IEnumerable of SortCriterias</param>
        /// <returns><see cref="IOrderedQueryable<typeparamref name="T"/>"/></returns>
        public static IOrderedQueryable <T> DoSorting <T>(this IQueryable <T> source, IEnumerable <SortCriteria> sortCriteria)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            IOrderedQueryable <T> ordered = source.OrderBy(p => 0);

            if (!ordered.Any() || sortCriteria == null)
            {
                return(ordered);
            }

            int index = 0;

            using (var sequenceEnum = sortCriteria.OrderBy(x => x.Priority).GetEnumerator())
            {
                while (sequenceEnum.MoveNext())
                {
                    if (index == 0)
                    {
                        ordered = (sequenceEnum.Current.Order == SortOrder.Ascending) ? source.OrderBy(sequenceEnum.Current.ColumnName) : source.OrderByDescending(sequenceEnum.Current.ColumnName);
                    }
                    else
                    {
                        ordered = (sequenceEnum.Current.Order == SortOrder.Ascending) ? ordered.ThenBy(sequenceEnum.Current.ColumnName) : ordered.ThenByDescending(sequenceEnum.Current.ColumnName);
                    }
                    index++;
                }
            }

            return(ordered);
        }
 public void SearchByName(ref IOrderedQueryable <Employee> employees, string employeeName)
 {
     if (!employees.Any() || string.IsNullOrWhiteSpace(employeeName))
     {
         return;
     }
     employees = employees.Where(o => o.FullName.ToLower().Contains(employeeName.Trim().ToLower())).OrderBy(att => att.BranchId);
 }
Beispiel #3
0
 public void SearchByName(ref IOrderedQueryable <Company> companies, string branchName)
 {
     if (!companies.Any() || string.IsNullOrWhiteSpace(branchName))
     {
         return;
     }
     companies = companies.Where(o => o.BranchName.ToLower().Contains(branchName.Trim().ToLower())).OrderBy(att => att.BranchId);
 }
 private void SearchByName(ref IOrderedQueryable <User> users, string userName)
 {
     if (!users.Any() || string.IsNullOrWhiteSpace(userName))
     {
         return;
     }
     users = (IOrderedQueryable <User>)users.Where(o => o.Name.ToLower().Contains(userName.Trim().ToLower()));
 }
Beispiel #5
0
 private void SearchByName(ref IOrderedQueryable <Course> courses, string courseName)
 {
     if (!courses.Any() || string.IsNullOrWhiteSpace(courseName))
     {
         return;
     }
     courses = (IOrderedQueryable <Course>)courses.Where(o => o.Name.ToLower().Contains(courseName.Trim().ToLower()));
 }
        private string GetStudentText(IOrderedQueryable <Models.Student> students)
        {
            if (!students.Any())
            {
                return("NONE");
            }

            return(string.Join(",", students.Select(x => x.Name).ToArray()));
        }
Beispiel #7
0
        /// <summary>
        /// Get next available BaseNoteOrdinal
        /// </summary>
        /// <param name="db">ApplicationDbContext</param>
        /// <param name="noteFileId">NoteFileID</param>
        /// <returns></returns>
        public static async Task <int> NextBaseNoteOrdinal(ApplicationDbContext db, int noteFileId, int arcId)
        {
            IOrderedQueryable <NoteHeader> bnhq = GetBaseNoteHeaderByIdRev(db, noteFileId, arcId);

            if (bnhq == null || !bnhq.Any())
            {
                return(1);
            }

            NoteHeader bnh = await bnhq.FirstAsync();

            return(bnh.NoteOrdinal + 1);
        }
Beispiel #8
0
        private IEnumerable <ListIngrediente> ConvertList(IOrderedQueryable <Domain.Ingrediente.Entity.Ingrediente> list)
        {
            ICollection <ListIngrediente> result = new List <ListIngrediente>();

            if (list.Any())
            {
                foreach (var item in list)
                {
                    result.Add(item);
                }
            }

            return(result);
        }
Beispiel #9
0
 public static bool AnyNoLock <T>(this IOrderedQueryable <T> query)
 {
     using (
         var scope = new TransactionScope(TransactionScopeOption.Required,
                                          new TransactionOptions()
     {
         IsolationLevel = IsolationLevel.ReadUncommitted
     },
                                          TransactionScopeAsyncFlowOption.Enabled))
     {
         var toReturn = query.Any();
         scope.Complete();
         return(toReturn);
     }
 }
Beispiel #10
0
 public static bool AnyNoLock <T>(this IOrderedQueryable <T> query, Expression <Func <T, bool> > predicate)
 {
     using (
         var scope = new TransactionScope(TransactionScopeOption.Required,
                                          new TransactionOptions()
     {
         IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted
     },
                                          TransactionScopeAsyncFlowOption.Enabled))
     {
         var toReturn = query.Any(predicate);
         scope.Complete();
         return(toReturn);
     }
 }
        private static AnalyticsPrice CalculateAnalyticsPrice(IOrderedQueryable <HourlyShareRate> ratesOrderedByTimestamp)
        {
            if (!ratesOrderedByTimestamp.Any())
            {
                return(null);
            }

            return(new AnalyticsPrice
            {
                High = ratesOrderedByTimestamp.Max(r => r.Rate),
                Low = ratesOrderedByTimestamp.Min(r => r.Rate),
                Open = ratesOrderedByTimestamp.First().Rate,
                Close = ratesOrderedByTimestamp.Last().Rate,
            });
        }
Beispiel #12
0
        private void ApplySort(ref IOrderedQueryable <Owner> owners, string orderByQueryString)
        {
            if (!owners.Any())
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(orderByQueryString))
            {
                owners = owners.OrderBy(x => x.Name);
                return;
            }

            var orderParams       = orderByQueryString.Trim().Split(',');
            var propertyInfos     = typeof(Owner).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            var orderQueryBuilder = new StringBuilder();

            foreach (var param in orderParams)
            {
                if (string.IsNullOrWhiteSpace(param))
                {
                    continue;
                }

                var propertyFromQueryName = param.Split(" ")[0];
                var objectProperty        = propertyInfos.FirstOrDefault(pi => pi.Name.Equals(propertyFromQueryName, StringComparison.InvariantCultureIgnoreCase));

                if (objectProperty == null)
                {
                    continue;
                }

                var sortingOrder = param.EndsWith(" desc") ? "descending" : "ascending";

                orderQueryBuilder.Append($"{objectProperty.Name.ToString()} {sortingOrder}, ");
            }

            var orderQuery = orderQueryBuilder.ToString().TrimEnd(',', ' ');

            if (string.IsNullOrWhiteSpace(orderQuery))
            {
                owners = owners.OrderBy(x => x.Name);
                return;
            }

            owners = owners.OrderBy(orderQuery);
        }
Beispiel #13
0
        public static IQueryable <T> Pagination <T>(this IOrderedQueryable <T> items, IPaging pagination)
        {
            if (pagination == null)
            {
                return(items);
            }

            pagination.Length = 0;
            if (items == null || !items.Any())
            {
                return(items);
            }

            var skip = pagination.Page == 0 ? 0 : pagination.Page;

            pagination.Length = items.Count();

            return(items.Skip(skip * pagination.PageSize).Take(pagination.PageSize));
        }
Beispiel #14
0
        public virtual IActionResult GaleriPictureAdd(int pictureId, int displayOrder,
                                                      string overrideAltAttribute, string overrideTitleAttribute, string url, int galeriId)
        {
            if (pictureId == 0)
            {
                throw new ArgumentException();
            }

            Slider galeri = _sliderRepository.GetById(galeriId)
                            ?? throw new ArgumentException("No product found with the specified id");
            IOrderedQueryable <SliderPictureMapping> query = from pg in _sliderPicturRepository.Table
                                                             where pg.SliderId == galeriId
                                                             orderby pg.DisplayOrder, pg.Id
            select pg;

            if (query.Any(p => p.PictureId == pictureId))
            {
                return(Json(new { Result = false }));
            }
            Picture picture = _pictureService.GetPictureById(pictureId)
                              ?? throw new ArgumentNullException("No Picture found with th spec id");

            _pictureService.UpdatePicture(picture.Id,
                                          _pictureService.LoadPictureBinary(picture),
                                          picture.MimeType,
                                          picture.SeoFilename,
                                          overrideAltAttribute,
                                          overrideTitleAttribute
                                          );
            _pictureService.SetSeoFilename(picture.Id, _pictureService.GetPictureSeName(galeri.Name));
            _sliderPicturRepository.Insert(new SliderPictureMapping
            {
                SliderId     = galeriId,
                DisplayOrder = displayOrder,
                PictureId    = pictureId,
                Url          = url,
                PictureTitle = overrideTitleAttribute,
                Title        = overrideAltAttribute
            });

            return(Json(new { Result = true }));
        }
Beispiel #15
0
        public void Entities_Page()
        {
            //Arrange
            const int total    = 33;
            const int page     = 2;
            const int pageSize = 10;

            PopulateTestData(total, 0);

            //Act
            var expected = _context.Blogs.OrderBy(b => b.BlogId).Page(page, pageSize).ToArray();
            IOrderedQueryable queryable = _context.Blogs.Select("it").OrderBy("BlogId");
            bool any    = queryable.Any();
            var  count  = queryable.Count();
            var  result = queryable.Page(page, pageSize).ToDynamicArray <Blog>();

            //Assert
            Assert.Equal(true, any);
            Assert.Equal(total, count);
            Assert.Equal(expected, result);
        }
        /// <summary>
        /// Gets the entries.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="so">The so.</param>
        /// <returns>TimeData[][].</returns>
        public static TimeData[] GetEntries(DateTime @from, DateTime to, SortOrder so)
        {
            using (var db = new TimeDataContext(TimeDataContext.DBConnectionString)) {
                @from = new DateTime(@from.Year, @from.Month, @from.Day, 0, 0, 0);
                to    = new DateTime(to.Year, to.Month, to.Day, 0, 0, 0).AddDays(1);
                IOrderedQueryable <TimeDataItem> entries = from x in db.TimeDataItems
                                                           where x.Date >= @from && x.Date < to
                                                           orderby x.Date
                                                           select x;

                if (entries.Any())
                {
                    IEnumerable <TimeDataItem> e = so == SortOrder.DateNewestToOldest ? entries.ToArray().Reverse() : entries.ToArray();
                    return(e.Select(tdi => new TimeData
                    {
                        BibleStudies = tdi.BibleStudies, Books = tdi.Books, Brochures = tdi.Brochures, Date = tdi.Date, ItemId = tdi.ItemId, Magazines = tdi.Magazines, Minutes = tdi.Minutes, Notes = tdi.Notes, ReturnVisits = tdi.ReturnVisits, Tracts = tdi.Tracts ?? 0
                    }).ToArray());
                }
                return(new TimeData[0]);
            }
        }
Beispiel #17
0
        public PagedList(IOrderedQueryable <EntityType> source, int pageNumber, int pageSize)
        {
            Items      = Enumerable.Empty <EntityType>();
            PageSize   = pageSize;
            PageNumber = pageNumber;

            if (source == null || !source.Any())
            {
                return;
            }

            IEnumerable <EntityType> paged = source;

            if (pageSize > 0)
            {
                var start = PageSize * (PageNumber - 1);
                paged = source.Skip(start).Take(PageSize);
            }

            Items       = paged;
            RecordCount = source.Count();
        }
Beispiel #18
0
        /// <summary>
        /// Gets the previous visits.
        /// </summary>
        /// <param name="rvItemId">The rv item id.</param>
        /// <param name="so">The Sort Order.</param>
        /// <returns>RvPreviousVisitData[].</returns>
        public static RvPreviousVisitData[] GetPreviousVisits(int rvItemId, SortOrder so)
        {
            var rvVists = new List <RvPreviousVisitData>();

            using (var db = new RvPreviousVisitsContext(RvPreviousVisitsContext.DBConnectionString)) {
                IOrderedQueryable <RvPreviousVisitItem> qry = from x in db.RvPreviousVisitItems
                                                              where x.RvItemId == rvItemId
                                                              orderby x.Date
                                                              select x;

                if (qry.Any())
                {
                    IEnumerable <RvPreviousVisitItem> visits = so == SortOrder.DateNewestToOldest ? qry.ToArray().Reverse() : qry.ToArray();
                    foreach (RvPreviousVisitItem v in visits)
                    {
                        rvVists.Add(RvPreviousVisitData.Copy(v));
                    }
                    return(rvVists.ToArray());
                }
                return(new RvPreviousVisitData[0]);
            }
        }
Beispiel #19
0
        private void LoadItemAuditTrailDetails(string ItemID)
        {
            SCAuditLogsDataContext scAuditLogsDataContext =
                new SCAuditLogsDataContext();

            IOrderedQueryable <Log> logs =
                scAuditLogsDataContext.Logs.Where(x =>
                                                  x.SCItemId == ItemID).
                OrderByDescending(x => x.Date);

            if (logs == null && !logs.Any())
            {
                ShowMessage("No audit trail records found, it seems that you haven't configured SCAuditTrail or no actions recorded yet.",
                            "Error");
                lblMessage.Visible             = true;
                tblSCAuditTrailForItem.Visible = false;
            }
            else
            {
                foreach (Log aLog in logs)
                {
                    if (aLog != null)
                    {
                        TableRow tableRow = new TableRow();
                        tableRow.ID           = "row" + aLog.ID.ToString();
                        tableRow.TableSection = TableRowSection.TableBody;


                        //Action
                        SCBasics.AuditTrail.Utils.UIControlUtil.AddTableCell(tableRow,
                                                                             aLog.SCAction,
                                                                             SCBasics.AuditTrail.Utils.SourceTextType.Text);


                        //UserName
                        SCBasics.AuditTrail.Utils.UIControlUtil.AddTableCell(tableRow,
                                                                             aLog.SCUser,
                                                                             SCBasics.AuditTrail.Utils.SourceTextType.Text);

                        //Date
                        SCBasics.AuditTrail.Utils.UIControlUtil.AddTableCell(tableRow,
                                                                             aLog.Date.ToUniversalTime().ToString(),
                                                                             SCBasics.AuditTrail.Utils.SourceTextType.DateTime);


                        //ItemLanguage
                        SCBasics.AuditTrail.Utils.UIControlUtil.AddTableCell(tableRow,
                                                                             aLog.SCLanguage,
                                                                             SCBasics.AuditTrail.Utils.SourceTextType.Text);

                        // ItemVersion
                        SCBasics.AuditTrail.Utils.UIControlUtil.AddTableCell(tableRow,
                                                                             aLog.SCVersion,
                                                                             SCBasics.AuditTrail.Utils.SourceTextType.Text);

                        tblSCAuditTrailForItem.Rows.Add(tableRow);
                    }
                }


                lblMessage.Visible             = true;
                tblSCAuditTrailForItem.Visible = true;
            }
        }