public ActionResult GetApostadores(JqGridRequest request)
        {
            //int equipoId = ViewBag.ApuestaId;
            int totalRecords = 0;
            List<Apostador> apuestas = repository.dal_apostador.GetApostadores(); ;
            totalRecords = apuestas.Count();

            //Prepare JqGridData instance
            JqGridResponse response = new JqGridResponse()
            {
                //Total pages count
                TotalPagesCount = (int)Math.Ceiling((float)totalRecords / (float)request.RecordsCount),
                //Page number
                PageIndex = request.PageIndex,
                //Total records count
                TotalRecordsCount = totalRecords
            };

            foreach (Apostador apuesta in apuestas)
            {
                response.Records.Add(new JqGridRecord(Convert.ToString(apuesta.ApostadorId), new List<object>()
                {
                   apuesta.ApostadorId,
                   apuesta.Nombre,
                   apuesta.Correo,
                   apuesta.Puntaje
                }));
            }

            //Return data as json
            return new JqGridJsonResult() { Data = response };
        }
Example #2
0
        public static string GetFilterExpression(JqGridRequest request, string ignoreString)
        {
            string result = string.Empty;

            if (request.SearchingFilter != null)
                return GetFilter(request.SearchingFilter.SearchingName, request.SearchingFilter.SearchingOperator, request.SearchingFilter.SearchingValue.Equals(ignoreString) ? "" : request.SearchingFilter.SearchingValue);
            else if (request.SearchingFilters != null)
            {
                StringBuilder filterExpressionBuilder = new StringBuilder();
                string groupingOperatorToString = request.SearchingFilters.GroupingOperator.ToString();

                foreach (JqGridRequestSearchingFilter element in request.SearchingFilters.Filters)
                {
                    filterExpressionBuilder.Append(GetFilter(element.SearchingName, element.SearchingOperator, element.SearchingValue.Equals(ignoreString) ? "" : element.SearchingValue));
                    filterExpressionBuilder.Append(String.Format(" {0} ", groupingOperatorToString));
                }

                if (filterExpressionBuilder.Length > 0)
                    filterExpressionBuilder.Remove(filterExpressionBuilder.Length - groupingOperatorToString.Length - 2, groupingOperatorToString.Length + 2);

                result = filterExpressionBuilder.ToString();
            }

            return result;
        }
        public JqGridData FetchGroupsPersonIsNotInJQGrid(Person currentPerson, int personId, JqGridRequest request)
        {
            var groups = _personGroupRepository.GetPersonGroupViewModels(personId, currentPerson);
            var groupsPersonIsNotIn = groups.Where(g => g.IsInGroup==false);

            return CreateGridFromData(request, groupsPersonIsNotIn);
        }
Example #4
0
        public ActionResult Search(JqGridRequest request, String marketSearchBoxString)
        {
            int totalRecordsCount = CoinManager.GetCount(new MarketSearchBoxModel(marketSearchBoxString));

            JqGridResponse response = new JqGridResponse()
            {
                TotalPagesCount = (int)Math.Ceiling((float)totalRecordsCount / (float)request.RecordsCount),
                PageIndex = request.PageIndex,
                TotalRecordsCount = totalRecordsCount
            };

            IList<CoinViewModel> coins = new List<CoinViewModel>();
            foreach (var coin in CoinManager.GetCoinsByMarketSearch(
                new MarketSearchBoxModel(marketSearchBoxString),
                String.Format("{0} {1}", request.SortingName, request.SortingOrder), request.PageIndex))
            {
                response.Records.Add(new JqGridRecord<CoinViewModel>(
                    Convert.ToString(coin.Id),
                    new CoinViewModel(coin)
                ));
            }

            ViewBag.MarketSearchBoxString = marketSearchBoxString;
            return new JqGridJsonResult() { Data = response };
        }
        public ActionResult NameSpaces(JqGridRequest request)
        {
            using (var db = new ContentRepository())
            {
                var nameSpaceQry = from n in db.NameSpaces orderby n.Id select n;

                var totalRecs = db.NameSpaces.Count();
                var response = new JqGridResponse()
                                   {
                                       TotalPagesCount =
                                           (int) Math.Ceiling((float) totalRecs/(float) request.RecordsCount),
                                       PageIndex = request.PageIndex,
                                       TotalRecordsCount = totalRecs
                                   };

                var nameSpaces = nameSpaceQry
                    .Skip(request.PageIndex*request.RecordsCount)
                    .Take((request.PagesCount.HasValue ? request.PagesCount.Value : 1)*request.RecordsCount).ToList();

                var jqGridRecords = from n in nameSpaces
                        select new JqGridRecord<NameSpaceGridModel>(
                            n.Id.ToString(),
                            new NameSpaceGridModel(n));

                response.Records.AddRange(jqGridRecords);

                return new JqGridJsonResult() { Data = response };
            }
        }
Example #6
0
        public JqGridJsonResult GetUsersGridModel(JqGridRequest request)
        {
            var enumerable = this.Manager.FindAll(new UserAll(true));

            var users = new List<UserEntity>(enumerable);

            var totalRecordsCount = users.Count();

            var list = (from u in users
                        select
                            new JqGridRecord<UserGridModel>(
                                u.Id.ToString(CultureInfo.InvariantCulture), 
                                new UserGridModel
                                {
                                    Id = u.Id,
                                    Name = u.Name,
                                    Email = u.Email,
                                    Login = u.UserPasswordCredential != null ? u.UserPasswordCredential.Login : string.Empty,
                                })).ToList();

            var response = new JqGridResponse
                {
                    TotalPagesCount = (int)Math.Ceiling(totalRecordsCount / (float)request.RecordsCount),
                    PageIndex = request.PageIndex,
                    TotalRecordsCount = totalRecordsCount,
                };

            response.Records.AddRange(list);

            return new JqGridJsonResult { Data = response };
        }
        public JqGridData FetchListOfChildren(Person currentPerson, JqGridRequest request, string[] selectedRoles)
        {
            IEnumerable<ChildReportDto> listOfChildren = new List<ChildReportDto>();
            try
            {
                listOfChildren = _childrenReportsRepository.GetListOfChildrenForAChurch(currentPerson, ConversionService.ConvertSelectedRolesToListOfInts(selectedRoles));
            }
            catch (Exception ex)
            {
                _emailService.SendExceptionEmail(ex);
            }

            var totalRecords = listOfChildren.Count();

            switch (request.sidx)
            {
                case "Age":
                    {
                        listOfChildren = request.sord.ToLower() == "asc" ? listOfChildren.OrderBy(p => p.Age).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfChildren.OrderByDescending(p => p.Age).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                case "Surname":
                    {
                        listOfChildren = request.sord.ToLower() == "asc" ? listOfChildren.OrderBy(p => p.Surname).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfChildren.OrderByDescending(p => p.Surname).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                case "Firstname":
                    {
                        listOfChildren = request.sord.ToLower() == "asc" ? listOfChildren.OrderBy(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfChildren.OrderByDescending(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
            }

            var childrenGridData = new JqGridData()
            {
                total = (int) Math.Ceiling((float) totalRecords/request.rows),
                page = request.page,
                records = totalRecords,
                rows = (from p in listOfChildren.AsEnumerable()
                    select new JqGridRow()
                    {
                        id = p.PersonId.ToString(),
                        cell = new[]
                        {
                            p.PersonId.ToString(),
                            p.Age.ToString(),
                            p.Firstname,
                            p.Surname,
                            p.CellNo,
                            p.GroupName,
                            p.Father,
                            p.Mother

                        }
                    }).ToArray()
            };

            return childrenGridData;
        }
        public static JqGridData FetchPermissionsForRoleJQGrid(Person currentPerson, JqGridRequest request, int roleId)
        {
            using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var permissions = (from p in context.Permissions
                              join pr in context.PermissionRoles
                              on p.PermissionId equals pr.PermissionId
                              join r in context.Roles
                              on pr.RoleId equals r.RoleId
                              where r.ChurchId == currentPerson.ChurchId
                                && (pr.RoleId == roleId)
                              select p);

                if (!currentPerson.HasPermission(Permissions.SystemAdministrator))
                {
                    permissions = permissions.Where(p => p.IsVisible == true);
                }

                int totalRecords = permissions.Count();

                switch (request.sidx)
                {
                    case "Permission":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                permissions = permissions.OrderBy(p => p.Name).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                permissions = permissions.OrderByDescending(p => p.Name).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                }

                JqGridData peopleGridData = new JqGridData()
                {
                    total = (int)Math.Ceiling((float)totalRecords / (float)request.rows),
                    page = request.page,
                    records = totalRecords,
                    rows = (from p in permissions.AsEnumerable()
                            select new JqGridRow()
                            {
                                id = p.PermissionId.ToString(),
                                cell = new string[]
                                {
                                    p.PermissionId.ToString(),
                                    p.Name
                                }
                            }).ToArray()
                };

                return peopleGridData;
            }
        }
Example #9
0
 public JqGridResponse GetJqGridResponse(int totalRecordsCount, JqGridRequest request)
 {
     return new JqGridResponse
     {
         TotalPagesCount = (int)Math.Ceiling((float)totalRecordsCount / (float)request.RecordsCount),
         PageIndex = request.PageIndex,
         TotalRecordsCount = totalRecordsCount,
         UserData = new { sortexp = request.SortingName, sortdir = request.SortingOrder.ToString().ToLower() }
     };
 }
 public ActionResult GetTypeMembers(JqGridRequest request, string keyword)
 {
   var searchCriteria = new TypeMemberSearchCriteria();
   var result = _typeMemberReportService.Search(searchCriteria, request.RecordsCount, request.PageIndex);
   var jsonData = new
   {
     total = (result.Count + request.RecordsCount - 1) / request.RecordsCount,
     page = request.PageIndex + 1,
     records = result.Count,
     rows = result.Items
   };
   return Json(jsonData, JsonRequestBehavior.AllowGet);
 }
        private JqGridJsonResult GetJqGridJsonResult(JqGridRequest request, IEnumerable<Concurenta> records)
        {
            int totalRecordsCount = records.Count();

            var result = GetJqGridResponse(totalRecordsCount, request);

            records = records.Skip((request.PageIndex) * request.RecordsCount).Take(request.RecordsCount).ToList();

            foreach (var item in records)
            {
                result.Records.Add(item.ToJqGridRecord());
            }

            return new JqGridJsonResult { Data = result };
        }
        public JqGridData FetchPeopleToBeRemindedJQGrid(Person currentPerson, string reminderType, JqGridRequest request)
        {
            var people = _reminderRepository.FetchPeopleToBeReminded(currentPerson.ChurchId, reminderType);
            var totalRecords = people.Count();
            var sort = "Surname";
            var sortList = request.sidx.Split(',');
            if (sortList.Count() > 1)
                sort = sortList[1].Trim();
            switch (sort)
            {
                case "Firstname":
                    {
                        people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Firstname) : people.OrderByDescending(p => p.Firstname);
                        break;
                    }
                case "Surname":
                    {
                        people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Surname) : people.OrderByDescending(p => p.Surname);
                        break;
                    }
            }

            if (request.rows > 0)
                people = people.Skip((request.page - 1) * request.rows).Take(request.rows);
            else
                request.page = 1;

            var peopleGridData = new JqGridData()
            {
                total = request.rows > 0 ? (int) Math.Ceiling((float) totalRecords/(float) request.rows) : 1,
                page = request.page,
                records = totalRecords,
                rows = (from p in people.AsEnumerable()
                    select new JqGridRow()
                    {
                        id = p.PersonId.ToString(),
                        cell = new[]
                        {
                            p.PersonId.ToString(),
                            p.Firstname,
                            p.Surname,
                            p.Email
                        }
                    }).ToArray()
            };

            return peopleGridData;
        }
Example #13
0
        public ActionResult Employees(JqGridRequest request)
        {
            using (var proxy = new TimeCardServiceClient())
            {
                var employees = proxy.SearchEmployees(null, null, null, false);

                var response = new JqGridResponse();

                response.Records.AddRange(employees.Select(e => new JqGridRecord<EmployeeModel>(Convert.ToString(e.Id), e.ToModel())));

                return new JqGridJsonResult
                           {
                               Data = response
                           };
            }
        }
        private static JqGridData CreateGridFromData(JqGridRequest request, IEnumerable<PersonGroupViewModel> groupsPersonIsIn)
        {
            var totalRecords = groupsPersonIsIn.Count();

            switch (request.sidx)
            {
                case "Name":
                case "GroupName":
                    {
                        if (request.sord.ToLower() == "asc")
                        {
                            groupsPersonIsIn = groupsPersonIsIn.OrderBy(g => g.GroupName)
                                                               .Skip((request.page - 1)*request.rows)
                                                               .Take(request.rows)
                                                               .ToList();
                        }
                        else
                        {
                            groupsPersonIsIn = groupsPersonIsIn
                                .OrderByDescending(g => g.GroupName)
                                .Skip((request.page - 1)*request.rows)
                                .Take(request.rows)
                                .ToList();
                        }
                        break;
                    }
            }

            var groupsGridData = new JqGridData()
                {
                    total = (int) Math.Ceiling((float) totalRecords/(float) request.rows),
                    page = request.page,
                    records = totalRecords,
                    rows = (from g in groupsPersonIsIn
                            select new JqGridRow()
                                {
                                    id = g.GroupId.ToString(),
                                    cell = new string[]
                                        {
                                            g.GroupId.ToString(),
                                            g.GroupName,
                                            g.IsPrimaryGroup.ToString()
                                        }
                                }).ToArray()
                };
            return groupsGridData;
        }
        public JqGridData FormatCommentsForGrid(IEnumerable<CommentDto> comments, JqGridRequest request)
        {
            var totalRecords = comments.Count();

            switch (request.sidx)
            {
                case "Date":
                    {
                        comments = request.sord.ToLower() == "asc" ? comments.OrderBy(e => e.CommentDate).Skip((request.page - 1) * request.rows).Take(request.rows) : comments.OrderByDescending(e => e.CommentDate).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                case "Comment":
                    {
                        comments = request.sord.ToLower() == "asc" ? comments.OrderBy(e => e.Comment).Skip((request.page - 1) * request.rows).Take(request.rows) : comments.OrderByDescending(e => e.Comment).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                case "CreatedBy":
                    {
                        comments = request.sord.ToLower() == "asc" ? comments.OrderBy(e => e.CreatedByPerson).Skip((request.page - 1) * request.rows).Take(request.rows) : comments.OrderByDescending(e => e.CreatedByPerson).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
            }

            var commentsForGrid = new JqGridData()
            {
                total = (int)Math.Ceiling((float)totalRecords / request.rows),
                page = request.page,
                records = totalRecords,
                rows = (from e in comments
                        select new JqGridRow()
                        {
                            id = e.CommentId.ToString(),
                            cell = new[] {
                                e.CommentId.ToString(),
                                e.CommentDate.ToString("dd MMM yyyy"),
                                e.Comment,
                                e.CreatedByPerson
                                }
                        }).ToArray()
            };
            return commentsForGrid;
        }
        public void CanSortCommentsCorrectly()
        {
            IGridFormatter gridFormatter = new GridFormatter();

            var request = new JqGridRequest
            {
                sidx = "Comment",
                rows = 2,
                page = 1,
                sord = "desc"
            };

            var comments = new List<CommentDto>
                {new CommentDto {Comment = "Comment1", CommentDate = new DateTime(2012, 1, 1)},
                 new CommentDto {Comment = "Comment2", CommentDate = new DateTime(2012, 2, 1)},
                 new CommentDto {Comment = "Comment3", CommentDate = new DateTime(2012, 3, 1)},
                 new CommentDto {Comment = "Comment4", CommentDate = new DateTime(2012, 4, 1)}
                };

            var result = gridFormatter.FormatCommentsForGrid(comments, request);

            Assert.That(result.rows[0].cell[1], Is.EqualTo("01 Apr 2012"));
        }
        public void CanFormatCommentsCorrectly()
        {
            IGridFormatter gridFormatter = new GridFormatter();

            var request = new JqGridRequest
                              {
                                  sidx = "Date",
                                  rows = 2,
                                  page = 1,
                                  sord = "asc"
                              };

            var comments = new List<CommentDto>
                {new CommentDto {Comment = "Comment1", CommentDate = new DateTime(2012, 1, 1)},
                 new CommentDto {Comment = "Comment2", CommentDate = new DateTime(2012, 2, 1)},
                 new CommentDto {Comment = "Comment3", CommentDate = new DateTime(2012, 3, 1)},
                 new CommentDto {Comment = "Comment4", CommentDate = new DateTime(2012, 4, 1)}
                };

            var result = gridFormatter.FormatCommentsForGrid(comments, request);

            Assert.That(result.rows.Length, Is.EqualTo(2));
            Assert.That(result.records, Is.EqualTo(4));
        }
Example #18
0
        public JqGridData FetchAnniversaryList(Person currentPerson, JqGridRequest request, int monthId, string[] selectedRoles)
        {
            IEnumerable<PersonViewModel> listOfAnniversaries = new List<PersonViewModel>();
            try
            {
                listOfAnniversaries = _birthdayAndAnniversaryRepository.GetAnniversaryListForAMonth(monthId, selectedRoles, currentPerson.ChurchId);
            }
            catch (Exception ex)
            {
                _emailService.SendExceptionEmail(ex);
            }

            var totalRecords = listOfAnniversaries.Count();

            switch (request.sidx)
            {
                case "Firstname":
                    {
                        listOfAnniversaries = request.sord.ToLower() == "asc" ? listOfAnniversaries.OrderBy(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfAnniversaries.OrderByDescending(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                case "Surname":
                    {
                        listOfAnniversaries = request.sord.ToLower() == "asc" ? listOfAnniversaries.OrderBy(p => p.Surname).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfAnniversaries.OrderByDescending(p => p.Surname).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                case "Day":
                    {
                        listOfAnniversaries = request.sord.ToLower() == "asc" ? listOfAnniversaries.OrderBy(p => p.Anniversary_Value.Value.Day).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfAnniversaries.OrderByDescending(p => p.Anniversary_Value.Value.Day).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                case "MemberStatus":
                    {
                        listOfAnniversaries = request.sord.ToLower() == "asc" ? listOfAnniversaries.OrderBy(p => p.RoleName).ThenBy(p => p.Anniversary_Value.Value.Day).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfAnniversaries.OrderByDescending(p => p.RoleName).ThenBy(p => p.Anniversary_Value.Value.Day).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                case "Email":
                    {
                        listOfAnniversaries = request.sord.ToLower() == "asc" ? listOfAnniversaries.OrderBy(p => p.Email).Skip((request.page - 1) * request.rows).Take(request.rows) : listOfAnniversaries.OrderByDescending(p => p.Email).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
            }

            var peopleGridData = new JqGridData()
            {
                total = (int)Math.Ceiling((float)totalRecords / request.rows),
                page = request.page,
                records = totalRecords,
                rows = (from p in listOfAnniversaries.AsEnumerable()
                        select new JqGridRow()
                        {
                            id = p.PersonId.ToString(),
                            cell = new string[] {
                                                        p.PersonId.ToString(),
                                                        p.Anniversary_Value.Value.Day.ToString(CultureInfo.InvariantCulture),
                                                        p.Firstname,
                                                        p.Surname,
                                                        p.RoleName,
                                                        p.HomePhone,
                                                        p.CellPhone,
                                                        p.Email
                                    }
                        }).ToArray()
            };

            return peopleGridData;
        }
        public static JqGridData FetchPeopleNotInAHomeGroupJQGrid(Person currentPerson, JqGridRequest request)
        {
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var includedRoles = context
                                    .PermissionRoles
                                    .Where(pr => pr.PermissionId == (int)Permissions.IncludeInNotInGroupList)
                                    .Select(pr => pr.RoleId)
                                    .ToList();

                var peopleNotInGroups = (from p in context.People
                                         join c in context.PersonChurches
                                           on p.PersonId equals c.PersonId
                                         join pg in context.PersonGroups
                                           on p.PersonId equals pg.PersonId into tList
                                         from pgEmpty in tList.DefaultIfEmpty()
                                         where pgEmpty.GroupId == null
                                         && c.ChurchId == currentPerson.ChurchId
                                         && includedRoles.Contains(c.RoleId)
                                         select p);

                var totalRecords = peopleNotInGroups.Count();

                switch (request.sidx)
                {
                    case "Firstname":
                    {
                        peopleNotInGroups = request.sord.ToLower() == "asc" ? peopleNotInGroups.OrderBy(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows) : peopleNotInGroups.OrderByDescending(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                    case "Surname":
                    {
                        peopleNotInGroups = request.sord.ToLower() == "asc" ? peopleNotInGroups.OrderBy(p => p.Family.FamilyName).Skip((request.page - 1) * request.rows).Take(request.rows) : peopleNotInGroups.OrderByDescending(p => p.Family.FamilyName).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                    case "Site":
                    {
                        peopleNotInGroups = request.sord.ToLower() == "asc" ? peopleNotInGroups.OrderBy(p => p.Site.Name).Skip((request.page - 1) * request.rows).Take(request.rows) : peopleNotInGroups.OrderByDescending(p => p.Site.Name).Skip((request.page - 1) * request.rows).Take(request.rows);
                        break;
                    }
                }

                var sitesGridData = new JqGridData()
                {
                    total = (int)Math.Ceiling((float)totalRecords / (float)request.rows),
                    page = request.page,
                    records = totalRecords,
                    rows = (from p in peopleNotInGroups.AsEnumerable()
                            select new JqGridRow()
                            {
                                id = p.PersonId.ToString(),
                                cell = new string[] {
                                                    p.PersonId.ToString(CultureInfo.InvariantCulture),
                                                    p.Firstname,
                                                    p.Family.FamilyName,
                                                    p.Family.HomePhone,
                                                    p.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)OptionalFields.CellPhone)==null?"":p.PersonOptionalFields.Where<PersonOptionalField>(c => c.OptionalFieldId == (int)OptionalFields.CellPhone).FirstOrDefault().Value,
                                                    p.Email,
                                                    p.Site==null?string.Empty:p.Site.Name
                                }
                            }).ToArray()
                };
                return sitesGridData;
            }
        }
        public static JqGridData FetchPeopleInGroupJQGrid(Person currentPerson, JqGridRequest request, int groupId)
        {
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var people = FetchPeopleInGroup(currentPerson, groupId, context);

                if (request._search)
                {
                    foreach (var rule in request.filters.rules)
                    {
                        var ruleData = rule.data.ToLower();
                        //If we use rule.data throughout we get some strange errors in the SQL that Linq generates
                        switch (rule.field)
                        {
                            case "Firstname":
                                {
                                    people = (from p in people
                                              where p.Firstname.ToLower().Contains(ruleData)
                                              select p);
                                    break;
                                }
                            case "Surname":
                                {
                                    people = (from p in people
                                              where p.Surname.ToLower().Contains(ruleData)
                                              select p);
                                    break;
                                }
                        }
                    }
                }

                var totalRecords = people.Count();
                var sort = "Surname";
                var sortList = request.sidx.Split(',');
                if (sortList.Count() > 1)
                    sort = sortList[1].Trim();
                switch (sort)
                {
                    case "Firstname":
                    {
                        people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.RoleName).ThenBy(p => p.Firstname) : people.OrderBy(p => p.RoleName).ThenByDescending(p => p.Firstname);
                        break;
                    }
                    case "Surname":
                    {
                        people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.RoleName).ThenBy(p => p.Surname) : people.OrderBy(p => p.RoleName).ThenByDescending(p => p.Surname);
                        break;
                    }
                }

                if (request.rows > 0)
                    people = people.Skip((request.page - 1)*request.rows).Take(request.rows);
                else
                    request.page = 1;

                var peopleGridData = new JqGridData()
                {
                    total = request.rows>0 ? (int)Math.Ceiling((float)totalRecords / (float)request.rows) : 1,
                    page = request.page,
                    records = totalRecords,
                    rows = (from p in people.AsEnumerable()
                            select new JqGridRow()
                            {
                                id = p.PersonId.ToString(),
                                cell = new string[] {
                                                        p.PersonId.ToString(),
                                                        p.Firstname,
                                                        p.Surname,
                                                        p.HomePhone,
                                                        p.CellPhone,
                                                        p.Email,
                                                        p.RoleName
                                    }
                            }).ToArray()
                };

                return peopleGridData;
            }
        }
        public static JqGridData FetchHomeGroupsJQGrid(Person currentPerson, JqGridRequest request, int? selectedGroupId, bool? useGroupId)
        {
            if (!(currentPerson.HasPermission(Permissions.EditOwnGroups) || currentPerson.HasPermission(Permissions.EditAllGroups)))
            {
                throw new Exception("Invalid security Role");
            }

            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var rules = request.filters == null ? null : request.filters.rules;
                var groups = FetchGroupList(currentPerson, request._search, rules, context);

                var sortedGroups = sortGroupList(request, groups).ToList();

                if (useGroupId.HasValue && useGroupId.Value)
                {
                    if (selectedGroupId.HasValue && selectedGroupId.Value == 0)
                        request.page = 1;
                    else if(selectedGroupId.HasValue)
                    {
                        var result = sortedGroups
                            .Select((x, i) => new {Item = x, Index = i})
                            .FirstOrDefault(itemWithIndex => itemWithIndex.Item.GroupId == selectedGroupId);

                        request.page = 1;
                        if (result != null)
                            request.page = ((result.Index + request.rows)/request.rows);

                    }
                }

                var totalRecords = sortedGroups.Count();
                var filteredGroups = sortedGroups.Skip((request.page - 1) * request.rows).Take(request.rows).ToList();

                var sitesGridData = new JqGridData()
                {
                    total = (int)Math.Ceiling((float)totalRecords / (float)request.rows),
                    page = request.page,
                    records = totalRecords,
                    rows = (from g in filteredGroups.AsEnumerable()
                            select new JqGridRow()
                            {
                                id = g.GroupId.ToString(),
                                cell = new string[] {
                                                    g.GroupId.ToString(),
                                                    g.Name,
                                                    g.Leader==null? string.Empty : g.Leader.Firstname + " " + g.Leader.Family.FamilyName,
                                                    g.Administrator==null? string.Empty : g.Administrator.Firstname + " " + g.Administrator.Family.FamilyName,
                                                    g.Address==null? string.Empty : g.Address.ChurchSuburb==null?g.Address.Line3:g.Address.ChurchSuburb.Suburb,
                                                    g.GroupClassification==null? string.Empty :g.GroupClassification.Name,
                                                    g.PersonLinkedToGroups.FirstOrDefault(p => p.Description == CacheNames.OverseeingElder)==null? string.Empty : g.PersonLinkedToGroups.First(p => p.Description == CacheNames.OverseeingElder).Person.Firstname + " " + g.PersonLinkedToGroups.First(p => p.Description == CacheNames.OverseeingElder).Person.Family.FamilyName
                                }
                            }).ToArray()
                };

                return sitesGridData;
            }
        }
 private static IEnumerable<Group> sortGroupList(JqGridRequest request, IQueryable<Group> groups)
 {
     switch (request.sidx)
     {
         case "GroupName":
             {
                 return request.sord.ToLower() == "asc"
                              ? groups.OrderBy(g => g.Name)
                              : groups.OrderByDescending(g => g.Name);
             }
         case "LeaderName":
             {
                 return request.sord.ToLower() == "asc"
                              ? groups.OrderBy(g => g.Leader.Firstname)
                              : groups.OrderByDescending(g => g.Leader.Firstname);
             }
         case "Administrator":
             {
                 return request.sord.ToLower() == "asc"
                              ? groups.OrderBy(g => g.Administrator.Firstname)
                              : groups.OrderByDescending(g => g.Administrator.Firstname);
             }
         case "Suburb":
             {
                 return request.sord.ToLower() == "asc"
                              ? groups.OrderBy(g => g.Address.ChurchSuburb.Suburb).ThenBy(g => g.Address.Line3)
                              : groups.OrderByDescending(g => g.Address.ChurchSuburb.Suburb)
                                      .ThenByDescending(g => g.Address.Line3);
             }
         case "GroupClassification":
             {
                 return request.sord.ToLower() == "asc"
                              ? groups.OrderBy(g => g.GroupClassification.Name)
                              : groups.OrderByDescending(g => g.GroupClassification.Name);
             }
         case "OverseeingElder":
             {
                 return request.sord.ToLower() == "asc"
                              ? groups.OrderBy(g => g.PersonLinkedToGroups.FirstOrDefault(p => p.Description == CacheNames.OverseeingElder).Person.Firstname).ThenBy(g => g.PersonLinkedToGroups.FirstOrDefault(p => p.Description == CacheNames.OverseeingElder).Person.Family.FamilyName)
                              : groups.OrderByDescending(g => g.PersonLinkedToGroups.FirstOrDefault(p => p.Description == CacheNames.OverseeingElder).Person.Firstname).ThenByDescending(g => g.PersonLinkedToGroups.FirstOrDefault(p => p.Description == CacheNames.OverseeingElder).Person.Family.FamilyName);
             }
     }
     throw new Exception("Invalid sort parameter");
 }
        public static JqGridData FetchGroupAttendanceJQGrid(Person currentPerson, JqGridRequest request)
        {
            using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                JqGridData attendanceGridData = new JqGridData();

                ObjectResult<FetchGroupAttendance_Result> results = context.FetchGroupAttendance(currentPerson.ChurchId);
                var toSort = results.AsEnumerable();

                switch (request.sidx)
                {
                    case "Name":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.Name).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.Name).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "Jan":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.C1).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.C1).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "Feb":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.C2).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.C2).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "Mar":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.C3).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.C3).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "Apr":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.C4).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.C4).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "May":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.C5).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.C5).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "Jun":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.C6).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.C6).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "Jul":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.C7).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.C7).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "Aug":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.C8).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.C8).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "Sep":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.C9).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.C9).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "Oct":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.C10).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.C10).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "Nov":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.C11).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.C11).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "Dec":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                toSort = toSort.OrderBy(g => g.C12).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                toSort = toSort.OrderByDescending(g => g.C12).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                }

                int currentMonth = DateTime.Now.Month;
                int totalRecords = (from g in context.Groups
                                    where g.ChurchId == currentPerson.ChurchId
                                    select g).Count();

                JqGridData sitesGridData = new JqGridData()
                {
                    total = (int)Math.Ceiling((float)totalRecords / (float)request.rows),
                    page = request.page,
                    records = totalRecords,
                    rows = (from g in toSort
                            select new JqGridRow()
                            {
                                id = g.GroupId.ToString(),
                                cell = new string[] {
                                                    g.Name,
                                                    currentMonth==1 ? (g.C8.HasValue ? (g.C8.Value*100M).ToString("0") + "%" : "nc") : currentMonth==2 ? (g.C9.HasValue ? (g.C9.Value*100M).ToString("0") + "%" : "nc") : currentMonth==3 ? (g.C10.HasValue ? (g.C10.Value*100M).ToString("0") + "%" : "nc") : currentMonth==4 ? (g.C11.HasValue ? (g.C11.Value*100M).ToString("0") + "%" : "nc") : currentMonth==5 ? (g.C12.HasValue ? (g.C12.Value*100M).ToString("0") + "%" : "nc") : currentMonth==6 ? (g.C1.HasValue ? (g.C1.Value*100M).ToString("0") + "%" : "nc") : currentMonth==7 ? (g.C2.HasValue ? (g.C2.Value*100M).ToString("0") + "%" : "nc") : currentMonth==8 ? (g.C3.HasValue ? (g.C3.Value*100M).ToString("0") + "%" : "nc") : currentMonth==9 ? (g.C4.HasValue ? (g.C4.Value*100M).ToString("0") + "%" : "nc") : currentMonth==10 ? (g.C5.HasValue ? (g.C5.Value*100M).ToString("0") + "%" : "nc") : currentMonth==11 ? (g.C6.HasValue ? (g.C6.Value*100M).ToString("0") + "%" : "nc") : currentMonth==12 ? (g.C7.HasValue ? (g.C7.Value*100M).ToString("0") + "%" : "nc") : "0",
                                                    currentMonth==1 ? (g.C9.HasValue ? (g.C9.Value*100M).ToString("0") + "%" : "nc") : currentMonth==2 ? (g.C10.HasValue ? (g.C10.Value*100M).ToString("0") + "%" : "nc") : currentMonth==3 ? (g.C11.HasValue ? (g.C11.Value*100M).ToString("0") + "%" : "nc") : currentMonth==4 ? (g.C12.HasValue ? (g.C12.Value*100M).ToString("0") + "%" : "nc") : currentMonth==5 ? (g.C1.HasValue ? (g.C1.Value*100M).ToString("0") + "%" : "nc") : currentMonth==6 ? (g.C2.HasValue ? (g.C2.Value*100M).ToString("0") + "%" : "nc") : currentMonth==7 ? (g.C3.HasValue ? (g.C3.Value*100M).ToString("0") + "%" : "nc") : currentMonth==8 ? (g.C4.HasValue ? (g.C4.Value*100M).ToString("0") + "%" : "nc") : currentMonth==9 ? (g.C5.HasValue ? (g.C5.Value*100M).ToString("0") + "%" : "nc") : currentMonth==10 ? (g.C6.HasValue ? (g.C6.Value*100M).ToString("0") + "%" : "nc") : currentMonth==11 ? (g.C7.HasValue ? (g.C7.Value*100M).ToString("0") + "%" : "nc") : currentMonth==12 ? (g.C8.HasValue ? (g.C8.Value*100M).ToString("0") + "%" : "nc") : "0",
                                                    currentMonth==1 ? (g.C10.HasValue ? (g.C10.Value*100M).ToString("0") + "%" : "nc") : currentMonth==2 ? (g.C11.HasValue ? (g.C11.Value*100M).ToString("0") + "%" : "nc") : currentMonth==3 ? (g.C12.HasValue ? (g.C12.Value*100M).ToString("0") + "%" : "nc") : currentMonth==4 ? (g.C1.HasValue ? (g.C1.Value*100M).ToString("0") + "%" : "nc") : currentMonth==5 ? (g.C2.HasValue ? (g.C2.Value*100M).ToString("0") + "%" : "nc") : currentMonth==6 ? (g.C3.HasValue ? (g.C2.Value*100M).ToString("0") + "%" : "nc") : currentMonth==7 ? (g.C4.HasValue ? (g.C4.Value*100M).ToString("0") + "%" : "nc") : currentMonth==8 ? (g.C5.HasValue ? (g.C5.Value*100M).ToString("0") + "%" : "nc") : currentMonth==9 ? (g.C6.HasValue ? (g.C6.Value*100M).ToString("0") + "%" : "nc") : currentMonth==10 ? (g.C7.HasValue ? (g.C7.Value*100M).ToString("0") + "%" : "nc") : currentMonth==11 ? (g.C8.HasValue ? (g.C8.Value*100M).ToString("0") + "%" : "nc") : currentMonth==12 ? (g.C9.HasValue ? (g.C9.Value*100M).ToString("0") + "%" : "nc") : "0",
                                                    currentMonth==1 ? (g.C11.HasValue ? (g.C11.Value*100M).ToString("0") + "%" : "nc") : currentMonth==2 ? (g.C12.HasValue ? (g.C12.Value*100M).ToString("0") + "%" : "nc") : currentMonth==3 ? (g.C1.HasValue ? (g.C1.Value*100M).ToString("0") + "%" : "nc") : currentMonth==4 ? (g.C2.HasValue ? (g.C2.Value*100M).ToString("0") + "%" : "nc") : currentMonth==5 ? (g.C3.HasValue ? (g.C3.Value*100M).ToString("0") + "%" : "nc") : currentMonth==6 ? (g.C4.HasValue ? (g.C2.Value*100M).ToString("0") + "%" : "nc") : currentMonth==7 ? (g.C5.HasValue ? (g.C5.Value*100M).ToString("0") + "%" : "nc") : currentMonth==8 ? (g.C6.HasValue ? (g.C6.Value*100M).ToString("0") + "%" : "nc") : currentMonth==9 ? (g.C7.HasValue ? (g.C7.Value*100M).ToString("0") + "%" : "nc") : currentMonth==10 ? (g.C8.HasValue ? (g.C8.Value*100M).ToString("0") + "%" : "nc") : currentMonth==11 ? (g.C9.HasValue ? (g.C9.Value*100M).ToString("0") + "%" : "nc") : currentMonth==12 ? (g.C10.HasValue ? (g.C10.Value*100M).ToString("0") + "%" : "nc") : "0",
                                                    currentMonth==1 ? (g.C12.HasValue ? (g.C12.Value*100M).ToString("0") + "%" : "nc") : currentMonth==2 ? (g.C1.HasValue ? (g.C1.Value*100M).ToString("0") + "%" : "nc") : currentMonth==3 ? (g.C2.HasValue ? (g.C2.Value*100M).ToString("0") + "%" : "nc") : currentMonth==4 ? (g.C3.HasValue ? (g.C3.Value*100M).ToString("0") + "%" : "nc") : currentMonth==5 ? (g.C4.HasValue ? (g.C4.Value*100M).ToString("0") + "%" : "nc") : currentMonth==6 ? (g.C5.HasValue ? (g.C2.Value*100M).ToString("0") + "%" : "nc") : currentMonth==7 ? (g.C6.HasValue ? (g.C6.Value*100M).ToString("0") + "%" : "nc") : currentMonth==8 ? (g.C7.HasValue ? (g.C7.Value*100M).ToString("0") + "%" : "nc") : currentMonth==9 ? (g.C8.HasValue ? (g.C8.Value*100M).ToString("0") + "%" : "nc") : currentMonth==10 ? (g.C9.HasValue ? (g.C9.Value*100M).ToString("0") + "%" : "nc") : currentMonth==11 ? (g.C10.HasValue ? (g.C10.Value*100M).ToString("0") + "%" : "nc") : currentMonth==12 ? (g.C11.HasValue ? (g.C11.Value*100M).ToString("0") + "%" : "nc") : "0",
                                                    currentMonth==1 ? (g.C1.HasValue ? (g.C1.Value*100M).ToString("0") + "%" : "nc") : currentMonth==2 ? (g.C2.HasValue ? (g.C2.Value*100M).ToString("0") + "%" : "nc") : currentMonth==3 ? (g.C3.HasValue ? (g.C3.Value*100M).ToString("0") + "%" : "nc") : currentMonth==4 ? (g.C4.HasValue ? (g.C4.Value*100M).ToString("0") + "%" : "nc") : currentMonth==5 ? (g.C5.HasValue ? (g.C5.Value*100M).ToString("0") + "%" : "nc") : currentMonth==6 ? (g.C6.HasValue ? (g.C2.Value*100M).ToString("0") + "%" : "nc") : currentMonth==7 ? (g.C7.HasValue ? (g.C7.Value*100M).ToString("0") + "%" : "nc") : currentMonth==8 ? (g.C8.HasValue ? (g.C8.Value*100M).ToString("0") + "%" : "nc") : currentMonth==9 ? (g.C9.HasValue ? (g.C9.Value*100M).ToString("0") + "%" : "nc") : currentMonth==10 ? (g.C10.HasValue ? (g.C10.Value*100M).ToString("0") + "%" : "nc") : currentMonth==11 ? (g.C11.HasValue ? (g.C11.Value*100M).ToString("0") + "%" : "nc") : currentMonth==12 ? (g.C12.HasValue ? (g.C12.Value*100M).ToString("0") + "%" : "nc") : "0"
                                }
                            }).ToArray()
                };
                return sitesGridData;
            }
        }
Example #24
0
        public ActionResult GetEquipos(JqGridRequest request)
        {
            //int equipoId = ViewBag.ApuestaId;
            int totalRecords = 0;
            List<Equipo> equipos = repository.dal_equipo.GetEquipos(); ;
            totalRecords = equipos.Count();

            //Prepare JqGridData instance
            JqGridResponse response = new JqGridResponse()
            {
                //Total pages count
                TotalPagesCount = (int)Math.Ceiling((float)totalRecords / (float)request.RecordsCount),
                //Page number
                PageIndex = request.PageIndex,
                //Total records count
                TotalRecordsCount = totalRecords
            };

            foreach (Equipo equipo in equipos)
            {
                response.Records.Add(new JqGridRecord(Convert.ToString(equipo.Equipo_ID), new List<object>()
                {
                   equipo.Equipo_ID,
                   equipo.Grupo,
                   equipo.Equipo_desc,
                   equipo.Ptos,
                   equipo.PJ,
                   equipo.PG,
                   equipo.PE,
                   equipo.PP,
                   equipo.GF,
                   equipo.GC,
                   equipo.DG,
                }));
            }

            //Return data as json
            return new JqGridJsonResult() { Data = response };
        }
Example #25
0
        public ActionResult GetPartidosUpdate(JqGridRequest request)
        {
            //int equipoId = ViewBag.ApuestaId;
            int totalRecords = 0;
            List<PartidoLog> partidos = repository.dal_partido_log.GetPartidos();
            totalRecords = partidos.Count();

            //Prepare JqGridData instance
            JqGridResponse response = new JqGridResponse()
            {
                //Total pages count
                TotalPagesCount = (int)Math.Ceiling((float)totalRecords / (float)request.RecordsCount),
                //Page number
                PageIndex = request.PageIndex,
                //Total records count
                TotalRecordsCount = totalRecords
            };

            foreach (PartidoLog partido in partidos)
            {
                response.Records.Add(new JqGridRecord(Convert.ToString(partido.Id), new List<object>()
                {
                   partido.Id,
                   partido.PartidoId,
                   partido.UserId,
                   partido.UpdateDate.ToString("yy/MM/dd hh:mm:ss"),
                   partido.Partido.EquipoIdLocal,
                   partido.Partido.EquipoDescLocal,
                   partido.Partido.GolesLocal,
                   partido.Partido.Resultado,
                   partido.Partido.EquipoIdVisita,
                   partido.Partido.EquipoDescVisita,
                   partido.Partido.GolesVisita
                }));
            }

            //Return data as json
            return new JqGridJsonResult() { Data = response };
        }
Example #26
0
        public static JqGridData FetchPeopleJQGrid(Person currentPerson, JqGridRequest request, int roleId)
        {
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var people = (from p in context.People.Include("Family").Include("PersonGroups")
                              from pc in p.PersonChurches
                              where pc.ChurchId == currentPerson.ChurchId
                                && (pc.RoleId == roleId)
                              select p);

                if (request._search)
                {
                    foreach (var rule in request.filters.rules)
                    {
                        var ruleData = rule.data;
                        //If we use rule.data throughout we get some strange errors in the SQL that Linq generates
                        switch (rule.field)
                        {
                            case "Group":
                                {
                                    var groupIds = (from g in context.Groups
                                                    where g.Name.Contains(ruleData)
                                                    select g.GroupId).ToList();

                                    people = (from p in people
                                              from pg in p.PersonGroups
                                              where groupIds.Contains(pg.GroupId)
                                              select p);
                                    break;
                                }
                            case "Firstname":
                                {
                                    people = (from p in people
                                              where p.Firstname.Contains(ruleData)
                                              select p);
                                    break;
                                }
                            case "Surname":
                                {
                                    people = (from p in people
                                              where p.Family.FamilyName.Contains(ruleData)
                                              select p);
                                    break;
                                }
                            case "Date":
                                {
                                    DateTime dStart;
                                    if (DateTime.TryParse(ruleData, out dStart))
                                    {
                                        var dEnd = dStart.AddDays(1);
                                        people = (from p in people
                                                  where p.Created >= dStart && p.Created < dEnd
                                                  select p);
                                    }
                                    break;
                                }
                            case "Site":
                                {
                                    people = (from p in people
                                              where p.Site.Name.Contains(ruleData)
                                              select p);
                                    break;
                                }
                            case "HomePhone":
                                {
                                    people = (from p in people
                                              where p.Family.HomePhone.Contains(ruleData)
                                              select p);
                                    break;
                                }
                            case "CellPhone":
                                {
                                    people = (from p in people
                                              from po in p.PersonOptionalFields
                                              where (po.OptionalFieldId == (int)OptionalFields.CellPhone
                                                     && po.Value.Contains(ruleData))
                                              select p);
                                    break;
                                }
                            case "Email":
                                {
                                    people = (from p in people
                                              where p.Email.Contains(ruleData)
                                              select p);
                                    break;
                                }
                        }
                    }
                }

                int totalRecords = people.Count();

                switch (request.sidx)
                {
                    case "Firstname":
                        {
                            people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows) : people.OrderByDescending(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows);
                            break;
                        }
                    case "Surname":
                        {
                            people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Family.FamilyName).Skip((request.page - 1) * request.rows).Take(request.rows) : people.OrderByDescending(p => p.Family.FamilyName).Skip((request.page - 1) * request.rows).Take(request.rows);
                            break;
                        }
                    case "Date":
                        {
                            people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Created).Skip((request.page - 1) * request.rows).Take(request.rows) : people.OrderByDescending(p => p.Created).Skip((request.page - 1) * request.rows).Take(request.rows);
                            break;
                        }
                    case "Group":
                        {
                            people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.PersonGroups.FirstOrDefault().Group.Name).Skip((request.page - 1) * request.rows).Take(request.rows) : people.OrderByDescending(p => p.PersonGroups.FirstOrDefault().Group.Name).Skip((request.page - 1) * request.rows).Take(request.rows);
                            break;
                        }
                    case "Site":
                        {
                            people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Site.Name).Skip((request.page - 1) * request.rows).Take(request.rows) : people.OrderByDescending(p => p.Site.Name).Skip((request.page - 1) * request.rows).Take(request.rows);
                            break;
                        }
                    case "HomePhone":
                        {
                            people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Family.HomePhone).Skip((request.page - 1) * request.rows).Take(request.rows) : people.OrderByDescending(p => p.Family.HomePhone).Skip((request.page - 1) * request.rows).Take(request.rows);
                            break;
                        }
                    case "Email":
                        {
                            people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Email).Skip((request.page - 1) * request.rows).Take(request.rows) : people.OrderByDescending(p => p.Email).Skip((request.page - 1) * request.rows).Take(request.rows);
                            break;
                        }
                }

                var peopleGridData = new JqGridData()
                    {
                        total = (int)Math.Ceiling((float)totalRecords / request.rows),
                        page = request.page,
                        records = totalRecords,
                        rows = (from p in people.AsEnumerable()
                                select new JqGridRow()
                                {
                                    id = p.PersonId.ToString(),
                                    cell = new string[] {
                                                        p.PersonId.ToString(),
                                                        p.Firstname,
                                                        p.Family.FamilyName,
                                                        p.Family.HomePhone,
                                                        p.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)OptionalFields.CellPhone)==null?"":p.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)OptionalFields.CellPhone).Value,
                                                        p.Email,
                                                        p.Created.ToString("dd MMM yyyy"),
                                                        p.PersonGroups.Count > 1 ? "Multiple" : (p.PersonGroups.Count==0 ? "None" : p.PersonGroups.First().Group.Name),
                                                        p.Site== null ? string.Empty : p.Site.Name
                                    }
                                }).ToArray()
                    };

                return peopleGridData;
            }
        }
Example #27
0
        public static JqGridData FetchGroupsForPersonJQGrid(Person currentPerson, int personId, JqGridRequest request)
        {
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                IEnumerable<PersonGroupModel> groups = (from g in context.Groups
                                                 join pg in context.PersonGroups
                                                   on g.GroupId equals pg.GroupId
                                                 where pg.PersonId == personId
                                                     && g.ChurchId == currentPerson.ChurchId
                                                 select new PersonGroupModel
                                                 {
                                                     PersonId = pg.PersonId,
                                                     GroupId = g.GroupId,
                                                     Name = g.Name,
                                                     Type = g.GroupType.Name,
                                                     Administrator = g.Administrator.Firstname + " " + g.Administrator.Family.FamilyName,
                                                     Leader = g.Leader.Firstname + " " + g.Leader.Family.FamilyName
                                                 })
                                                 .ToList();

                foreach (PersonGroupModel pg in groups)
                {
                    string groupIdAsString = pg.GroupId.ToString();
                    DateTime lastDateAttended = (from e in context.OldEvents
                                            where e.Reference == personId
                                              && e.Value == groupIdAsString
                                            orderby e.EventDate descending
                                            select e.EventDate)
                                            .FirstOrDefault();

                    pg.LastAttended = lastDateAttended == DateTime.MinValue ? "Never" : lastDateAttended.ToString("dd MMM yyyy");

                    var groupClassification = context.Groups.FirstOrDefault(g => g.GroupId == pg.GroupId).GroupClassification;
                    if (groupClassification != null)
                        pg.Type = groupClassification.Name;
                }

                int totalRecords = groups.Count();

                switch (request.sidx)
                {
                    case "Name":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                groups = groups.OrderBy(g => g.Name)
                                    .Skip((request.page - 1) * request.rows)
                                    .Take(request.rows)
                                    .ToList();
                            }
                            else
                            {
                                groups = groups
                                    .OrderByDescending(g => g.Name)
                                    .Skip((request.page - 1) * request.rows)
                                    .Take(request.rows)
                                    .ToList();
                            }
                            break;
                        }
                    case "Type":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                groups = groups.OrderBy(g => g.Type)
                                    .Skip((request.page - 1) * request.rows)
                                    .Take(request.rows)
                                    .ToList();
                            }
                            else
                            {
                                groups = groups
                                    .OrderByDescending(g => g.Type)
                                    .Skip((request.page - 1) * request.rows)
                                    .Take(request.rows)
                                    .ToList();
                            }
                            break;
                        }
                    case "LastAttended":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                groups = groups.OrderBy(g => g.LastAttended)
                                    .Skip((request.page - 1) * request.rows)
                                    .Take(request.rows)
                                    .ToList();
                            }
                            else
                            {
                                groups = groups
                                    .OrderByDescending(g => g.LastAttended)
                                    .Skip((request.page - 1) * request.rows)
                                    .Take(request.rows)
                                    .ToList();
                            }
                            break;
                        }
                    case "Leader":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                groups = groups.OrderBy(g => g.Leader)
                                    .Skip((request.page - 1) * request.rows)
                                    .Take(request.rows)
                                    .ToList();
                            }
                            else
                            {
                                groups = groups
                                    .OrderByDescending(g => g.Leader)
                                    .Skip((request.page - 1) * request.rows)
                                    .Take(request.rows)
                                    .ToList();
                            }
                            break;
                        }
                    case "Administrator":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                groups = groups.OrderBy(g => g.Administrator)
                                    .Skip((request.page - 1) * request.rows)
                                    .Take(request.rows)
                                    .ToList();
                            }
                            else
                            {
                                groups = groups
                                    .OrderByDescending(g => g.Administrator)
                                    .Skip((request.page - 1) * request.rows)
                                    .Take(request.rows)
                                    .ToList();
                            }
                            break;
                        }
                }

                JqGridData groupsGridData = new JqGridData()
                {
                    total = (int)Math.Ceiling((float)totalRecords / (float)request.rows),
                    page = request.page,
                    records = totalRecords,
                    rows = (from g in groups
                            select new JqGridRow()
                            {
                                id = g.GroupId.ToString(),
                                cell = new string[] {
                                                    g.GroupId.ToString(),
                                                    g.Name,
                                                    g.Type,
                                                    g.LastAttended,
                                                    g.Leader,
                                                    g.Administrator
                                }
                            }).ToArray()
                };
                return groupsGridData;
            }
        }
Example #28
0
        public ActionResult Partidos(JqGridRequest request)
        {
            _logger.Info("START  Partidos");
            JqGridResponse response;
            try
            {
                int totalRecords = 0;

                List<PartidosView> partidos = repository.dal_partido.GetPartidosView(0);
                totalRecords = partidos.Count();
                //Prepare JqGridData instance
                response = new JqGridResponse()
                {
                    //Total pages count
                    TotalPagesCount = (int)Math.Ceiling((float)totalRecords / (float)request.RecordsCount),
                    //Page number
                    PageIndex = request.PageIndex,
                    //Total records count
                    TotalRecordsCount = totalRecords
                };

                foreach (PartidosView partido in partidos)
                {
                    response.Records.Add(new JqGridRecord(Convert.ToString(partido.PartidoId), new List<object>()
                {
                    partido.PartidoId,
                    partido.EquipoIdLocal,
                    partido.EquipoDescLocal,
                    partido.GolesLocal,
                    partido.Resultado,
                    partido.EquipoIdVisita,
                    partido.GolesVisita,
                    partido.EquipoDescVisita
                }));
                }

            }
            catch (Exception ex)
            {
                _logger.Error("Error : ", ex);
                throw;
            }
            finally
            {

            }
            //Return data as json
            return new JqGridJsonResult() { Data = response };
        }
Example #29
0
 public ActionResult GetOrders(JqGridRequest request, string keyword)
 {
   var searchCriteria = new OrderingSearchCriteria(){PersonId = (Guid)Session["Person"]};
   var result = _orderingReportService.OrderingRetailOrders(searchCriteria, request.RecordsCount, request.PageIndex);
   var jsonData = new
   {
     total = (result.Count + request.RecordsCount - 1) / request.RecordsCount,
     page = request.PageIndex + 1,
     records = result.Count,
     rows = result.Items
   };
   return Json(jsonData, JsonRequestBehavior.AllowGet);
 }
Example #30
0
        public static JqGridData FetchChurchListJQGrid(Person currentPerson, JqGridRequest request)
        {
            using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var rolesToInclude = context
                    .PermissionRoles
                    .Where(p => p.PermissionId == (int)Permissions.IncludeInChurchList && p.Role.ChurchId == currentPerson.ChurchId)
                    .Select(p=>p.RoleId)
                    .ToList();

                var people = (from p in context.People.Include("Family").Include("PersonOptionalFields")
                              from c in p.PersonChurches
                              where c.ChurchId == currentPerson.ChurchId
                              && rolesToInclude.Contains(c.RoleId)
                              select p);

                if (!(currentPerson.HasPermission(Permissions.ViewChurchContactDetails)))
                {
                    if(!currentPerson.HasPermission(Permissions.ViewGroupContactDetails))
                        throw new Exception("You do not have permission to view contact details");
                    //Get the groups
                    var groups = (from pg in context.PersonGroups
                                  where pg.PersonId == currentPerson.PersonId
                                  select pg.GroupId).ToList();

                    people = (from p in people
                              from pg in p.PersonGroups
                              where groups.Contains(pg.GroupId)
                              select p);
                }

                if (request._search)
                {
                    switch (request.searchField)
                    {
                        case "search":
                            {
                                people = Filters.ApplyNameSearch(request.searchString, people);
                                break;
                            }
                        case "homegroup":
                            {
                                var homegroupId = (from pg in context.PersonGroups
                                                   where pg.PersonId == currentPerson.PersonId
                                                   select pg.GroupId).FirstOrDefault();

                                if (homegroupId > 0)
                                {
                                    people = (from p in context.People.Include("Family").Include("PersonOptionalFields")
                                              from c in p.PersonChurches
                                              join pg in context.PersonGroups
                                              on p.PersonId equals pg.PersonId
                                              where c.ChurchId == currentPerson.ChurchId
                                              && pg.GroupId == homegroupId
                                              select p);
                                }
                                break;
                            }
                    }
                }

                int totalRecords = people.Count();

                switch (request.sidx)
                {
                    case "Firstname":
                        {
                            people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows) : people.OrderByDescending(p => p.Firstname).Skip((request.page - 1) * request.rows).Take(request.rows);
                            break;
                        }
                    case "Surname":
                        {
                            people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Family.FamilyName).Skip((request.page - 1) * request.rows).Take(request.rows) : people.OrderByDescending(p => p.Family.FamilyName).Skip((request.page - 1) * request.rows).Take(request.rows);
                            break;
                        }
                    case "Email":
                        {
                            people = request.sord.ToLower() == "asc" ? people.OrderBy(p => p.Email).Skip((request.page - 1) * request.rows).Take(request.rows) : people.OrderByDescending(p => p.Email).Skip((request.page - 1) * request.rows).Take(request.rows);
                            break;
                        }
                }

                var membersGridData = new JqGridData()
                {
                    total = (int)Math.Ceiling((float)totalRecords / request.rows),
                    page = request.page,
                    records = totalRecords,
                    rows = (from p in people.AsEnumerable()
                            select new JqGridRow()
                            {
                                id = p.PersonId.ToString(),
                                cell = new string[] {
                                                    p.PersonId.ToString(),
                                                    p.Firstname,
                                                    p.Family.FamilyName,
                                                    p.Family.HomePhone,
                                                    p.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)OptionalFields.CellPhone)==null?"":p.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)OptionalFields.CellPhone).Value,
                                                    p.Email
                                                }
                            }).ToArray()
                };
                return membersGridData;
            }
        }