public static void FetchBulkSmsUsernameAndPassword(Person currentPerson, out string username, out string password)
        {
            if (currentPerson.HasPermission(common.Permissions.SmsChurch) || currentPerson.HasPermission(common.Permissions.SmsGroupLeaders) || currentPerson.HasPermission(common.Permissions.SmsGroupMembers))
            {
                using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
                {
                    username = (from c in context.ChurchSmsProviders
                                where c.ChurchId == currentPerson.ChurchId
                                    && c.SmsProviderId == (int)SmsProviders.BulkSmsSouthAfrica
                                select c.Username)
                                .FirstOrDefault();

                    password = (from c in context.ChurchSmsProviders
                                where c.ChurchId == currentPerson.ChurchId
                                    && c.SmsProviderId == (int)SmsProviders.BulkSmsSouthAfrica
                                select c.Password)
                                .FirstOrDefault();

                    return;
                }
            }

            username = null;
            password = null;
        }
예제 #2
0
        public static List<StandardCommentViewModel> AddStandardComment(Person currentPerson, string standardComment)
        {
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                if (currentPerson.HasPermission(common.Permissions.AddEvent))
                {
                    var check = CheckToSeeIfTheCommentIsAlreadyThere(currentPerson, standardComment, context);

                    if (check == 0)
                    {
                        var newStandardComment = new StandardComment
                                               {
                                                   StandardComment1= standardComment,
                                                   ChurchId        = currentPerson.ChurchId
                                               };

                        context.StandardComments.AddObject(newStandardComment);
                        context.SaveChanges();
                    }
                }

                return (from e in context.StandardComments
                        where e.ChurchId == currentPerson.ChurchId
                        select new StandardCommentViewModel
                        {
                            StandardCommentId = e.StandardCommentId,
                            StandardComment = e.StandardComment1
                        }).ToList();
            }
        }
        public static string DeleteSite(Person currentPerson, int siteId)
        {
            if (currentPerson.HasPermission(Permissions.DeleteSite))
            {
                using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
                {
                    var siteToDelete = (from s in context.Sites
                                        where s.ChurchId == currentPerson.ChurchId
                                        && s.SiteId == siteId
                                        select s).FirstOrDefault();

                    if (siteToDelete == null)
                    {
                        return "Could not delete site";
                    }

                    //Remove all the people linked to this site
                    var peopleLinkedToSite = context.People.Where(p => p.SiteId == siteId);

                    foreach (var p in peopleLinkedToSite)
                    {
                        p.SiteId = null;
                        p.Changed = DateTime.Now;
                    }

                    context.Sites.DeleteObject(siteToDelete);

                    context.SaveChanges();
                    return "Site succesfully removed";
                }
            }
            return "Could not delete site";
        }
예제 #4
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;
            }
        }
예제 #5
0
 public static void DeletePerson(int personId, Person currentPerson)
 {
     if(!currentPerson.HasPermission(Permissions.DeletePerson))
         return;
     using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
     {
         if (RemovePersonFromChurchSpecificTables(personId, currentPerson, context))
         {
             DeletePerson(personId, context);
         }
         context.SaveChanges();
     }
 }
예제 #6
0
        public static List<GroupClassificationViewModel> AddGroupClassification(Person currentPerson, string groupClassification)
        {
            using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                if (currentPerson.HasPermission(common.Permissions.AddGroupClassification))
                {//Check to see if it is not already in the db
                    var check = (from g in context.GroupClassifications
                                 where g.ChurchId == currentPerson.ChurchId
                                 && g.Name == groupClassification
                                 select g).Count();
                    if (check == 0)
                    {
                        GroupClassification gc = new GroupClassification();
                        gc.Created = DateTime.Now;
                        gc.Changed = DateTime.Now;
                        gc.Name = groupClassification;
                        gc.ChurchId = currentPerson.ChurchId;
                        if (currentPerson.ChurchId == 3) //ebenezer
                        {
                            gc.GroupTypeId = (int)GroupTypes.LifeGroup;
                        }
                        else
                        {
                            gc.GroupTypeId = (int)GroupTypes.HomeGroup;
                        }

                        context.GroupClassifications.AddObject(gc);
                        context.SaveChanges();
                    }

                }

                return (from g in context.GroupClassifications
                        where g.ChurchId == currentPerson.ChurchId
                        select new GroupClassificationViewModel
                        {
                            GroupClassificationId = g.GroupClassificationId,
                            GroupClassification = g.Name
                        }).ToList();

            }
        }
예제 #7
0
        public static void AddPermissionsToRole(Person currentPerson, int roleId, List<int> permissionIds)
        {
            if (!currentPerson.HasPermission(Permissions.EditPermissions))
                return;
            using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                foreach (var permissionId in permissionIds)
                {
                    PermissionRole pr = new PermissionRole()
                    {
                        RoleId = roleId,
                        Changed = DateTime.Now,
                        Created = DateTime.Now,
                        PermissionId = permissionId
                    };

                    context.PermissionRoles.AddObject(pr);
                }

                context.SaveChanges();

            }
        }
예제 #8
0
 private static void SendVisitorWelcome(bool includeUsername,
     string firstname,
     string surname,
     Church church,
     string email,
     Person personToSave)
 {
     string password = string.Empty;
     if (includeUsername)
     {
         personToSave.Username = (firstname + surname).Replace(" ", string.Empty);  //TODO replace with a boolean saying welcome letter has been sent
         password = RandomPasswordGenerator.Generate(RandomPasswordOptions.AlphaNumeric);
         personToSave.PasswordHash = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "sha1");
     }
     personToSave.PublicId = Email.SendWelcomeEmail(firstname,
           surname,
           church,
           email,
           password,
           personToSave.HasPermission(Permissions.SendVisitorWelcomeLetter),
           includeUsername);
 }
예제 #9
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;
            }
        }
예제 #10
0
 private static void SendEmails(PersonViewModel person, bool sendWelcomeEmail, Church church, Person personToSave)
 {
     if (sendWelcomeEmail && person.PersonId == 0 && personToSave.HasPermission(Permissions.SendWelcomeLetter) && personToSave.HasValidEmail())
     {
         SendVisitorWelcome(sendWelcomeEmail,
             person.Firstname,
             person.Surname,
             church,
             person.Email,
             personToSave);
     }
     else if (sendWelcomeEmail && personToSave.HasValidEmail() && personToSave.HasPermission(Permissions.Login))
     {
         SendEmailAndPassword(person.Firstname,
             person.Surname,
             church,
             person.Email,
             personToSave);
     }
 }
        public static void SaveSite(Person currentPerson, SiteSettingsViewModel siteSettings)
        {
            if (string.IsNullOrWhiteSpace(siteSettings.SiteName))
                return;

            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                //Check Roles
                if (!currentPerson.HasPermission(Permissions.AddSite) && !currentPerson.HasPermission(Permissions.EditSite)) return;
                var siteToSave = new Site();
                if (siteSettings.SiteId == 0)
                {
                    if (!currentPerson.HasPermission(Permissions.AddSite)) return;
                    siteToSave.Created = DateTime.Now;
                    siteToSave.ChurchId = currentPerson.ChurchId;
                }
                else
                {
                    if (!currentPerson.HasPermission(Permissions.EditSite)) return;
                    siteToSave = (from s in context.Sites.Include("Address")
                                  where s.SiteId == siteSettings.SiteId
                                  select s).FirstOrDefault() ??
                                 new Site {Created = DateTime.Now, ChurchId = currentPerson.ChurchId};
                }

                siteToSave.Changed = DateTime.Now;
                siteToSave.Name = siteSettings.SiteName;

                if (siteSettings.AddressId == 0)
                {
                    siteToSave.Address = new Address {Created = DateTime.Now};
                    context.Sites.AddObject(siteToSave);
                }

                siteToSave.Address.Changed = DateTime.Now;
                siteToSave.Address.Line1 = siteSettings.Address1 ?? string.Empty;
                siteToSave.Address.Line2 = siteSettings.Address2 ?? string.Empty;
                siteToSave.Address.Line3 = siteSettings.Address3 ?? string.Empty;
                siteToSave.Address.Line4 = siteSettings.Address4 ?? string.Empty;
                siteToSave.Address.Lat = siteSettings.Lat;
                siteToSave.Address.Long = siteSettings.Lng;
                siteToSave.Address.AddressType = siteSettings.AddressType ?? string.Empty;

                context.SaveChanges();
            }
        }
예제 #12
0
        public static AutoCompleteViewModel[] FetchPersonAutoComplete(string term, Person currentPerson, bool wholeChurch)
        {
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var query = (from p in context.People.Include("PersonOptionalField").Include("Address")
                             from c in p.PersonChurches
                             join r in context.Roles
                                on c.RoleId equals r.RoleId
                             where c.ChurchId == currentPerson.ChurchId
                               && r.ChurchId == currentPerson.ChurchId
                             select p);

                if (term.Contains(" "))
                {
                    var searchStrings = term.Split(' ');
                    var searchString1 = searchStrings[0];
                    var searchString2 = searchStrings[1];
                    query             = query.Where(p => p.Firstname.Contains(searchString1) && p.Family.FamilyName.Contains(searchString2));
                }
                else
                {
                    query = query.Where(p => p.Firstname.Contains(term) || p.Family.FamilyName.Contains(term));
                }

                if (!wholeChurch)
                {
                    //Find out the persons role
                    if (currentPerson.HasPermission(Permissions.EditChurchPersonalDetails))
                    {
                        //No filter required
                        query = query.Take(12);
                    }
                    else if (currentPerson.HasPermission(Permissions.EditGroupPersonalDetails))
                    {
                        var grp = (from g in context.Groups
                                       where g.LeaderId == currentPerson.PersonId
                                       || g.AdministratorId == currentPerson.PersonId
                                       select g).FirstOrDefault();

                        if (grp == null)
                        {
                            return new AutoCompleteViewModel[0];
                        }
                        //Filter for the group
                        query = (from q in query
                                 join pg in context.PersonGroups
                                    on q.PersonId equals pg.PersonId
                                 where pg.GroupId == grp.GroupId
                                 select q).Take(12);
                    }
                    else
                    {
                        return new AutoCompleteViewModel[0];
                    }
                }

                return (from p in query.OrderBy(p => p.Firstname)
                        select new AutoCompleteViewModel
                        {
                            id = p.PersonId,
                            label = p.Firstname + " " + p.Family.FamilyName,
                            value = p.Firstname + " " + p.Family.FamilyName
                        }).ToArray();
            }
        }
예제 #13
0
        public static int SavePerson(PersonViewModel person, Person currentPerson)
        {
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                if (!currentPerson.HasPermission(Permissions.EditChurchPersonalDetails))
                {
                    if (currentPerson.HasPermission(Permissions.EditGroupPersonalDetails))
                    {
                        if (!CheckSavePermissionGroup(person, currentPerson, context)) { return person.PersonId; }
                    }
                    else if (currentPerson.HasPermission(Permissions.EditOwnDetails))
                    {
                        if (!CheckSavePermissionPersonal(person, currentPerson, context)) { return person.PersonId; }
                    }
                    else
                    {
                        return person.PersonId;
                    }
                }

                bool sendWelcomeEmail;
                Church church;
                Person personToSave;

                GetPersonToSaveEntity(person, currentPerson, context, out sendWelcomeEmail, out church, out personToSave);
                bool anniversaryHasChanged = SavePersonalDetails(person, currentPerson, context, personToSave);
                SaveRole(person, currentPerson, context, personToSave);
                bool addedToNewGroup = AddPersonToGroup(person, currentPerson, context, personToSave);
                SaveContactInformation(person, personToSave);
                SaveAddressInformation(person, personToSave);

                UpdateRelationships(person, context, personToSave, anniversaryHasChanged);
                context.SaveChanges();
                personToSave = FetchPerson(personToSave.PersonId, context, currentPerson);
                SaveWindowsLiveId(person, personToSave, context);
                SendEmails(person, sendWelcomeEmail, church, personToSave);
                EmailGroupLeader(person, currentPerson, context, church, personToSave, addedToNewGroup);

                context.SaveChanges();

                return personToSave.PersonId;
            }
        }
예제 #14
0
 private static bool CheckSavePermissionGroup(PersonViewModel person, Person currentPerson, oikonomosEntities context)
 {
     var canSave = false;
     if (person.PersonId > 0)
     {
         var groupPerson = (from pg in context.PersonGroups
                            join g in context.Groups
                            on pg.GroupId equals g.GroupId
                            where pg.PersonId == person.PersonId
                            && g.ChurchId == currentPerson.ChurchId
                            && (g.LeaderId == currentPerson.PersonId || g.AdministratorId == currentPerson.PersonId)
                            select pg).FirstOrDefault();
         if (groupPerson != null)
         {
             canSave = true;
         }
     }
     else
     {
         canSave = currentPerson.HasPermission(Permissions.AddNewPerson);
     }
     return canSave;
 }
예제 #15
0
 private static void CheckThatChurchIdsMatch(int personId, Person currentPerson, oikonomosEntities context)
 {
     if (currentPerson.HasPermission(Permissions.SystemAdministrator))
         return;
     if (!context.People.First(p => p.PersonId == personId).PersonChurches.Select(c => c.ChurchId).ToList().Contains(currentPerson.ChurchId))
         throw new ApplicationException("ChurchId does not match currentPerson ChurchId");
 }
예제 #16
0
 public static Church SelectNewChurch(Person currentPerson, int churchId)
 {
     using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
     {
         if (currentPerson.HasPermission(Permissions.SystemAdministrator))
         {
             var church = context.Churches.First(c => c.ChurchId == churchId);
             SetupPermissions(context, currentPerson, church, true);
             return church;
         }
         return null;
     }
 }
예제 #17
0
        public static bool SendEmailAndPassword(Person currentPerson, int personId, ref string message)
        {
            if (personId == 0)
            {
                message = "You need to save the person before sending the email";
                return false;
            }

            if (!currentPerson.HasPermission(Permissions.SendEmailAndPassword))
            {
                message = "You don't have permission to perform this action";
                return false;
            }

            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var church = (from c in context.Churches
                              where c.ChurchId == currentPerson.ChurchId
                              select c).FirstOrDefault();
                if (church == null)
                {
                    message = "Error sending Email";
                    return false;
                }

                var personToUpdate = FetchPerson(personId, context, currentPerson);

                if (personToUpdate == null)
                {
                    message = "Error sending Email";
                    return false;
                }

                if (personToUpdate.HasPermission(Permissions.Login))
                {
                    if (personToUpdate.HasValidEmail())
                    {

                        SendEmailAndPassword(personToUpdate.Firstname,
                            personToUpdate.Family.FamilyName,
                            church,
                            personToUpdate.Email,
                            personToUpdate);

                        context.SaveChanges();
                        message = "Email sent succesfully";
                        return true;
                    }
                    else
                    {
                        message = "Invalid Email address";
                        return false;
                    }
                }
                else
                {
                    var roleName = context.PersonChurches.First(pc => pc.PersonId == personToUpdate.PersonId && pc.ChurchId == personToUpdate.ChurchId).Role.Name;
                    message = string.Format("You cannot send login details to a person with a role of {0}", roleName);
                    return false;
                }
            }
        }
예제 #18
0
        public static List<AttendanceEventViewModel> FetchGroupAttendance(Person currentPerson, int groupId, DateTime startDate, DateTime? endDate)
        {
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                if (!(currentPerson.HasPermission(Permissions.EditOwnGroups) || currentPerson.HasPermission(Permissions.EditAllGroups)))
                {
                    throw new Exception("Invalid security Role");
                }

                if (!(currentPerson.HasPermission(Permissions.EditAllGroups)) && currentPerson.HasPermission(Permissions.EditOwnGroups))
                {
                    var gr = (from g in context.Groups
                             where (g.LeaderId == currentPerson.PersonId || g.AdministratorId == currentPerson.PersonId)
                             && g.GroupId == groupId
                             select g).FirstOrDefault();
                    if (gr == null)
                    {
                        throw new Exception("Invalid security Role");
                    }
                }

                var groupIdString = groupId.ToString();
                var attendanceList = (from pg in context.PersonGroups
                                      join e in context.OldEvents
                                         on pg.PersonId equals e.Reference
                                      join pc in context.PersonChurches
                                         on pg.PersonId equals pc.PersonId
                                      where (e.Description.StartsWith(EventNames.AttendedGroup) || e.Description.StartsWith(EventNames.DidNotAttendGroup))
                                      && e.TableId == (int)Tables.Person
                                      && pg.GroupId == groupId
                                      && e.Value == groupIdString
                                      orderby e.EventDate, pg.Person.Family.FamilyName, pg.Person.Created
                                      select new AttendanceEventViewModel
                                      {
                                          PersonId  = pg.PersonId,
                                          FamilyId  = pg.Person.FamilyId,
                                          Firstname = pg.Person.Firstname,
                                          Surname   = pg.Person.Family.FamilyName,
                                          Attended  = e.Description.StartsWith(EventNames.AttendedGroup),
                                          Date      = e.EventDate,
                                          RoleId    = pc.RoleId,
                                          Role      = pc.Role.DisplayName
                                      });

                if (endDate == null)
                    return (from ae in attendanceList
                            where ae.Date == startDate
                            select ae).ToList();

                return (from ae in attendanceList
                        where ae.Date >= startDate
                              && ae.Date <= endDate.Value
                        select ae).ToList();
            }
        }
예제 #19
0
        public static JqGridData FetchEventListJQGrid(Person currentPerson, int personId, JqGridRequest request)
        {
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                int visibilityLevel = 2;
                if (currentPerson.HasPermission(Permissions.ViewComments))
                {
                    visibilityLevel = 1;
                }

                var events = (from e in context.OldEvents
                              where e.Reference == personId
                                  && e.TableId == (int)Tables.Person
                                  && e.EventVisibilityId >= visibilityLevel
                                  && e.ChurchId == currentPerson.ChurchId
                              select e);

                int totalRecords = events.Count();

                switch (request.sidx)
                {
                    case "Date":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                events = events.OrderBy(e => e.EventDate).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                events = events.OrderByDescending(e => e.EventDate).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "Event":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                events = events.OrderBy(e => e.Description).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                events = events.OrderByDescending(e => e.Description).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                    case "CreatedBy":
                        {
                            if (request.sord.ToLower() == "asc")
                            {
                                events = events.OrderBy(e => e.CreatedByPerson.Firstname).ThenBy(e => e.CreatedByPerson.Family.FamilyName).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            else
                            {
                                events = events.OrderByDescending(e => e.CreatedByPerson.Firstname).ThenBy(e => e.CreatedByPerson.Family.FamilyName).Skip((request.page - 1) * request.rows).Take(request.rows);
                            }
                            break;
                        }
                }

                JqGridData eventsGridData = new JqGridData()
                {
                    total = (int)Math.Ceiling((float)totalRecords / (float)request.rows),
                    page = request.page,
                    records = totalRecords,
                    rows = (from e in events.AsEnumerable()
                            select new JqGridRow()
                            {
                                id = e.EventId.ToString(),
                                cell = new string[] {
                                                    e.Reference.ToString(),
                                                    e.EventDate.ToString("dd MMM yyyy"),
                                                    e.Description=="Comment" ? e.Comments : e.Description,
                                                    e.CreatedByPerson.Firstname + " " + e.CreatedByPerson.Family.FamilyName,
                                                    e.Comments
                                }
                            }).ToArray()
                };
                return eventsGridData;
            }
        }
예제 #20
0
        public static void SaveChurchContactDetails(Person currentPerson, ChurchSettingsViewModel churchSettings)
        {
            if (currentPerson.HasPermission(common.Permissions.EditChurchContactDetails))
            {
                using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
                {
                    var churchToSave = (from c in context.Churches
                                        where c.ChurchId == currentPerson.ChurchId
                                        select c).FirstOrDefault();

                    PopulateChurchModel(churchSettings, churchToSave);
                    PopulateChurchAddress(churchSettings, context, churchToSave);

                    context.SaveChanges();
                }
            }
        }
예제 #21
0
        private static void SetupPermissions(oikonomosEntities context, Person currentPerson, Church church, bool sysAdmin)
        {
            currentPerson.Permissions = (from pr in context.PersonChurches
                                  join r in context.Roles
                                    on pr.RoleId equals r.RoleId
                                  join permissions in context.PermissionRoles
                                    on r.RoleId equals permissions.RoleId
                                  where pr.PersonId == currentPerson.PersonId
                                    && r.ChurchId == church.ChurchId
                                  select permissions.PermissionId)
                                  .ToList();

            if (sysAdmin) currentPerson.Permissions.Add((int)Permissions.SystemAdministrator);
            var surname = currentPerson.Family.FamilyName;
            currentPerson.Church = church;
            currentPerson.ChurchId = church.ChurchId;
            var personChurch = currentPerson.PersonChurches.FirstOrDefault(pc => pc.ChurchId == currentPerson.ChurchId);
            Role role = null;
            if (personChurch != null)
            {
                role = context.Roles.First(r=>r.RoleId==personChurch.RoleId);
            }
            else if(currentPerson.HasPermission(Permissions.SystemAdministrator))
            {
                role = context.Roles.FirstOrDefault(r => r.ChurchId == church.ChurchId && r.Name.Contains("Administrator"));
                if(role==null)
                    throw new ApplicationException("Cannot set role for new church");
            }
            else
            {
                throw new ApplicationException("Cannot set role for new church");
            }
            currentPerson.RoleId = role.RoleId;
            currentPerson.Role = role;
            var churchIds = (from p in currentPerson.PersonChurches select p.ChurchId).ToList();
            currentPerson.Churches = context.Churches.Where(c => churchIds.Contains(c.ChurchId)).ToList();
        }
예제 #22
0
        public static SysAdminViewModel FetchSysAdminViewModel(Person currentPerson)
        {
            using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var sysAdminViewModel = new SysAdminViewModel();
                if (currentPerson.HasPermission(Permissions.SystemAdministrator))
                {
                    sysAdminViewModel.EmailTemplates = (from et in context.EmailTemplates
                                                        select new EmailTemplateViewModel
                                                        {
                                                            EmailTemplateId = et.EmailTemplateId,
                                                            Name = et.Name
                                                        }).ToList();

                    sysAdminViewModel.EmailTemplateId = sysAdminViewModel.EmailTemplates[0].EmailTemplateId;

                    sysAdminViewModel.ChurchId = currentPerson.ChurchId;
                    sysAdminViewModel.Churches = ChurchDataAccessor.FetchChurches(currentPerson);
                }
                return sysAdminViewModel;
            }
        }
예제 #23
0
        public static void SaveBulkSmsDetails(Person currentPerson, string username, string password)
        {
            if (currentPerson.HasPermission(common.Permissions.EditBulkSmsDetails))
            {
                using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
                {
                    ChurchSmsProvider currentSettings = (from c in context.ChurchSmsProviders
                                                         where c.ChurchId == currentPerson.ChurchId
                                                             && c.SmsProviderId == (int)SmsProviders.BulkSmsSouthAfrica
                                                         select c)
                                                        .FirstOrDefault();

                    if (currentSettings == null)
                    {
                        currentSettings = new ChurchSmsProvider();
                        currentSettings.Created = DateTime.Now;
                        currentSettings.SmsProviderId = (int)SmsProviders.BulkSmsSouthAfrica;
                        currentSettings.ChurchId = currentPerson.ChurchId;
                        context.ChurchSmsProviders.AddObject(currentSettings);
                    }

                    currentSettings.Username = username;
                    currentSettings.Password = password;

                    context.SaveChanges();
                }
            }
        }
예제 #24
0
        private static IQueryable<Person> FetchChurchList(Person currentPerson, bool search, string searchField, string searchString, oikonomosEntities context)
        {
            var showWholeChurchList = (currentPerson.HasPermission(Permissions.ViewChurchContactDetails));
            if (!showWholeChurchList)
            {
                showWholeChurchList = (from c in context.ChurchOptionalFields
                                       where c.ChurchId == currentPerson.ChurchId
                                       && c.OptionalFieldId == (int)OptionalFields.ShowWholeChurch
                                       select c.Visible).FirstOrDefault();
            }

            var personList = (from p in context.People
                              from c in p.PersonChurches
                              join permissions in context.PermissionRoles
                                  on c.RoleId equals permissions.RoleId
                              where c.ChurchId == currentPerson.ChurchId
                                  && permissions.PermissionId == (int)Permissions.Login
                              select p);

            if (!showWholeChurchList || (search && searchField == "homegroup"))
            {
                //Get the groups
                var groups = (from pg in context.PersonGroups
                              where pg.PersonId == currentPerson.PersonId
                              select pg.GroupId).ToList();

                personList = (from p in personList
                              from pg in p.PersonGroups
                              where groups.Contains(pg.GroupId)
                              select p);
            }
            else
            {
                if (search && searchField == "search")
                {
                    personList = Filters.ApplyNameSearch(searchString, personList);
                }
            }
            return personList;
        }
예제 #25
0
        public static PersonViewModel FetchPersonViewModel(int personId, Person currentPerson)
        {
            if (currentPerson.HasPermission(Permissions.EditChurchPersonalDetails) ||
               currentPerson.HasPermission(Permissions.EditGroupPersonalDetails) ||
               currentPerson.HasPermission(Permissions.EditOwnDetails))
            {
                using (var context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
                {
                    try
                    {
                        CheckThatChurchIdsMatch(personId, currentPerson, context);

                        var familyId = (from p in context.People
                                        where p.PersonId == personId
                                        select p.FamilyId).FirstOrDefault();

                        var person = FetchPerson(personId, context, currentPerson);

                        if(person==null)
                            throw new ApplicationException("Invalid PersonId");

                        //SetupPermissions(context, person, currentPerson.Church);
                        var personViewModel = new PersonViewModel
                                      {
                                          PersonId          = person.PersonId,
                                          FamilyId          = person.FamilyId,
                                          Firstname         = person.Firstname,
                                          Surname           = person.Family.FamilyName,
                                          Email             = person.Email,
                                          DateOfBirth_Value = person.DateOfBirth,
                                          Anniversary_Value = person.Anniversary,
                                          HomePhone         = person.Family.HomePhone,
                                          CellPhone         = person.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)OptionalFields.CellPhone)==null ? string.Empty    : person.PersonOptionalFields.First(c => c.OptionalFieldId == (int)OptionalFields.CellPhone).Value,
                                          WorkPhone         = person.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)OptionalFields.WorkPhone) == null ? string.Empty  : person.PersonOptionalFields.First(c => c.OptionalFieldId == (int)OptionalFields.WorkPhone).Value,
                                          Skype             = person.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)OptionalFields.Skype) == null ? string.Empty      : person.PersonOptionalFields.First(c => c.OptionalFieldId == (int)OptionalFields.Skype).Value,
                                          Twitter           = person.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)OptionalFields.Twitter) == null ? string.Empty    : person.PersonOptionalFields.First(c => c.OptionalFieldId == (int)OptionalFields.Twitter).Value,
                                          FacebookId        = person.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)OptionalFields.Facebook) == null ? string.Empty   : person.PersonOptionalFields.First(c => c.OptionalFieldId == (int)OptionalFields.Facebook).Value,
                                          Occupation        = person.Occupation,
                                          Gender            = person.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)OptionalFields.Gender) == null ? string.Empty     : person.PersonOptionalFields.First(c => c.OptionalFieldId == (int)OptionalFields.Gender).Value,
                                          Address1          = person.Family.Address.Line1,
                                          Address2          = person.Family.Address.Line2,
                                          Address3          = person.Family.Address.Line3,
                                          Address4          = person.Family.Address.Line4,
                                          Lat               = person.Family.Address.Lat,
                                          Lng               = person.Family.Address.Long,
                                          HasUsername       = person.Username != null,
                                          FindFamily        = false,
                                          GroupId           = 0,
                                          Site              = person.SiteId.HasValue ? person.Site.Name : "Select site...",
                                          HeardAbout        = person.PersonOptionalFields.FirstOrDefault(c => c.OptionalFieldId == (int)OptionalFields.HeardAbout) == null ? string.Empty : person.PersonOptionalFields.First(c => c.OptionalFieldId == (int)OptionalFields.HeardAbout).Value,
                                          RoleId            = person.RoleId,
                                          RoleName          = person.Role.Name
                                      };

                        SetGroupId(personId, currentPerson, context, personViewModel);

                        personViewModel.FamilyMembers = FetchFamilyMembers(personId, familyId, context);
                        personViewModel.SecurityRoles = Cache.SecurityRoles(context, currentPerson);

                        return personViewModel;
                    }
                    catch (Exception ex)
                    {
                        Email.SendExceptionEmail(ex);
                        return null;
                    }
                }
            }
            throw new Exception(ExceptionMessage.InvalidCredentials);
        }
예제 #26
0
        private static IQueryable<Person> FetchExtendedChurchList(Person currentPerson, oikonomosEntities context)
        {
            if (!currentPerson.HasPermission(Permissions.ViewChurchContactDetails))
            {
                return null;
            }

            return (from p in context.People
                    from c in p.PersonChurches
                    where c.ChurchId == currentPerson.ChurchId
                    select p);
        }
예제 #27
0
        public static void RemovePermissionsFromRole(Person currentPerson, int roleId, List<int> permissionIds)
        {
            if (!currentPerson.HasPermission(Permissions.EditPermissions))
                return;
            using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                var permissionRoles = (from p in context.PermissionRoles
                                       where p.RoleId == roleId
                                       && permissionIds.Contains(p.PermissionId)
                                       select p).ToList();
                if (permissionRoles != null)
                {
                    foreach (var permissionRole in permissionRoles)
                    {
                        context.DeleteObject(permissionRole);
                    }
                }

                context.SaveChanges();

            }
        }
예제 #28
0
        private static Person FetchPerson(int personId, oikonomosEntities context, Person currentPerson)
        {
            var sysAdmin = currentPerson!=null && currentPerson.Permissions!=null && currentPerson.HasPermission(Permissions.SystemAdministrator);
            var person = context.People.Include("PersonChurches.Role.PermissionRoles").First(p => p.PersonId == personId);
            SetupPermissions(context, person, sysAdmin);

            return person;
        }
예제 #29
0
        private static void EmailGroupLeader(PersonViewModel person, Person currentPerson, oikonomosEntities context, Church church, Person personToSave, bool addedToNewGroup)
        {
            if (personToSave.HasPermission(Permissions.NotifyGroupLeaderOfVisit) && person.GroupId > 0)
            {
                bool sendEmailToGroupLeader = person.PersonId == 0;
                var personGroup = (from pg in context.PersonGroups
                                   where pg.PersonId == personToSave.PersonId
                                   select pg).FirstOrDefault();

                if (personGroup == null)
                    return;
                else if (addedToNewGroup)
                    sendEmailToGroupLeader = true;

                if (personGroup.Group.LeaderId == currentPerson.PersonId || personGroup.Group.AdministratorId == currentPerson.PersonId)
                    sendEmailToGroupLeader = false;  //This is the groupleader

                if (sendEmailToGroupLeader)
                {
                    //Send email to the home group leader
                    var group = (from g in context.Groups
                                 where g.GroupId == person.GroupId
                                 select g).FirstOrDefault();

                    if (group != null)
                    {
                        if (group.Leader != null && group.Leader.HasValidEmail() && group.LeaderId != currentPerson.PersonId)
                        {
                            Email.SendNewVisitorEmail(person, church, group.Leader.Firstname, group.Leader.Family.FamilyName, group.Leader.Email);
                        }
                        else if (group.Administrator != null && group.Administrator.HasValidEmail() && group.LeaderId != currentPerson.PersonId)
                        {
                            Email.SendNewVisitorEmail(person, church, group.Administrator.Firstname, group.Administrator.Family.FamilyName, group.Administrator.Email);
                        }
                    }
                }
            }
        }
예제 #30
0
        public static List<SuburbViewModel> AddSuburb(Person currentPerson, string suburbName)
        {
            using (oikonomosEntities context = new oikonomosEntities(ConfigurationManager.ConnectionStrings["oikonomosEntities"].ConnectionString))
            {
                if (currentPerson.HasPermission(common.Permissions.AddSuburb))
                {//Check to see if it is not already in the db
                    var check = (from s in context.ChurchSuburbs
                                 where s.ChurchId == currentPerson.ChurchId
                                 && s.Suburb == suburbName
                                 select s).Count();
                    if (check == 0)
                    {
                        ChurchSuburb suburb = new ChurchSuburb();
                        suburb.Created = DateTime.Now;
                        suburb.Changed = DateTime.Now;
                        suburb.Suburb = suburbName;
                        suburb.ChurchId = currentPerson.ChurchId;

                        context.ChurchSuburbs.AddObject(suburb);
                        context.SaveChanges();
                    }

                }

                return (from s in context.ChurchSuburbs
                        where s.ChurchId == currentPerson.ChurchId
                        select new SuburbViewModel
                        {
                            SuburbId = s.ChurchSuburbId,
                            SuburbName = s.Suburb
                        }).ToList();
            }
        }