예제 #1
0
        public JsonResult GetDeliveredOrder(string sidx, string sord, int page, int rows)  //Gets the todo Lists.
        {
            int pageIndex = Convert.ToInt32(page) - 1;
            int pageSize  = rows;

            List <OrderViewModel> vmorder = new List <OrderViewModel>();
            var productList = _productBusiness.GetListWT();
            var orderList   = _orderBusiness.GetListWT(c => c.OrderStatus == "Delivered");

            vmorder = (from c in orderList
                       select new OrderViewModel
            {
                OrderId = c.OrderId,
                OrderCode = c.OrderCode,
                OrderDate = c.OrderDate,
                OrderStatus = c.OrderStatus,
                OrderedItems = GetOrderedItems(c.OrderId, productList),
                CustomerName = c.FirstName + " " + c.LastName,
                //FullAddress = c.Address + ", " + c.Pincode + " " + c.City
            }).OrderByDescending(col => col.OrderDate).ToList();

            var records = vmorder.AsQueryable();


            int totalRecords = records.Count();
            var totalPages   = (int)Math.Ceiling((float)totalRecords / (float)rows);

            if (!string.IsNullOrEmpty(sidx) && !string.IsNullOrEmpty(sord))
            {
                if (sord.Trim().ToLower() == "asc")
                {
                    records = SortHelper.OrderBy(records, sidx);
                }
                else
                {
                    records = SortHelper.OrderByDescending(records, sidx);
                }
            }

            //applying paging
            records = records.Skip(pageIndex * pageSize).Take(pageSize);

            var jsonData = new
            {
                total = totalPages,
                page,
                records = totalRecords,
                rows    = records
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public List <ProviderModel> GetProvider(int?page, int?limit, string sortBy, string direction, string searchString, out int total)
        {
            var providerList = db.Proveedor.ToList();

            var productList  = Factory.Factory.CreateListProductdb();
            var listProvider = Factory.Factory.ListProviderModels();

            //Edit Product Selected
            foreach (var item in providerList)
            {
                var pc = db.IdProveedorProducto.Where(x => x.IdProveedor == item.IdProveedor).ToList();

                foreach (var itemproduct in pc)
                {
                    var product = db.Product.Where(x => x.IdProducto == itemproduct.IdProducto).First();
                    productList.Add(product);
                }

                var map = MapperObject.CreateProveedorProductModel(item, productList);
                listProvider.Add(map);
            }

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                listProvider = listProvider.Where(p => (p.RazonSocial.ToUpper().StartsWith(searchString.ToUpper()) || p.RazonSocial.ToUpper().EndsWith(searchString.ToUpper())) ||
                                                  (p.Codigo.ToUpper().StartsWith(searchString.ToUpper()) || p.Codigo.ToUpper().EndsWith(searchString.ToUpper()))).ToList();
            }

            total = listProvider.Count();
            var clienteQueryable = listProvider.AsQueryable();

            if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
            {
                if (direction.Trim().ToLower() == "asc")
                {
                    clienteQueryable = SortHelper.OrderBy(clienteQueryable, sortBy);
                }
                else
                {
                    clienteQueryable = SortHelper.OrderByDescending(clienteQueryable, sortBy);
                }
            }

            if (page.HasValue && limit.HasValue)
            {
                int start = (page.Value - 1) * limit.Value;
                clienteQueryable = clienteQueryable.Skip(start).Take(limit.Value);
            }

            return(listProvider);
        }
예제 #3
0
        public List <MenuViewModel> GetAllMenusForGrid(int?page, int?limit, string sortBy, string direction, string searchString, out int total)
        {
            var result = _menuRepository.GetAllMenus().ToViewModelList();

            total = result.Count();
            var records = result;

            records = from m in records
                      join p in records on m.ParentId equals p.Id into inners
                      from od in inners.DefaultIfEmpty()
                      select new MenuViewModel
            {
                Id           = m.Id,
                Name         = m.Name,
                DisplayName  = m.DisplayName,
                ParentId     = m.ParentId,
                ParentName   = (od == null?String.Empty:od.Name),
                LinkUrl      = m.LinkUrl,
                ImageUrl     = m.ImageUrl,
                IsActive     = m.IsActive,
                CreatedBy    = m.CreatedBy,
                CreatedDate  = m.CreatedDate,
                ModifiedBy   = m.ModifiedBy,
                ModifiedDate = m.ModifiedDate,
                DisplayOrder = m.DisplayOrder
            };

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                records = records.Where(p => p.Name.Contains(searchString) || p.DisplayName.Contains(searchString));
            }
            if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
            {
                if (direction.Trim().ToLower() == "asc")
                {
                    records = SortHelper.OrderBy(records, sortBy);
                }
                else
                {
                    records = SortHelper.OrderByDescending(records, sortBy);
                }
            }
            if (page.HasValue && limit.HasValue)
            {
                int start = (page.Value - 1) * limit.Value;
                records = records.Skip(start).Take(limit.Value);
            }
            //var result= records.ToList();
            return(records.ToList());
        }
        public JsonResult GetCategory(string sidx, string sord, int page, int rows, string colName, string colValue)  //Gets the todo Lists.
        {
            int pageIndex       = Convert.ToInt32(page) - 1;
            int pageSize        = rows;
            var categoryList    = _categoryBusiness.GetListWT();
            var subcategoryList = _subcategoryBusiness.GetListWT();
            var records         = (from p in subcategoryList
                                   join c in categoryList on p.CategoryId equals c.CategoryId
                                   select new SubCategoryViewModel
            {
                TokenKey = p.TokenKey,
                SubCategoryName = p.SubCategoryName,
                CategoryName = c.CategoryName
            }).AsQueryable();

            //applying filter
            if (!string.IsNullOrEmpty(colName) && !string.IsNullOrEmpty(colValue))
            {
                records = records.Where(c => c.GetType().GetProperty(colName).GetValue(c, null).ToString().ToLower().Contains(colValue.ToLower()));
            }

            int totalRecords = records.Count();
            var totalPages   = (int)Math.Ceiling((float)totalRecords / (float)rows);

            if (!string.IsNullOrEmpty(sidx) && !string.IsNullOrEmpty(sord))
            {
                if (sord.Trim().ToLower() == "asc")
                {
                    records = SortHelper.OrderBy(records, sidx);
                }
                else
                {
                    records = SortHelper.OrderByDescending(records, sidx);
                }
            }

            //applying paging
            records = records.Skip(pageIndex * pageSize).Take(pageSize);

            var jsonData = new
            {
                total = totalPages,
                page,
                records = totalRecords,
                rows    = records
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }
예제 #5
0
        public static (long, int, Op) FindMin(long[,] optimumOperation, int i)
        {
            bool IsDiv3 = i % 3 == 0, IsDiv2 = i % 2 == 0;
            List <(long, int, Op)> SortHelper = new List <(long, int, Op)>();

            if (IsDiv2)
            {
                SortHelper.Add((optimumOperation[0, i / 2], i / 2, Op.Div2));
            }
            if (IsDiv3)
            {
                SortHelper.Add((optimumOperation[0, i / 3], i / 3, Op.Div3));
            }
            SortHelper.Add((optimumOperation[0, i - 1], i - 1, Op.Sub1));
            return(SortHelper
                   .OrderBy(x => x.Item1)
                   .ThenByDescending(x => x.Item3)
                   .First());
        }
예제 #6
0
            public bool IsValid()
            {
                SortHelper[] sorter = new SortHelper[26];
                foreach (char c in Name)
                {
                    int index = c - 'a';
                    sorter[c - 'a'].c = c;
                    ++sorter[c - 'a'].count;
                }
                var postSort = sorter.OrderBy(s => s.c).OrderByDescending(s => s.count);

                for (int i = 0; i < Checksum.Length; ++i)
                {
                    if (Checksum[i] != postSort.ElementAt(i).c)
                    {
                        return(false);
                    }
                }
                return(true);
            }
예제 #7
0
        public List <ProjectStudent> GetReportsJsonData(int?page, int?limit, string sortBy, string direction, out int total, string projectName = null, string projectType = null, bool?isApproved = null, bool?isClosed = null)
        {
            var records = _context.ProjectStudents.Include(p => p.Creator).Include(p => p.Updater).Where(p => p.Project.ProjectType == "Bachelor")
                          .Select(p => new ProjectStudent()
            {
                Id            = p.Id,
                ProjectName   = p.Project.Name,
                StudentName   = p.ApplicationUser.FirstName + " " + p.ApplicationUser.LastName,
                Professor     = (string.IsNullOrEmpty(p.Creator.FirstName) || string.IsNullOrEmpty(p.Creator.LastName)) ? p.Creator.UserName : (p.Creator.FirstName + " " + p.Creator.LastName),
                ProjectType   = p.Project.ProjectType,
                ProjectBranch = p.Project.ProjectSubType
            })
                          .AsQueryable();


            if (!string.IsNullOrEmpty(projectName))
            {
                records = records.Where(r => r.ProjectName.ToLower().Contains(projectName.Trim().ToLower()));
            }

            total = records.Count();

            if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
            {
                if (direction.Trim().ToLower() == "asc")
                {
                    records = SortHelper.OrderBy(records, sortBy);
                }
                else
                {
                    records = SortHelper.OrderByDescending(records, sortBy);
                }
            }
            if (page.HasValue && limit.HasValue)
            {
                int start = (page.Value - 1) * limit.Value;
                records = records.Skip(start).Take(limit.Value);
            }

            return(records.ToList());
        }
예제 #8
0
        public ListModel <ParameterGroupModel> List(FilterModel filterModel)
        {
            var startDate = filterModel.StartDate.ResetTimeToStartOfDay();
            var endDate   = filterModel.EndDate.ResetTimeToEndOfDay();
            Expression <Func <ParameterGroup, bool> > expression;

            if (filterModel.Status != -1)
            {
                var status = filterModel.Status.ToString().ToBoolean();
                if (filterModel.Searched != null)
                {
                    if (status)
                    {
                        expression = c => c.IsApproved && c.Name.Contains(filterModel.Searched);
                    }
                    else
                    {
                        expression = c => c.IsApproved == false && c.Name.Contains(filterModel.Searched);
                    }
                }
                else
                {
                    if (status)
                    {
                        expression = c => c.IsApproved;
                    }
                    else
                    {
                        expression = c => c.IsApproved == false;
                    }
                }
            }
            else
            {
                if (filterModel.Searched != null)
                {
                    expression = c => c.Name.Contains(filterModel.Searched);
                }
                else
                {
                    expression = c => c.Id != Guid.Empty;
                }
            }

            expression = expression.And(e => e.CreationTime >= startDate && e.CreationTime <= endDate);

            var model = filterModel.CreateMapped <FilterModel, ListModel <ParameterGroupModel> >();

            if (model.Paging == null)
            {
                model.Paging = new Paging
                {
                    PageSize   = filterModel.PageSize,
                    PageNumber = filterModel.PageNumber
                };
            }

            var sortHelper = new SortHelper <ParameterGroupModel>();

            var query = _repositoryParameterGroup
                        .Join(x => x.Creator.Person)
                        .Join(x => x.LastModifier.Person)

                        .Where(expression);

            sortHelper.OrderBy(x => x.DisplayOrder);

            model.Paging.TotalItemCount = query.Count();
            var items      = model.Paging.PageSize > 0 ? query.Skip((model.Paging.PageNumber - 1) * model.Paging.PageSize).Take(model.Paging.PageSize) : query;
            var modelItems = new HashSet <ParameterGroupModel>();

            foreach (var item in items)
            {
                var modelItem = item.CreateMapped <ParameterGroup, ParameterGroupModel>();
                modelItem.Creator      = new IdCodeName(item.Creator.Id, item.Creator.Username, item.Creator.Person.DisplayName);
                modelItem.LastModifier = new IdCodeName(item.LastModifier.Id, item.LastModifier.Username, item.LastModifier.Person.DisplayName);
                modelItems.Add(modelItem);
            }
            model.Items = modelItems.ToList();
            var pageSizeDescription = _serviceMain.ApplicationSettings.PageSizeList;
            var pageSizes           = pageSizeDescription.Split(',').Select(s => new KeyValuePair <int, string>(s.ToInt(), s)).ToList();

            pageSizes.Insert(0, new KeyValuePair <int, string>(-1, "[" + Dictionary.All + "]"));
            model.Paging.PageSizes = pageSizes;
            model.Paging.PageCount = (int)Math.Ceiling((float)model.Paging.TotalItemCount / model.Paging.PageSize);
            if (model.Paging.TotalItemCount > model.Items.Count)
            {
                model.Paging.HasNextPage = true;
            }

            // ilk sayfa ise

            if (model.Paging.PageNumber == 1)
            {
                if (model.Paging.TotalItemCount > 0)
                {
                    model.Paging.IsFirstPage = true;
                }

                // tek sayfa ise

                if (model.Paging.PageCount == 1)
                {
                    model.Paging.IsLastPage = true;
                }
            }

            // son sayfa ise
            else if (model.Paging.PageNumber == model.Paging.PageCount)
            {
                model.Paging.HasNextPage = false;
                // tek sayfa değilse

                if (model.Paging.PageCount > 1)
                {
                    model.Paging.IsLastPage      = true;
                    model.Paging.HasPreviousPage = true;
                }
            }

            // ara sayfa ise
            else
            {
                model.Paging.HasNextPage     = true;
                model.Paging.HasPreviousPage = true;
            }

            if (model.Paging.TotalItemCount > model.Items.Count && model.Items.Count <= 0)
            {
                model.Message = Messages.DangerRecordNotFoundInPage;
            }

            if (model.Paging.TotalItemCount == 0)
            {
                model.Message = Messages.DangerRecordNotFound;
            }
            return(model);
        }
예제 #9
0
        private ListModel <CategoryModel> List(DateTime startDate, DateTime endDate, int pageNumber, int pageSize, int status, string searched, Guid languageId, ListModel <CategoryModel> model)
        {
            var resetedStartDate = startDate.ResetTimeToStartOfDay();
            var resetedEndDate   = endDate.ResetTimeToEndOfDay();
            var language         = languageId != Guid.Empty ? _repositoryLanguage.Get(x => x.Id == languageId) : _defaultLanguage;

            Expression <Func <Category, bool> > expression;

            if (model.Paging == null)
            {
                model.Paging = new Paging
                {
                    PageSize   = pageSize,
                    PageNumber = pageNumber
                };
            }

            if (status != -1)
            {
                var bStatus = status.ToString().ToBoolean();
                if (searched != null)
                {
                    if (bStatus)
                    {
                        expression = c => c.CategoryLanguageLines.Any(x => x.Name.Contains(searched) && x.IsApproved);
                    }
                    else
                    {
                        expression = c => c.CategoryLanguageLines.Any(x => x.Name.Contains(searched) && x.IsApproved == false);
                    }
                }
                else
                {
                    if (bStatus)
                    {
                        expression = c => c.CategoryLanguageLines.Any(x => x.IsApproved);
                    }
                    else
                    {
                        expression = c => c.CategoryLanguageLines.Any(x => x.IsApproved == false);
                    }
                }
            }
            else
            {
                if (searched != null)
                {
                    expression = c => c.CategoryLanguageLines.Any(x => x.Name.Contains(searched));
                }
                else
                {
                    expression = c => c.Id != Guid.Empty;
                }
            }

            expression = expression.And(e => e.CreationTime >= resetedStartDate && e.CreationTime <= resetedEndDate);

            var sortHelper = new SortHelper <CategoryModel>();

            var query = _repositoryCategory
                        .Join(x => x.Creator.Person)
                        .Join(x => x.LastModifier.Person)
                        .Join(z => z.CategoryLanguageLines)
                        .ThenJoin(x => x.Language)
                        .Where(expression);

            sortHelper.OrderBy(x => x.DisplayOrder);

            model.Paging.TotalItemCount = query.Count();
            var items      = model.Paging.PageSize > 0 ? query.Skip((model.Paging.PageNumber - 1) * model.Paging.PageSize).Take(model.Paging.PageSize) : query;
            var modelItems = new HashSet <CategoryModel>();

            foreach (var item in items)
            {
                CategoryModel modelItem;
                if (item.CategoryLanguageLines == null)
                {
                    modelItem = new CategoryModel();
                }
                else
                {
                    var itemLine = item.CategoryLanguageLines.FirstOrDefault(x => x.Language.Id == language.Id);
                    modelItem = itemLine != null?itemLine.CreateMapped <CategoryLanguageLine, CategoryModel>() : new CategoryModel();
                }

                modelItem.Creator      = new IdCodeName(item.Creator.Id, item.Creator.Username, item.Creator.Person.DisplayName);
                modelItem.LastModifier = new IdCodeName(item.LastModifier.Id, item.LastModifier.Username, item.LastModifier.Person.DisplayName);
                modelItem.Language     = new IdCodeName(language.Id, language.Code, language.Name);
                modelItem.CategoryId   = item.Id;
                modelItems.Add(modelItem);
            }
            model.Items = modelItems.ToList();
            var pageSizeDescription = _serviceMain.ApplicationSettings.PageSizeList;
            var pageSizes           = pageSizeDescription.Split(',').Select(s => new KeyValuePair <int, string>(s.ToInt(), s)).ToList();

            pageSizes.Insert(0, new KeyValuePair <int, string>(-1, "[" + Dictionary.All + "]"));
            model.Paging.PageSizes = pageSizes;
            model.Paging.PageCount = (int)Math.Ceiling((float)model.Paging.TotalItemCount / model.Paging.PageSize);
            if (model.Paging.TotalItemCount > model.Items.Count)
            {
                model.Paging.HasNextPage = true;
            }

            // ilk sayfa ise

            if (model.Paging.PageNumber == 1)
            {
                if (model.Paging.TotalItemCount > 0)
                {
                    model.Paging.IsFirstPage = true;
                }

                // tek sayfa ise

                if (model.Paging.PageCount == 1)
                {
                    model.Paging.IsLastPage = true;
                }
            }

            // son sayfa ise
            else if (model.Paging.PageNumber == model.Paging.PageCount)
            {
                model.Paging.HasNextPage = false;
                // tek sayfa değilse

                if (model.Paging.PageCount > 1)
                {
                    model.Paging.IsLastPage      = true;
                    model.Paging.HasPreviousPage = true;
                }
            }

            // ara sayfa ise
            else
            {
                model.Paging.HasNextPage     = true;
                model.Paging.HasPreviousPage = true;
            }

            if (model.Paging.TotalItemCount > model.Items.Count && model.Items.Count <= 0)
            {
                model.Message = Messages.DangerRecordNotFoundInPage;
            }

            if (model.Paging.TotalItemCount == 0)
            {
                model.Message = Messages.DangerRecordNotFound;
            }
            return(model);
        }
예제 #10
0
        public ListModel <LanguageModel> List(FilterModel filterModel)
        {
            var startDate = filterModel.StartDate.ResetTimeToStartOfDay();

            var endDate = filterModel.EndDate.ResetTimeToEndOfDay();

            Expression <Func <Language, bool> > expression;

            if (filterModel.Status != -1)
            {
                var status = filterModel.Status.ToString().ToBoolean();

                if (filterModel.Searched != null)
                {
                    if (status)
                    {
                        expression = c => c.IsApproved && c.Name.Contains(filterModel.Searched);
                    }
                    else
                    {
                        expression = c => c.IsApproved == false && c.Name.Contains(filterModel.Searched);
                    }
                }
                else
                {
                    if (status)
                    {
                        expression = c => c.IsApproved;
                    }
                    else
                    {
                        expression = c => c.IsApproved == false;
                    }
                }
            }
            else
            {
                if (filterModel.Searched != null)
                {
                    expression = c => c.Name.Contains(filterModel.Searched);
                }
                else
                {
                    expression = c => c.Id != Guid.Empty;
                }
            }

            expression = expression.And(e => e.CreationTime >= startDate && e.CreationTime <= endDate);

            var listModel = filterModel.CreateMapped <FilterModel, ListModel <LanguageModel> >();

            listModel.Paging ??= new Paging
            {
                PageSize   = filterModel.PageSize,
                PageNumber = filterModel.PageNumber
            };

            var sortHelper = new SortHelper <Language>();

            sortHelper.OrderBy(x => x.DisplayOrder);

            var query = (IOrderedQueryable <Language>)_repositoryLanguage
                        .Get().Where(expression);

            query = sortHelper.GenerateOrderedQuery(query);

            listModel.Paging.TotalItemCount = query.Count();

            var items = listModel.Paging.PageSize > 0 ? query.Skip((listModel.Paging.PageNumber - 1) * listModel.Paging.PageSize).Take(listModel.Paging.PageSize) : query;

            var modelItems = new HashSet <LanguageModel>();

            foreach (var item in items)
            {
                var modelItem = item.CreateMapped <Language, LanguageModel>();

                modelItems.Add(modelItem);
            }

            listModel.Items = modelItems.ToList();

            var pageSizeDescription = _serviceMain.ApplicationSettings.PageSizeList;

            var pageSizes = pageSizeDescription.Split(',').Select(s => new KeyValuePair <int, string>(s.ToInt(), s)).ToList();

            pageSizes.Insert(0, new KeyValuePair <int, string>(-1, "[" + Dictionary.All + "]"));

            listModel.Paging.PageSizes = pageSizes;

            listModel.Paging.PageCount = (int)Math.Ceiling((float)listModel.Paging.TotalItemCount / listModel.Paging.PageSize);

            if (listModel.Paging.TotalItemCount > listModel.Items.Count)
            {
                listModel.Paging.HasNextPage = true;
            }

            if (listModel.Paging.PageNumber == 1)
            {
                if (listModel.Paging.TotalItemCount > 0)
                {
                    listModel.Paging.IsFirstPage = true;
                }


                if (listModel.Paging.PageCount == 1)
                {
                    listModel.Paging.IsLastPage = true;
                }
            }

            else if (listModel.Paging.PageNumber == listModel.Paging.PageCount)
            {
                listModel.Paging.HasNextPage = false;

                if (listModel.Paging.PageCount > 1)
                {
                    listModel.Paging.IsLastPage      = true;
                    listModel.Paging.HasPreviousPage = true;
                }
            }

            else
            {
                listModel.Paging.HasNextPage     = true;
                listModel.Paging.HasPreviousPage = true;
            }

            if (listModel.Paging.TotalItemCount > listModel.Items.Count && listModel.Items.Count <= 0)
            {
                listModel.Message = Messages.DangerRecordNotFoundInPage;
            }

            if (listModel.Paging.TotalItemCount == 0)
            {
                listModel.Message = Messages.DangerRecordNotFound;
            }

            return(listModel);
        }
        public List <Project> GetJsonData(int?page, int?limit, string sortBy, string direction, out int total, string projectName = null, string projectType = null,
                                          string projectSubType = null, string Professor = null)
        {
            var isBac   = _context.ApplicationUsers.Where(p => p.Id == UserIdentity.Id).Select(p => p.IsBachelorStudent).SingleOrDefault();
            var records = _context.Projects.Include(p => p.Creator).Include(p => p.Updater)
                          .Select(p => new Project()
            {
                Id                  = p.Id,
                Name                = p.Name,
                IsApproved          = p.IsApproved,
                IsClosed            = p.IsClosed,
                ApprovalSummary     = p.IsApproved.Value ? "Yes" : "No",
                CloserSummary       = p.IsClosed?"Yes":"No",
                MaxApprovedStudents = p.MaxApprovedStudents,
                ProjectType         = p.ProjectType,
                ProjectSubType      = p.ProjectSubType,
                CreatedBy           = (string.IsNullOrEmpty(p.Creator.FirstName) || string.IsNullOrEmpty(p.Creator.LastName)) ? p.Creator.UserName : (p.Creator.FirstName + " " + p.Creator.LastName)
            }).Where(p => p.IsApproved.Value && !p.IsClosed && !_context.ProjectStudents.Select(c => c.ApplicationUserId).Contains(UserIdentity.Id) && isBac == true)
                          .AsQueryable();


            if (!string.IsNullOrEmpty(projectName))
            {
                records = records.Where(r => r.Name.ToLower().Contains(projectName.Trim().ToLower()));
            }
            if (!string.IsNullOrEmpty(projectType) && projectType != "Select")
            {
                records = records.Where(r => r.ProjectType.ToLower().Contains(projectType.Trim().ToLower()));
            }
            if (!string.IsNullOrEmpty(projectSubType) && projectSubType != "Select")
            {
                records = records.Where(r => r.ProjectSubType.ToLower().Contains(projectSubType.Trim().ToLower()));
            }
            if (!string.IsNullOrEmpty(Professor))
            {
                records = records.Where(r => r.CreatedBy.ToLower().Contains(Professor.Trim().ToLower()));
            }


            total = records.Count();

            if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
            {
                if (direction.Trim().ToLower() == "asc")
                {
                    records = SortHelper.OrderBy(records, sortBy);
                }
                else
                {
                    records = SortHelper.OrderByDescending(records, sortBy);
                }
            }
            if (page.HasValue && limit.HasValue)
            {
                int start = (page.Value - 1) * limit.Value;
                records = records.Skip(start).Take(limit.Value);
            }


            return(records.ToList());
        }
예제 #12
0
        private ListModel <UserModel> List(DateTime startDate, DateTime endDate, int pageNumber, int pageSize, int status, string searched, ICollection <Guid> parentIds, ListModel <UserModel> model)
        {
            var resetedStartDate = startDate.ResetTimeToStartOfDay();
            var resetedEndDate   = endDate.ResetTimeToEndOfDay();

            Expression <Func <User, bool> > expression;

            model.Paging ??= new Paging
            {
                PageSize   = pageSize,
                PageNumber = pageNumber
            };

            if (status != -1)
            {
                var bStatus = status.ToString().ToBoolean();

                if (searched != null)
                {
                    if (bStatus)
                    {
                        expression = c => c.IsApproved && c.Username.Contains(searched);
                    }
                    else
                    {
                        expression = c => c.IsApproved == false && c.Username.Contains(searched);
                    }
                }
                else
                {
                    if (bStatus)
                    {
                        expression = c => c.IsApproved;
                    }
                    else
                    {
                        expression = c => c.IsApproved == false;
                    }
                }
            }
            else
            {
                if (searched != null)
                {
                    expression = c => c.Username.Contains(searched);
                }
                else
                {
                    expression = c => c.Id != Guid.Empty;
                }
            }

            expression = expression.And(e => e.CreationTime >= resetedStartDate && e.CreationTime <= resetedEndDate);

            if (parentIds != null)
            {
                if (parentIds.Count > 0)
                {
                    expression = expression.And(e => e.RoleUserLines.Any(x => parentIds.Contains(x.Role.Id)));
                }
            }

            var identityUserMinRoleLevel = _serviceMain.IdentityUserMinRoleLevel;

            expression = expression.And(x => x.RoleUserLines.All(t => t.Role.Level > identityUserMinRoleLevel));

            var sortHelper = new SortHelper <User>();

            sortHelper.OrderBy(x => x.DisplayOrder);

            var query = (IOrderedQueryable <User>)_repositoryUser
                        .Join(x => x.Person)
                        .Join(x => x.Creator.Person)
                        .Join(x => x.LastModifier.Person)
                        .Join(x => x.RoleUserLines)
                        .ThenJoin(x => x.Role)
                        .Where(expression);

            query = sortHelper.GenerateOrderedQuery(query);

            model.Paging.TotalItemCount = query.Count();

            var items = model.Paging.PageSize > 0 ? query.Skip((model.Paging.PageNumber - 1) * model.Paging.PageSize).Take(model.Paging.PageSize) : query;

            var modelItems = new HashSet <UserModel>();

            foreach (var item in items)
            {
                var modelItem = item.CreateMapped <User, UserModel>();
                modelItem.Creator      = new IdName(item.Creator.Id, item.Creator.Person.DisplayName);
                modelItem.LastModifier = new IdName(item.LastModifier.Id, item.LastModifier.Person.DisplayName);
                modelItem.IdentityCode = item.Person.IdentityCode;
                modelItem.FirstName    = item.Person.FirstName;
                modelItem.LastName     = item.Person.LastName;
                modelItem.Roles        = item.RoleUserLines.Select(t => t.Role).Select(role => new IdCodeNameSelected(role.Id, role.Code, role.Name, true)).ToList();
                modelItems.Add(modelItem);
            }

            model.Items = modelItems.ToList();

            var pageSizeDescription = _serviceMain.ApplicationSettings.PageSizeList;

            var pageSizes = pageSizeDescription.Split(',').Select(s => new KeyValuePair <int, string>(s.ToInt(), s)).ToList();

            pageSizes.Insert(0, new KeyValuePair <int, string>(-1, "[" + Dictionary.All + "]"));

            model.Paging.PageSizes = pageSizes;

            model.Paging.PageCount = (int)Math.Ceiling((float)model.Paging.TotalItemCount / model.Paging.PageSize);

            if (model.Paging.TotalItemCount > model.Items.Count)
            {
                model.Paging.HasNextPage = true;
            }

            if (model.Paging.PageNumber == 1)
            {
                if (model.Paging.TotalItemCount > 0)
                {
                    model.Paging.IsFirstPage = true;
                }


                if (model.Paging.PageCount == 1)
                {
                    model.Paging.IsLastPage = true;
                }
            }

            else if (model.Paging.PageNumber == model.Paging.PageCount)
            {
                model.Paging.HasNextPage = false;

                if (model.Paging.PageCount > 1)
                {
                    model.Paging.IsLastPage      = true;
                    model.Paging.HasPreviousPage = true;
                }
            }

            else
            {
                model.Paging.HasNextPage     = true;
                model.Paging.HasPreviousPage = true;
            }

            if (model.Paging.TotalItemCount > model.Items.Count && model.Items.Count <= 0)
            {
                model.Message = Messages.DangerRecordNotFoundInPage;
            }

            if (model.Paging.TotalItemCount == 0)
            {
                model.Message = Messages.DangerRecordNotFound;
            }

            return(model);
        }
예제 #13
0
        public List <ItemType> GetJsonData(int?page, int?limit, string sortBy, string direction, out int total, string name)
        {
            var results = new List <ItemType>();

            results.Add(new ItemType()
            {
                ItemTypeId = 1, ItemTypeName = "Type1", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 2, ItemTypeName = "Type2", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 3, ItemTypeName = "Type3", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 4, ItemTypeName = "Type4", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 5, ItemTypeName = "Type5", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 6, ItemTypeName = "Type6", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 7, ItemTypeName = "Type7", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 8, ItemTypeName = "Type8", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 9, ItemTypeName = "Type9", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 10, ItemTypeName = "Type10", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 11, ItemTypeName = "Type11", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 12, ItemTypeName = "Type12", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 13, ItemTypeName = "Type13", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 14, ItemTypeName = "Type14", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 15, ItemTypeName = "Type15", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 16, ItemTypeName = "Type16", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 17, ItemTypeName = "Type17", ItemTypeDescription = "Type1"
            });
            results.Add(new ItemType()
            {
                ItemTypeId = 18, ItemTypeName = "Type18", ItemTypeDescription = "Type1"
            });

            var records = results.ToArray().AsQueryable();

            if (!string.IsNullOrEmpty(name))
            {
                records = records.Where(r => r.ItemTypeName.ToLower().Contains(name.Trim().ToLower()));
            }

            total = records.Count();

            if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
            {
                if (direction.Trim().ToLower() == "asc")
                {
                    records = SortHelper.OrderBy(records, sortBy);
                }
                else
                {
                    records = SortHelper.OrderByDescending(records, sortBy);
                }
            }
            if (page.HasValue && limit.HasValue)
            {
                int start = (page.Value - 1) * limit.Value;
                records = records.Skip(start).Take(limit.Value);
            }
            return(records.ToList());
        }
예제 #14
0
        public JsonResult GetNewOrder(string sidx, string sord, int page, int rows, string colName, string colValue)  //Gets the todo Lists.
        {
            int pageIndex = Convert.ToInt32(page) - 1;
            int pageSize  = rows;

            List <SaleRecordViewModel> vmorder = new List <SaleRecordViewModel>();
            var productList = _productBusiness.GetListWT();
            var orderList   = _orderBusiness.GetListWT();

            vmorder = (from c in orderList
                       select new SaleRecordViewModel
            {
                OrderId = c.OrderId,
                OrderStatus = c.OrderStatus,
                OrderCode = c.OrderCode,
                OrderDate = c.OrderDate,
                Vat = Convert.ToDouble(GetVATOrderedItems(c.OrderId, productList)),
                Sat = Convert.ToDouble(GetSATOrderedItems(c.OrderId, productList)),
                // TotalPrice = 2000,
                TotalPrice = Convert.ToDouble(GetOrderedItems(c.OrderId, productList)),
                CustomerName = c.FirstName + " " + c.LastName,
                Discount = Convert.ToDouble(GetDiscountedOrderedItems(c.OrderId, productList)),
                TaxTotalPrice = Convert.ToDouble(GetTotal(c.OrderId, productList))
            }).OrderByDescending(col => col.OrderDate).Where(u => u.OrderStatus == "Delivered").ToList();

            var records      = vmorder.AsQueryable();
            int totalRecords = records.Count();
            var totalPages   = (int)Math.Ceiling((float)totalRecords / (float)rows);

            if (!string.IsNullOrEmpty(sidx) && !string.IsNullOrEmpty(sord))
            {
                if (sord.Trim().ToLower() == "asc")
                {
                    records = SortHelper.OrderBy(records, sidx);
                }
                else
                {
                    records = SortHelper.OrderByDescending(records, sidx);
                }
            }

            if (!string.IsNullOrEmpty(colName) && !string.IsNullOrEmpty(colValue))
            {
                records = records.Where(c => c.GetType().GetProperty(colName).GetValue(c, null).ToString().ToLower().Contains(colValue.ToLower()));
            }
            //applying filter

            // int totalRecords = records.Count();
            //  var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);


            //applying paging
            records = records.Skip(pageIndex * pageSize).Take(pageSize);

            var jsonData = new
            {
                total = totalPages,
                page,
                records = totalRecords,
                rows    = records
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }
예제 #15
0
        public List <ApplicationUser> GetNotAllocatedStudentsJsonData(int?page, int?limit, string sortBy, string direction, out int total)
        {
            var approvedStudents = _context.ProjectStudents
                                   .Include(p => p.ApplicationUser)
                                   .Select(p => new ApplicationUser()
            {
                FirstName   = p.ApplicationUser.FirstName,
                LastName    = p.ApplicationUser.LastName,
                Email       = p.ApplicationUser.Email,
                PhoneNumber = p.ApplicationUser.PhoneNumber,
                UserName    = p.ApplicationUser.UserName
            });

            //var notApprovedStudents1 = _context.ProjectStudentChoices
            //   .Include(p => p.Project)
            //   .Include(p => p.ApplicationUser)
            //   .Where(p => p.IsApproved && p.Project.IsClosed)
            //   .Select(p => new ApplicationUser()
            //   {

            //       FirstName = p.ApplicationUser.FirstName,
            //       LastName = p.ApplicationUser.LastName,
            //       Email = p.ApplicationUser.Email,
            //       PhoneNumber = p.ApplicationUser.PhoneNumber,
            //       UserName = p.ApplicationUser.UserName
            //   });

            var notApprovedStudents = _context.ApplicationUsers
                                      .Where(p => !_context.ProjectStudentChoices.Where(a => a.IsApproved && a.Project.IsClosed).Select(c => c.ApplicationUserId).Contains(p.Id) &&
                                             _context.UserRoles.Where(c => c.RoleId == "1f8cd529-9587-48a9-8efe-f9a1ec3b6268").Select(c => c.UserId).Contains(p.Id)).Select(p => new ApplicationUser()
            {
                FirstName   = p.FirstName,
                LastName    = p.LastName,
                Email       = p.Email,
                PhoneNumber = p.PhoneNumber,
                UserName    = p.UserName
            });

            var records = notApprovedStudents.Except(approvedStudents);

            total = records.Count();

            if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
            {
                if (direction.Trim().ToLower() == "asc")
                {
                    records = SortHelper.OrderBy(records, sortBy);
                }
                else
                {
                    records = SortHelper.OrderByDescending(records, sortBy);
                }
            }
            if (page.HasValue && limit.HasValue)
            {
                int start = (page.Value - 1) * limit.Value;
                records = records.Skip(start).Take(limit.Value);
            }

            return(records.ToList());
        }