Beispiel #1
0
        public JsonResult Data(UserLicenseFilterGridModel filter)
        {
            var dbModel = _userService.GetAll()
                          .Where(x => x.IsDemo == filter.Demo &&
                                 (string.IsNullOrEmpty(filter.Name) || x.Name.StartsWith(filter.Name, StringComparison.CurrentCultureIgnoreCase)) &&
                                 (string.IsNullOrEmpty(filter.Email) || x.Email.StartsWith(filter.Email, StringComparison.CurrentCultureIgnoreCase)) &&
                                 (string.IsNullOrEmpty(filter.Phone) || x.Phone.StartsWith(filter.Phone, StringComparison.CurrentCultureIgnoreCase)) &&
                                 (string.IsNullOrEmpty(filter.CompanyId) || x.CompanyId.StartsWith(filter.CompanyId, StringComparison.CurrentCultureIgnoreCase)) &&
                                 (!filter.Company.HasValue || x.IsCompany == filter.Company))
                          .ToList();

            if (!string.IsNullOrEmpty(filter.SortField))
            {
                bool asc = filter.SortOrder.ToLower() == "asc";
                switch (filter.SortField.ToLower())
                {
                case "name":
                    dbModel = asc
                            ? dbModel.OrderBy(x => x.Name).ToList()
                            : dbModel.OrderByDescending(x => x.Name).ToList();
                    break;
                }
            }

            var data = dbModel
                       .Skip((filter.PageIndex - 1) * filter.PageSize)
                       .Take(filter.PageSize)
                       .Select(x => new
            {
                Id        = x.Id,
                Name      = x.Name,
                Demo      = x.IsDemo,
                Email     = x.Email,
                Phone     = x.Phone,
                Company   = x.IsCompany,
                CompanyId = x.CompanyId,
                DetailUrl = string.Format("../UserLicense/Details/{0}", x.Id),
                EditUrl   = RolesManager.CanCreateLicense(User.Identity)
                        ? string.Format("../UserLicense/Edit/{0}", x.Id)
                        : string.Empty
            })
                       .ToList();

            var result = new {
                data       = data,
                itemsCount = dbModel.Count
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public JsonResult Data(LicenseFilterGridModel filter)
        {
            var dbModel = _licenseService.GetAll();

            if (filter.UserId.HasValue)
            {
                dbModel = dbModel.Where(x => x.User.Id == filter.UserId.Value)
                          .ToList();
            }

            dbModel = dbModel
                      .Where(x => (filter.Type == 0 || (int)x.Type == filter.Type) &&
                             (!filter.Demo.HasValue || x.IsDemo == filter.Demo.Value) &&
                             (!filter.Activated.HasValue || x.IsActivated == filter.Activated.Value) &&
                             (!filter.Enabled.HasValue || x.Enabled == filter.Enabled.Value) &&
                             (string.IsNullOrEmpty(filter.UserName) || x.User.Name.StartsWith(filter.UserName, StringComparison.CurrentCultureIgnoreCase)))
                      .ToList();

            if (!string.IsNullOrEmpty(filter.SortField))
            {
                #region Sort
                bool asc = filter.SortOrder.ToUpper() == "ASC";
                switch (filter.SortField.ToUpper())
                {
                case "ID":
                    dbModel = asc
                            ? dbModel.OrderBy(x => x.Id).ToList()
                            : dbModel.OrderByDescending(x => x.Id).ToList();
                    break;

                case "VALIDTO":
                    dbModel = asc
                            ? dbModel.OrderBy(x => x.ValidTo).ToList()
                            : dbModel.OrderByDescending(x => x.ValidTo).ToList();
                    break;

                case "DEMO":
                    dbModel = asc
                            ? dbModel.OrderBy(x => x.IsDemo).ToList()
                            : dbModel.OrderByDescending(x => x.IsDemo).ToList();
                    break;

                case "USERNAME":
                    dbModel = asc
                            ? dbModel.OrderBy(x => x.User.Name).ToList()
                            : dbModel.OrderByDescending(x => x.User.Name).ToList();
                    break;

                case "CREATED":
                    dbModel = asc
                            ? dbModel.OrderBy(x => x.Created).ToList()
                            : dbModel.OrderByDescending(x => x.Created).ToList();
                    break;

                case "ACTIVATED":
                    dbModel = asc
                            ? dbModel.OrderBy(x => x.IsActivated).ToList()
                            : dbModel.OrderByDescending(x => x.IsActivated).ToList();
                    break;

                case "ENABLED":
                    dbModel = asc
                            ? dbModel.OrderBy(x => x.Enabled).ToList()
                            : dbModel.OrderByDescending(x => x.Enabled).ToList();
                    break;

                case "TYPE":
                    dbModel = asc
                            ? dbModel.OrderBy(x => x.Type).ToList()
                            : dbModel.OrderByDescending(x => x.Type).ToList();
                    break;
                }
                #endregion
            }

            var data = dbModel
                       .Skip((filter.PageIndex - 1) * filter.PageSize)
                       .Take(filter.PageSize)
                       .Select(x => new
            {
                Id        = string.Format("{0}...", x.Id.ToString().Substring(0, 20)),
                ValidTo   = x.ValidTo.ToShortDateString(),
                Demo      = x.IsDemo,
                UserName  = x.User.Name,
                Created   = x.Created.ToShortDateString(),
                Activated = x.IsActivated,
                Enabled   = x.Enabled,
                Type      = (int)x.Type,
                EditUrl   = RolesManager.CanCreateLicense(User.Identity)
                        ? string.Format("/License/Edit/{0}", x.Id)
                        : string.Empty,
                DetailUrl = string.Format("/License/Details/{0}", x.Id)
            }).ToArray();

            var dataResult = new {
                data       = data,
                itemsCount = dbModel.Count
            };

            return(Json(dataResult, JsonRequestBehavior.AllowGet));
        }