Пример #1
0
 void Instance_PublishingContent(object sender, EPiServer.ContentEventArgs e)
 {
     if (e.Content as ParticipantBlock != null)
     {
         ParticipantBlock participant = (e.Content as ParticipantBlock);
         ParticipantLog.AddLogText("Saved", "Participant saved with e-mail " + participant.Email + " and status " + participant.AttendStatus, participant);
     }
 }
Пример #2
0
        public override IParticipant GenerateParticipant(ContentReference EventPageBase, string email, bool sendMail, string xform, string logText)
        {
            var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>();

            EventPageBase EventPageBaseData = contentRepository.Get <EventPageBase>(EventPageBase);

            ContentFolder participantsFolder = GetOrCreateParticipantsFolder(EventPageBase);

            ParticipantBlock newParticipant = contentRepository.GetDefault <ParticipantBlock>(participantsFolder.ContentLink);

            (newParticipant as IContent).Name = email;
            newParticipant.Code          = GenerateCode();
            newParticipant.XForm         = xform;
            newParticipant.EventPage     = EventPageBase as PageReference;
            newParticipant.Email         = email;
            newParticipant.AttendStatus  = (GetAvailableSeats(EventPageBase) > 0) ? AttendStatus.Confirmed.ToString() : AttendStatus.Submitted.ToString();
            newParticipant.Price         = EventPageBaseData.EventDetails.Price;
            newParticipant.Username      = EPiServerProfile.Current.UserName;
            newParticipant.DateSubmitted = DateTime.Now;

            ParticipantEventArgs e1 = new ParticipantEventArgs();

            e1.CurrentParticipant = newParticipant;
            e1.CancelEvent        = false;
            e1.SendMail           = sendMail;
            RaiseOnAddingParticipant(e1);

            if (e1.CancelEvent == true)
            {
                return(null);
            }

            contentRepository.Save(newParticipant as IContent, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);
            newParticipant = ParticipantLog.AddLogTextAndSave("Generated", logText, newParticipant as ParticipantBlock) as ParticipantBlock;
            newParticipant = ParticipantLog.AddLogTextAndSave("Status", "Status set to " + newParticipant.AttendStatus, newParticipant as IParticipant) as ParticipantBlock;

            sendMail = e1.SendMail;

            ParticipantEventArgs e2 = new ParticipantEventArgs();

            e2.CurrentParticipant = newParticipant;
            e2.CancelEvent        = false;
            e2.SendMail           = sendMail;
            RaiseOnAddedParticipant(e2);

            sendMail = e1.SendMail;

            if (sendMail)
            {
                SendStatusMail(newParticipant);
            }



            return(newParticipant);
        }
        public async Task <IActionResult> Save(ParticipantLogModel model)
        {
            byte[] photoBytes = null;
            if (!string.IsNullOrEmpty(model.PhotoBase64))
            {
                photoBytes = Convert.FromBase64String(model.PhotoBase64);
            }

            var priorLog = await _repo.GetLastParticipantLogForParticipantId(model.ParticipantLog.ParticipantId);

            var currentDate = DateTime.Now;

            if (priorLog != null)
            {
                var sunday             = DayOfWeek.Sunday;
                var saturday           = DayOfWeek.Saturday;
                var sundayOfThisWeek   = currentDate.Date.AddDays(sunday - currentDate.DayOfWeek);
                var saturdayOfThisWeek = currentDate.Date.AddDays(saturday - currentDate.DayOfWeek);
                if (priorLog.DateSubmitted >= sundayOfThisWeek && priorLog.DateSubmitted <= saturdayOfThisWeek)
                {
                    return(BadRequest("You may not submit more than once a week."));
                }
            }

            var participantLog = new ParticipantLog
            {
                CurrentWeight      = model.ParticipantLog.CurrentWeight,
                HealthInitiativeId = model.HealthInitiativeId,
                ParticipantId      = model.ParticipantLog.ParticipantId,
                Photo         = photoBytes,
                DateSubmitted = DateTime.Now,
                Points        = 1
            };

            if (priorLog != null && priorLog.CurrentWeight > participantLog.CurrentWeight)
            {
                participantLog.Points += 1;
            }

            if (priorLog != null && participantLog.CurrentWeight <= priorLog.HealthParticipant.IndividualWeightLossGoal)
            {
                participantLog.Points += 5;
            }

            if (photoBytes != null)
            {
                participantLog.Points += 3;
            }

            await _repo.AddParticipantLog(participantLog);

            return(Ok());
        }
        public async Task AddParticipantLog(ParticipantLog log)
        {
            await _context.ParticipantLogs.AddAsync(log);

            await _context.SaveChangesAsync();
        }
Пример #5
0
        public override ActionResult Index(MyPageBlock currentBlock)
        {
            var model = new MyPageBlockViewModel <MyPageBlock>(currentBlock);

            string email       = Request.QueryString["email"];
            string code        = Request.QueryString["code"];
            string cancelEvent = Request.QueryString["cancelEvent"];
            string editEvent   = Request.QueryString["editEvent"];

            if (email.IsNullOrEmpty() || code.IsNullOrEmpty())
            {
                return(View("~/Modules/BVNetwork.Attend/Views/Blocks/MyPageBlock/EmptyView.cshtml", model));  //No results found, code not matching email.
            }
            var currentParticipant = BVNetwork.Attend.Business.API.AttendRegistrationEngine.GetParticipant(email, code);

            if (currentParticipant == null)
            {
                return(View("~/Modules/BVNetwork.Attend/Views/Blocks/MyPageBlock/EmptyView.cshtml", model));
            }


            ////Set name
            if (currentParticipant != null)
            {
                model.ParticipantName = currentParticipant.Username;
            }


            //Cancel event?
            if (cancelEvent == "true" && currentParticipant != null)
            {
                var entry = (currentParticipant as BlockData).CreateWritableClone() as ParticipantBlock;
                if (entry.AttendStatus != AttendStatus.Cancelled.ToString())
                {
                    entry.AttendStatus = AttendStatus.Cancelled.ToString();
                    ParticipantLog.AddLogText("Status change", "Status changed to ", entry);
                    _contentRepository.Save(entry as IContent, SaveAction.Publish, AccessLevel.NoAccess);
                    AttendRegistrationEngine.SendStatusMail(entry);
                    return(View("~/Modules/BVNetwork.Attend/Views/Blocks/MyPageBlock/Cancelled.cshtml", model));
                }
            }

            model.RegistrationCode = code;
            model.Email            = email;
            model.CurrentBlock     = currentBlock;

            //Edit event?
            if (editEvent == "true" && currentParticipant != null)
            {
                model.CurrentEvent     = _contentRepository.Get <EventPageBase>(currentParticipant.EventPage);
                model.PredefinedValues = currentParticipant.XForm;
                return(View("~/Modules/BVNetwork.Attend/Views/Blocks/MyPageBlock/EditEvent.cshtml", model));  //Edit event
            }


            var entries = BVNetwork.Attend.Business.API.AttendRegistrationEngine.GetParticipantByEmail(email);

            model.AllEntries      = new List <ParticipantBlock>();
            model.UpcomingEntries = new List <ParticipantBlock>();
            model.PastEntries     = new List <ParticipantBlock>();

            foreach (var entry in entries)
            {
                if (entry.EventPage == null || entry.EventPage == PageReference.EmptyReference)
                {
                    continue;
                }
                model.AllEntries.Add(entry as ParticipantBlock);

                var eventPage = BVNetwork.Attend.Business.API.AttendRegistrationEngine.GetEventPageBase(entry);
                if ((eventPage).EventDetails.EventEnd > DateTime.Now) //&& (entry.AttendStatus.Contains(AttendStatus.Confirmed.ToString()) || entry.AttendStatus == AttendStatus.Submitted.ToString() || entry.AttendStatus == AttendStatus.Standby.ToString()))
                {
                    model.UpcomingEntries.Add(entry as ParticipantBlock);
                }
                else
                {
                    model.PastEntries.Add(entry as ParticipantBlock);
                }
            }
            model.UpcomingEntries = model.UpcomingEntries.OrderBy(x => x.EventPageData().EventDetails.EventEnd).ToList();

            if (model.UpcomingEntries.Count == 0)
            {
                return(View("~/Modules/BVNetwork.Attend/Views/Blocks/MyPageBlock/EmptyView.cshtml", model));  //No results found, code not matching email.
            }

            var pageRouteHelper = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance <IPageRouteHelper>();

            model.CurrentPage = pageRouteHelper.Page;

            return(View("~/Modules/BVNetwork.Attend/Views/Blocks/MyPageBlock/Index.cshtml", model));  //No results found, code not matching email.
        }