Exemplo n.º 1
0
 public ChangeRequestViewModel.AppUser GetChangeRequestAppUser(CCGAppUser appUser)
 {
     return(new ChangeRequestViewModel.AppUser
     {
         Id = appUser.Id, FullName = appUser.FullName,
     });
 }
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            CCGAppUser ccgAppUser = unitOfWork.AppUserRepository.FindUserById(id);

            if (ccgAppUser == null)
            {
                return(HttpNotFound());
            }

            var ccgs   = unitOfWork.CCGRepository.FindAll();
            var ccgsVM = Mapper.Map <IList <CCGViewModel> >(ccgs);

            _ccgService.SetCCGViewName(ccgsVM);

            ViewBag.CCGs = new SelectList(ccgsVM, "Id", "CcgName", ccgAppUser.CcgId);
            var viewModel = Mapper.Map <EditCcgAppUserViewModel>(ccgAppUser);

            // Find roles and assign to EditRoles in view model
            viewModel.EditRoles = _service.SetViewModelEditRoles(ccgAppUser.Id);

            return(View(viewModel));
        }
        public ActionResult DeleteConfirmed(DeleteCcgAppUserViewModel viewModel)
        {
            CCGAppUser ccgAppUser = unitOfWork.AppUserRepository.FindUserById(viewModel.Id);

            unitOfWork.AppUserRepository.RemoveUser(ccgAppUser);

            return(Redirect(viewModel.ReturnUrl));
        }
Exemplo n.º 4
0
        public IEnumerable <ContactRecord> GetContactRecords(int?memberId, int?ccgId, bool getAll,
                                                             bool archive, CCGAppUser user, DateRangeFilter dateRangeFilter,
                                                             string query, out ActionResult actionResult)
        {
            actionResult = null;
            DateTime dateTimeOffset;

            GetOffsetDate(dateRangeFilter, out dateTimeOffset);

            // Prevents having one query for search and one for no search.
            if (query == null)
            {
                query = "";
            }

            // Get contact records for specific member
            if (memberId != null)
            {
                return(unitOfWork.ContactRecordRepository
                       .GetContactRecords(c => c.CCGMemberId == memberId &&
                                          c.Archive == archive &&
                                          c.Timestamp > dateTimeOffset &&
                                          c.ContactType.Name != _prayerRequestName &&
                                          (c.Subject.Contains(query) || c.Comments.Contains(query))).ToList());
            }
            // Get all contact records for a CCG passed to parameter
            if (ccgId != null && ccgId != -1)
            {
                return(unitOfWork.ContactRecordRepository
                       .GetContactRecords(c => c.CCGMember.CcgId == ccgId &&
                                          c.Archive == archive &&
                                          c.Timestamp > dateTimeOffset &&
                                          c.ContactType.Name != _prayerRequestName &&
                                          (c.Subject.Contains(query) || c.Comments.Contains(query))).ToList());
            }
            // Get all contact records; admin or leadership only
            if (getAll)
            {
                if (!CanViewAllRecords(user.Email))
                {
                    // If denied permission, get all records for user's CCG only
                    return(GetContactRecordsForCcg(archive, user, dateTimeOffset,
                                                   query, out actionResult).ToList());
                }

                // Gets all contact records.
                return(unitOfWork.ContactRecordRepository
                       .GetContactRecords(c => c.Archive == archive &&
                                          c.Timestamp > dateTimeOffset &&
                                          c.ContactType.Name != _prayerRequestName &&
                                          (c.Subject.Contains(query) || c.Comments.Contains(query))).ToList());
            }

            // Get all contact records for the user's CCG only
            return(GetContactRecordsForCcg(archive, user, dateTimeOffset, query,
                                           out actionResult).ToList());
        }
Exemplo n.º 5
0
 private void AddNameAsClaim(CCGAppUser user)
 {
     if (user != null)
     {
         // Adds claim with name which is appended to the cookie. This allows
         // for the display of the user's name in the nav bar.
         UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, user.FirstName));
     }
 }
Exemplo n.º 6
0
 public void SetIsMemberDeaconFlag(IList <ListMembersViewModel> memberList, CCGAppUser user)
 {
     foreach (var member in memberList)
     {
         member.IsUserMemberDeacon = user.CCG != null && AuthHelper.IsMemberDeacon(user.CCG.CCGName, member.CCG.CCGName);
         if (!member.IsUserMemberDeacon)
         {
             SetPhoneHrefLinks(member);
         }
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Updates the user's properties with new data.
 /// </summary>
 /// <param name="viewModel"></param>
 /// <param name="user"></param>
 public void UpdateUserProperties(EditCcgAppUserViewModel viewModel, CCGAppUser user)
 {
     user.FirstName            = viewModel.FirstName;
     user.LastName             = viewModel.LastName;
     user.CcgId                = viewModel.CcgId;
     user.PhoneNumber          = viewModel.PhoneNumber;
     user.CellNumber           = viewModel.CellNumber;
     user.ChangeRequestManager = viewModel.ChangeRequestManager;
     user.EmailAddress         = viewModel.EmailAddress;
     user.Email                = viewModel.SharePointEmail;
 }
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CCGAppUser ccgAppUser = unitOfWork.AppUserRepository.FindUserById(id);

            if (ccgAppUser == null)
            {
                return(HttpNotFound());
            }

            return(AutoMapView <DeleteCcgAppUserViewModel>(ccgAppUser, View()));
        }
        private EmailContact GetPassAlongEmail(ContactRecord record,
                                               CCGAppUser user, UnitOfWork db, StringBuilder sb)
        {
            //
            // ***TEST ONLY***
            // I've replace the user's email address with
            // literal string for testing only
            //
            string toEmailAddress = "*****@*****.**";
            //string toEmailAddress = pastor.Email;
            //

            var email = new EmailContact();

            email.SenderName       = user.FullName;
            email.FromEmailAddress = user.Email;
            email.ToEmailAddress   = toEmailAddress;
            email.Subject          = $"From Deacon {user.FullName}";

            // For testing, the email to the pastor is formatted
            // like this:

            // Subject: From Deacon Paul Bolden
            // Body:
            // [Pass along message from deacon]
            // [Contact record subject]
            // [Contact record comments if not private]


            sb.Append(record.PassAlongComments);
            sb.Append(Environment.NewLine + Environment.NewLine);
            sb.Append(record.Subject);
            sb.Append(Environment.NewLine + Environment.NewLine);
            if (!record.Private)
            {
                sb.Append(record.Comments);
            }

            // record.PassAlongComments;

            // What do we want to email message to the pastor to say?
            // Should the subject be the same as the contact record
            // or should it be something like "From Deacon Paul"?

            sb.Clear();

            return(email);
        }
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            CCGAppUser ccgAppUser = unitOfWork.AppUserRepository.FindUserById(id);

            if (ccgAppUser == null)
            {
                return(HttpNotFound());
            }

            ViewBag.Roles = unitOfWork.AppUserRepository.GetUserRoles(ccgAppUser.Id);

            var viewModel = Mapper.Map <DetailsCcgAppUserViewModel>(ccgAppUser);

            _service.SetHrefLinkForPhoneNumbers(viewModel);
            _service.SetImgSrcAndHasPhotoFlag(viewModel);

            return(View(viewModel));
        }
Exemplo n.º 11
0
        private IEnumerable <ContactRecord> GetContactRecordsForCcg(bool archive,
                                                                    CCGAppUser user, DateTime dateTimeOffset, string query,
                                                                    out ActionResult actionResult)
        {
            actionResult = null;

            // find the user's assigned CCG
            var ccg = unitOfWork.CCGRepository.Find(c => c.Id == user.CcgId);

            if (ccg == null)
            {
                actionResult = new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                return(null);
            }

            // find contact records of members in the user's CCG
            return(unitOfWork.ContactRecordRepository.GetContactRecords(
                       c => c.CCGMember.CcgId == ccg.Id &&
                       c.Archive == archive &&
                       c.Timestamp > dateTimeOffset &&
                       c.ContactType.Name != _prayerRequestName &&
                       (c.Subject.Contains(query) || c.Comments.Contains(query))).ToList());
        }
Exemplo n.º 12
0
        public void FilterMembers(ref List <CCGMember> members, MemberFilter filter, CCGAppUser user = null)
        {
            if (members == null)
            {
                return;
            }

            var timespan = TimeSpan.Zero;

            switch (filter)
            {
            case MemberFilter.NoPhoto:
            {
                members.RemoveAll(m => _photoService.DoesMemberHavePhoto(m.Id));
                return;
            }

            case MemberFilter.ActiveMember:
            {
                members.RemoveAll(m => !m.IsMemberActive);
                return;
            }

            case MemberFilter.InactiveMember:
            {
                members.RemoveAll(m => m.IsMemberActive);
                return;
            }

            case MemberFilter.NeedsCommunion:
            {
                // Get all needs communion records
                var needsCommunionService = new NeedsCommunionService(unitOfWork);
                var records = unitOfWork.NeedsCommunionRepository
                              .FindAll(r => r.Member.CcgId == user.CcgId)
                              .OrderByDescending(r => r.Timestamp)
                              .ToList();

                // Filter by last 30 days
                needsCommunionService.FilterByDateRange(records, CommunionDateRange.Last30Days);

                // Filtering existing list is convoluted. Easier to wipe out list and re-populate.
                members.Clear();
                if (user == null)
                {
                    return;
                }
                members.AddRange(records.Select(record => unitOfWork.MemberRepository.FindMemberById((record.MemberId))));

                // nix duplicates
                var recordsHashSet = new HashSet <CCGMember>(members, new CCGMemberEqComparer());
                members = recordsHashSet.ToList();

                return;
            }

            case MemberFilter.NoContactForOneMonth:
            {
                timespan = TimeSpan.FromDays(30);
                break;
            }

            case MemberFilter.NoContactForTwoMonths:
            {
                timespan = TimeSpan.FromDays(60);
                break;
            }

            case MemberFilter.NoContactForThreeMonths:
            {
                timespan = TimeSpan.FromDays(90);
                break;
            }

            case MemberFilter.NoContactForSixMonths:
            {
                timespan = TimeSpan.FromDays(180);
                break;
            }

            case MemberFilter.None:
            {
                return;
            }

            default:
            {
                throw new ArgumentOutOfRangeException(nameof(filter), filter, null);
            }
            }

            if (timespan != TimeSpan.Zero)
            {
                var dateTimeOffset = DateTime.Now.Subtract(timespan);

                // Remove all that are older than the offset date
                // '>' means more recent. Eg, if the 'last contact date'
                // is 15 days ago and the offset date is 30 days ago,
                // the contact will be removed. 3/15/17 > 3/15/16
                members.RemoveAll(cr => cr.LastDateContacted >= dateTimeOffset);
            }
        }
Exemplo n.º 13
0
        public IEnumerable <ContactRecord> GetPrayerRequests(int?memberId,
                                                             DateTime dateTimeOffset, int?ccgId, bool getAll, CCGAppUser user, string query)
        {
            // Prevents having one query for search and one for no search.
            if (query == null)
            {
                query = "";
            }

            var contactType = GetPrayerRequestContactType();

            if (memberId != null)
            {
                // Get all contact requests that are prayer requests for a member
                return(unitOfWork.ContactRecordRepository
                       .GetContactRecords(cr => cr.ContactTypeId == contactType.Id &&
                                          cr.CCGMemberId == memberId && cr.Timestamp > dateTimeOffset &&
                                          (cr.Subject.Contains(query) || cr.Comments.Contains(query))).ToList());
            }
            if (ccgId != null && ccgId != -1)
            {
                // Get all contact requests that are prayer requests for a CCG
                return(unitOfWork.ContactRecordRepository
                       .GetContactRecords(cr => cr.ContactTypeId == contactType.Id &&
                                          cr.CCGMember.CcgId == ccgId && cr.Timestamp > dateTimeOffset &&
                                          (cr.Subject.Contains(query) || cr.Comments.Contains(query))).ToList());
            }
            if (!getAll)
            {
                // Get prayer request for deacon's ccg only
                return(unitOfWork.ContactRecordRepository
                       .GetContactRecords(cr => cr.ContactTypeId == contactType.Id &&
                                          cr.AppUser.CcgId == user.CcgId && cr.Timestamp > dateTimeOffset &&
                                          (cr.Subject.Contains(query) || cr.Comments.Contains(query))).ToList());
            }

            // getAll is true
            // Get all contact requests that are prayer requests
            return(unitOfWork.ContactRecordRepository
                   .GetContactRecords(cr => cr.ContactTypeId == contactType.Id &&
                                      cr.Timestamp > dateTimeOffset &&
                                      (cr.Subject.Contains(query) || cr.Comments.Contains(query))).ToList());
        }
Exemplo n.º 14
0
        public List <ContactRecord> PrayerRequests(int?memberId, int?ccgId,
                                                   DateRangeFilter dateRange, ContactsSort contactsSort,
                                                   bool getAll = false, string query = null, CCGAppUser appuser = null)
        {
            // Get principal user obj
            var user = unitOfWork.AppUserRepository.FindUserByEmail(appuser.UserName);

            DateTime dateTimeOffset;

            GetOffsetDate(dateRange, out dateTimeOffset);

            List <ContactRecord> prayerRequests;

            // determine if user is leadership, pastor or admin
            AppUserRole[] roles = new AppUserRole[] { AppUserRole.Admin,
                                                      AppUserRole.DeaconLeadership,
                                                      AppUserRole.Pastor };
            // get all if user is admin, leadership, or pastor
            getAll = AuthHelper.IsInRole(appuser.UserName, roles);

            // not leadership so only get prayer requests within ccg
            if (!getAll && ccgId == null)
            {
                ccgId = user.CcgId;
            }

            prayerRequests = GetPrayerRequests(memberId,
                                               dateTimeOffset, ccgId, getAll, user, query).ToList();

            // Sort prayer requests
            return(SortContactRecords(contactsSort, prayerRequests).ToList());
        }