Esempio n. 1
0
        public void RegistrationDateKeyJoinsCorrectly()
        {
            var expectedRecordCount = 15;
            var year                = 2015;
            var rockContext         = new RockContext();
            var registrationService = new RegistrationService(rockContext);

            var minDateValue = TestDataHelper.GetAnalyticsSourceMinDateForYear(rockContext, year);
            var maxDateValue = TestDataHelper.GetAnalyticsSourceMaxDateForYear(rockContext, year);

            for (var i = 0; i < 15; i++)
            {
                var registration = BuildRegistration(rockContext,
                                                     TestDataHelper.GetRandomDateInRange(minDateValue, maxDateValue));

                registrationService.Add(registration);
            }

            rockContext.SaveChanges();

            var registrations = registrationService.
                                Queryable("AnalyticsSourceDate").
                                Where(i => i.ForeignKey == registrationForiegnKey).
                                Where(i => i.CreatedSourceDate.CalendarYear == year);

            Assert.AreEqual(expectedRecordCount, registrations.Count());
        }
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            // get the registration instance
            RegistrationInstance instance = new RegistrationInstanceService(rockContext).Get(GetAttributeValue(action, "RegistrationInstanceId", true).AsInteger());

            if (instance == null)
            {
                errorMessages.Add("The Registration Instance could not be determined or found!");
            }

            // determine the person that will be added to the registration instance
            Person person          = null;
            var    personAliasGuid = GetAttributeValue(action, "Registrar", true).AsGuidOrNull();

            if (personAliasGuid.HasValue)
            {
                person = new PersonAliasService(rockContext).Queryable()
                         .Where(a => a.Guid.Equals(personAliasGuid.Value))
                         .Select(a => a.Person)
                         .FirstOrDefault();
            }
            if (person == null || !person.PrimaryAliasId.HasValue)
            {
                errorMessages.Add("The Person for the Registrar value could not be determined or found!");
            }

            // Add registration
            if (!errorMessages.Any())
            {
                var registrationService = new RegistrationService(rockContext);

                var registration = new Registration();
                registrationService.Add(registration);
                registration.RegistrationInstanceId = instance.Id;
                registration.PersonAliasId          = person.PrimaryAliasId.Value;
                registration.FirstName         = person.NickName;
                registration.LastName          = person.LastName;
                registration.IsTemporary       = false;
                registration.ConfirmationEmail = person.Email;

                rockContext.SaveChanges();

                if (registration.Id > 0)
                {
                    string resultValue = registration.Id.ToString();
                    var    attribute   = SetWorkflowAttributeValue(action, "ResultAttribute", resultValue);
                    if (attribute != null)
                    {
                        action.AddLogEntry(string.Format("Set '{0}' attribute to '{1}'.", attribute.Name, resultValue));
                    }
                }
            }

            errorMessages.ForEach(m => action.AddLogEntry(m, true));

            return(!errorMessages.Any());
        }
        public ActionResult <RegistrationResponse> Post([FromBody] RegistrationRequest registrationRequest)
        {
            var result = _registrationService.Add(_mapper.Map <Registration>(registrationRequest));

            return(result != null?
                   Ok(new RegistrationResponse()
            {
                RegistrationId = result.ToString()
            }) :
                       BadRequest() as ActionResult);
        }
Esempio n. 4
0
        public void RegistrationDateKeySavesCorrectlyWhenNull()
        {
            var rockContext         = new RockContext();
            var registrationService = new RegistrationService(rockContext);

            var registrationRequest = BuildRegistration(rockContext, null);

            registrationService.Add(registrationRequest);
            rockContext.SaveChanges();

            var connectionRequestId = registrationRequest.Id;

            // We're bypassing the model because the model doesn't user the ConnectionRequestDateKey from the database,
            // but it still needs to be correct for inner joins to work correctly.
            var result = rockContext.Database.
                         SqlQuery <int>($"SELECT CreatedDateKey FROM Registration WHERE Id = {connectionRequestId}").First();

            Assert.AreEqual(Convert.ToInt32(RockDateTime.Now.ToString("yyyyMMdd")), result);
        }
Esempio n. 5
0
        public void RegistrationDateKeySavesCorrectly()
        {
            var rockContext         = new RockContext();
            var registrationService = new RegistrationService(rockContext);

            var registration = BuildRegistration(rockContext, Convert.ToDateTime("3/15/2010"));

            registrationService.Add(registration);
            rockContext.SaveChanges();

            var registrationId = registration.Id;

            // We're bypassing the model because the model doesn't user the RegistrationDateKey from the database,
            // but it still needs to be correct for inner joins to work correctly.
            var result = rockContext.Database.
                         SqlQuery <int>($"SELECT CreatedDateKey FROM Registration WHERE Id = {registrationId}").First();

            Assert.AreEqual(20100315, result);
        }
        protected void lbRegister_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();

            // get the person who was passed in for the registration registrar
            Person person = null;

            Guid personGuid = Guid.Empty;

            if (Request["PersonGuid"] != null)
            {
                personGuid = Request["PersonGuid"].AsGuid();

                person = new PersonService(_rockContext).Get(personGuid);
            }

            if (person == null)
            {
                lErrors.Text = "<div class='alert alert-warning'>Invalid person guid was passed.</div>";
                return;
            }

            // get event item
            int eventItemOccurrenceId = hfSelectedEventId.Value.AsInteger();

            // find registration
            var eventGroup = new EventItemOccurrenceGroupMapService(_rockContext).Queryable()
                             .Where(m => m.EventItemOccurrenceId == eventItemOccurrenceId)
                             .Select(m => m.Group)
                             .FirstOrDefault();

            var registrationLinkages = eventGroup.Linkages.ToList();


            if (registrationLinkages.Count() == 0)
            {
                lErrors.Text = "<div class='alert alert-warning'>No registration instances exists for this event.</div>";
                return;
            }

            EventItemOccurrenceGroupMap registrationLinkage = registrationLinkages.First();

            // create new registration
            var registrationService = new RegistrationService(rockContext);

            Registration registration = new Registration();

            registrationService.Add(registration);

            registration.RegistrationInstanceId = registrationLinkage.RegistrationInstanceId.Value;
            registration.ConfirmationEmail      = ebEmailReminder.Text;
            registration.PersonAliasId          = person.PrimaryAliasId;
            registration.FirstName   = person.NickName;
            registration.LastName    = person.LastName;
            registration.IsTemporary = true;

            // add registrants
            foreach (int registrantId in cblRegistrants.SelectedValuesAsInt)
            {
                RegistrationRegistrant registrant = new RegistrationRegistrant();
                registrant.PersonAliasId = registrantId;
                registration.Registrants.Add(registrant);
            }

            rockContext.SaveChanges();

            // redirect to registration page
            var queryParams = new Dictionary <string, string>();

            queryParams.Add("RegistrationInstanceId", registrationLinkage.RegistrationInstanceId.ToString());
            queryParams.Add("RegistrationId", registration.Id.ToString());
            queryParams.Add("StartAtBeginning", GetAttributeValue("StartRegistrationAtBeginning"));

            if (!string.IsNullOrWhiteSpace(registrationLinkage.UrlSlug))
            {
                queryParams.Add("Slug", registrationLinkage.UrlSlug);
            }

            if (registrationLinkage.Group != null)
            {
                queryParams.Add("GroupId", registrationLinkage.GroupId.ToString());
            }

            NavigateToLinkedPage("RegistrationPage", queryParams);
        }