Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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 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 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;
            }
        }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
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;
            }
        }
Ejemplo n.º 7
0
        public JsonResult FetchPermissionsUnLinked(JqGridRequest request, int roleId)
        {
            JqGridData jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                Person currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                jqGridData = PermissionDataAccessor.FetchPermissionsNotInRoleJQGrid(currentPerson, request, roleId);
            }

            return Json(jqGridData);
        }
Ejemplo n.º 8
0
        public JsonResult FetchPeopleInGroup(JqGridRequest request, int groupId)
        {
            JqGridData jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                Person currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                jqGridData = GroupDataAccessor.FetchPeopleInGroupJQGrid(currentPerson, request, groupId);
            }

            return Json(jqGridData);
        }
Ejemplo n.º 9
0
        public JsonResult FetchGroupsPersonIsNotIn(JqGridRequest request, int personId)
        {
            var jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                var currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                jqGridData = _personGroupService.FetchGroupsPersonIsNotInJQGrid(currentPerson, personId, request);
            }

            return Json(jqGridData);
        }
Ejemplo n.º 10
0
        public JsonResult FetchBirthdays(JqGridRequest request, int monthId, string selectedRoles)
        {
            var jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                var currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                jqGridData = _eventService.FetchBirthdayList(currentPerson, request, monthId, selectedRoles.Split(','));
            }

            return Json(jqGridData);
        }
Ejemplo n.º 11
0
        private JsonResult FetchListOfGroups(JqGridRequest request, int? selectedGroupId, bool? useGroupId)
        {
            try
            {
                var jqGridData = new JqGridData();
                if (Session[SessionVariable.LoggedOnPerson] != null)
                {
                    var currentPerson = (Person) Session[SessionVariable.LoggedOnPerson];
                    if (currentPerson.HasPermission(Permissions.EditAllGroups) ||
                        currentPerson.HasPermission(Permissions.EditOwnGroups))
                    {
                        jqGridData = GroupDataAccessor.FetchHomeGroupsJQGrid(currentPerson, request, selectedGroupId, useGroupId);
                    }
                }

                return Json(jqGridData);
            }
            catch (Exception ex)
            {
                try
                {
                    _emailService.SendExceptionEmail(ex);
                }
                catch
                {
                }
                return Json(null);
            }
        }
Ejemplo n.º 12
0
        public JsonResult FetchSites(JqGridRequest request)
        {
            var jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                var currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                jqGridData = ChurchDataAccessor.FetchSitesJQGrid(currentPerson, request);
            }

            return Json(jqGridData);
        }
Ejemplo n.º 13
0
        public JsonResult FetchPeopleToBeReminded(JqGridRequest request, string reminderType)
        {
            var jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                var currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                jqGridData = _reminderService.FetchPeopleToBeRemindedJQGrid(currentPerson, reminderType, request);
            }

            return Json(jqGridData);
        }
Ejemplo n.º 14
0
        public JsonResult FetchMessageStatusResults(JqGridRequest request)
        {
            var jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                var currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                jqGridData = _messageService.GetMessageStatuses(currentPerson, request);
            }

            return Json(jqGridData);
        }
Ejemplo n.º 15
0
        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;
        }
Ejemplo n.º 16
0
        public JsonResult FetchGroupsForPerson(JqGridRequest request, int personId)
        {
            JqGridData jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                Person currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                jqGridData = PersonDataAccessor.FetchGroupsForPersonJQGrid(currentPerson, personId, request);
            }

            return Json(jqGridData);
        }
Ejemplo n.º 17
0
        public JsonResult FetchHomeGroupList(JqGridRequest request)
        {
            try
            {
                JqGridData jqGridData = new JqGridData();
                var message = string.Empty;
                if (Session[SessionVariable.LoggedOnPerson] != null)
                {
                    var currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                    message = String.Format("Current Person:{0}", currentPerson.Fullname);

                }

                message += " is trying to access FetchHomeGroupList";

                Email.SendSystemEmail("Javascript file not updated", message);

                return Json(jqGridData);
            }
            catch (Exception ex)
            {
                try
                {
                    Email.SendExceptionEmail(ex);
                }
                catch { }
                return Json(null);
            }
        }
Ejemplo n.º 18
0
        public JsonResult FetchListOfChildren(JqGridRequest request, string selectedRoles)
        {
            var jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                var currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                jqGridData = _childReportsService.FetchListOfChildren(currentPerson, request, selectedRoles.Split(','));
            }

            return Json(jqGridData);
        }
Ejemplo n.º 19
0
        public JsonResult FetchPeopleNotInHomeGroup(JqGridRequest request)
        {
            JqGridData jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                Person currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                if (currentPerson.HasPermission(common.Permissions.ViewPeopleNotInAnyGroup))
                {
                    jqGridData = GroupDataAccessor.FetchPeopleNotInAHomeGroupJQGrid(currentPerson, request);
                }
            }

            return Json(jqGridData);
        }
Ejemplo n.º 20
0
        public JsonResult FetchChurchList(JqGridRequest request)
        {
            JqGridData jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                Person currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                jqGridData = PersonDataAccessor.FetchChurchListJQGrid(currentPerson, request);
            }

            return Json(jqGridData);
        }
Ejemplo n.º 21
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;
            }
        }
Ejemplo n.º 22
0
        public JsonResult FetchCommentListForPerson(JqGridRequest request, int personId)
        {
            var jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                var currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                ICommentService commentService = new CommentService(new CommentRepository(_context));
                IGridFormatter gridFormatter = new GridFormatter();
                var comments = commentService.GetListOfComments(currentPerson, personId);
                jqGridData = gridFormatter.FormatCommentsForGrid(comments, request);
            }

            return Json(jqGridData);
        }
Ejemplo n.º 23
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;
            }
        }
Ejemplo n.º 24
0
        public JsonResult FetchEventList(JqGridRequest request, DateTime fromDate, DateTime toDate)
        {
            JqGridData jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                Person currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                jqGridData = EventDataAccessor.FetchEventListJQGrid(currentPerson, fromDate, toDate, request);
            }

            return Json(jqGridData);
        }
        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;
            }
        }
Ejemplo n.º 26
0
        public JsonResult FetchEventListForPerson(JqGridRequest request, int personId)
        {
            var jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                var currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                jqGridData = EventDataAccessor.FetchEventListJQGrid(currentPerson, personId, request);
            }

            return Json(jqGridData);
        }
        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;
            }
        }
Ejemplo n.º 28
0
        public JsonResult FetchGroupAttendance(JqGridRequest request)
        {
            JqGridData jqGridData = new JqGridData();
            if (Session[SessionVariable.LoggedOnPerson] != null)
            {
                Person currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                if (currentPerson.HasPermission(common.Permissions.ViewGroupAttendance))
                {
                    jqGridData = GroupDataAccessor.FetchGroupAttendanceJQGrid(currentPerson, request);
                }
            }

            return Json(jqGridData);
        }
Ejemplo n.º 29
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;
        }
Ejemplo n.º 30
0
        public JsonResult FetchGroupList(JqGridRequest request)
        {
            try
            {
                JqGridData jqGridData = new JqGridData();
                if (Session[SessionVariable.LoggedOnPerson] != null)
                {
                    Person currentPerson = (Person)Session[SessionVariable.LoggedOnPerson];
                    if (currentPerson.HasPermission(common.Permissions.EditAllGroups) || currentPerson.HasPermission(Permissions.EditOwnGroups))
                    {
                        jqGridData = GroupDataAccessor.FetchHomeGroupsJQGrid(currentPerson, request);
                    }
                }

                return Json(jqGridData);
            }
            catch (Exception ex)
            {
                try
                {
                    Email.SendExceptionEmail(ex);
                }
                catch { }
                return Json(null);
            }
        }