public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CCGMember ccgMember = unitOfWork.MemberRepository.FindMemberById(id);

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

            // Only admins and leadership can edit member data
            if (!AuthHelper.HasAdminAccess(User.Identity.Name))
            {
                return(View("EditDenied"));
            }
            var ccgs   = unitOfWork.CCGRepository.FindAll();
            var ccgsVM = Mapper.Map <IList <CCGViewModel> >(ccgs);

            _ccgService.SetCCGViewName(ccgsVM);
            ViewBag.CCGs = new SelectList(ccgsVM, "Id", "CcgName");

            var ccgMemberVM = Mapper.Map <EditMemberViewModel>(ccgMember);

            return(View(ccgMemberVM));
        }
 /// <summary>
 /// Maps EditMemberViewModel to CCGMember.
 /// Manual mapping is safer than auto mapping for updates.
 /// </summary>
 /// <param name="viewModel"></param>
 /// <param name="member"></param>
 /// <returns></returns>
 private void MapEditMemberVMToMember(EditMemberViewModel viewModel, CCGMember member)
 {
     member.LastName        = viewModel.LastName;
     member.FirstName       = viewModel.FirstName;
     member.Title           = viewModel.Title;
     member.Suffix          = viewModel.Suffix;
     member.Address         = viewModel.Address;
     member.City            = viewModel.City;
     member.State           = viewModel.State;
     member.ZipCode         = viewModel.ZipCode;
     member.PhoneNumber     = viewModel.PhoneNumber;
     member.CellPhoneNumber = viewModel.CellPhoneNumber;
     member.BirthDate       = viewModel.BirthDate;
     member.EmailAddress    = viewModel.EmailAddress;
     member.DateJoinedZion  = viewModel.DateJoinedZion;
     member.AnniversaryDate = viewModel.AnniversaryDate;
     member.CcgId           = viewModel.CcgId;
     member.IsMemberActive  = viewModel.IsMemberActive;
 }
        private DateTime GetEventDate(CalendarEvents calEvent, CCGMember member)
        {
            DateTime eventDate = DateTime.Today;

            switch (calEvent)
            {
            case CalendarEvents.Birthday:
            {
                if (member.BirthDate != null)
                {
                    eventDate = member.BirthDate.Value;
                }
                break;
            }

            case CalendarEvents.WeddingAnniversary:
            {
                if (member.AnniversaryDate != null)
                {
                    eventDate = member.AnniversaryDate.Value;
                }
                break;
            }

            case CalendarEvents.JoinedZionAnniversary:
            {
                if (member.DateJoinedZion != null)
                {
                    eventDate = member.DateJoinedZion.Value;
                }
                break;
            }

            default:
            {
                return(new DateTime());
            }
            }

            // Updates year to current year for the event date.
            // Eg., 5-25-1961 ==> 5-25-2017 (current year)
            return(new DateTime(_startDate.Year, eventDate.Month, eventDate.Day));
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CCGMember ccgMember = unitOfWork.MemberRepository.FindMemberById((int)id);

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

            // Only admins and leadership can delete member
            if (!AuthHelper.HasAdminAccess(User.Identity.Name))
            {
                return(View("DeleteDenied"));
            }

            return(AutoMapView <DeleteMemberViewModel>(ccgMember, View()));
        }
        private CalendarEvent SetCalendarEventProps(CCGMember member, CalendarEvents calEvent)
        {
            _counter++;
            var eventDate = GetEventDate(calEvent, member);
            var eventName = GetEventName(calEvent);

            return(new CalendarEvent
            {
                Id = _counter,
                Title = $"{eventName} - {member.LastName}",
                Description = $"{member.FirstName} {member.LastName}'s {eventName}",
                FirstName = member.FirstName,
                LastName = member.LastName,
                EventDate = eventDate,
                DateString = eventDate.ToLongDateString(),
                Url = $"/CcgMembers/Details/{member.Id}",
                PhoneNumber = member.PhoneNumber,
                CellPhoneNumber = member.CellPhoneNumber,
                EmailAddress = member.EmailAddress,
            });
        }