Beispiel #1
0
 public void Should_Get_PrimaryFundList()
 {
     using (var db = CMSDataContext.Create(DatabaseFixture.Host))
     {
         var fundList = OnlineRegPersonModel.PrimaryFundList(db);
         fundList.Length.ShouldBe(2);
     }
 }
Beispiel #2
0
 public string PrepareSummaryInfo(OnlineRegPersonModel p)
 {
     this.p = p;
     om     = p.GetOrgMember();
     ti     = p.Parent.Transaction;
     if (ShowTransaction)
     {
         ts = om.TransactionSummary(this.db);
     }
     rr = p.person.GetRecReg();
 }
Beispiel #3
0
 // Set suggested giving fee for an indidividual person
 private static void CheckSetFee(OnlineRegModel m, OnlineRegPersonModel p)
 {
     if (m.OnlineGiving() && p.setting.ExtraValueFeeName.HasValue())
     {
         var f     = CmsWeb.Models.OnlineRegPersonModel.Funds().SingleOrDefault(ff => ff.Text == p.setting.ExtraValueFeeName);
         var evamt = p.person.GetExtra(p.setting.ExtraValueFeeName).ToDecimal();
         if (f != null && evamt > 0)
         {
             p.FundItem[f.Value.ToInt()] = evamt;
         }
     }
 }
Beispiel #4
0
        public void ShouldDetectDuplicateGift()
        {
            var requestManager = FakeRequestManager.Create();
            var testOrg        = new Organization()
            {
                OrganizationName   = "MockMasterName",
                RegistrationTitle  = "MockMasterTitle",
                Location           = "MockLocation",
                RegistrationTypeId = RegistrationTypeCode.JoinOrganization,
                Limit = 0
            };
            var org = FakeOrganizationUtils.MakeFakeOrganization(requestManager, testOrg);

            using (var db = CMSDataContext.Create(DatabaseFixture.Host))
            {
                Transaction t = new Transaction()
                {
                    TransactionDate    = DateTime.Now,
                    First              = "Chester",
                    Last               = "Tester",
                    Amt                = 30,
                    Testing            = true,
                    TransactionGateway = "Sage",
                    OrgId              = org.org.OrganizationId
                };
                db.Transactions.InsertOnSubmit(t);
                db.SubmitChanges();
            }

            OnlineRegPersonModel person = new OnlineRegPersonModel(db)
            {
                FirstName = "Chester",
                LastName  = "Tester"
            };

            OnlineRegModel om = FakeOrganizationUtils.GetFakeOnlineRegModel(org.org.OrganizationId);

            om.List = new List <OnlineRegPersonModel>()
            {
                person
            };
            om.CheckDuplicateGift(30).ShouldNotBeNull();
            FakeOrganizationUtils.DeleteOrg(org.org.OrganizationId);
        }
Beispiel #5
0
        public void Should_Get_SecondaryFundList()
        {
            int fundCount;

            using (var db = CMSDataContext.Create(DatabaseFixture.Host))
            {
                var funds = db.ContributionFunds.Where(c => c.ShowList == FundShowListCode.Primary).ToList();
                fundCount = funds.Count();
                foreach (var item in funds)
                {
                    item.ShowList = FundShowListCode.Secondary;
                }
                db.SubmitChanges();

                var fundList = OnlineRegPersonModel.SecondaryFundList(db);
                fundList.Length.ShouldBe(fundCount);

                foreach (var item in funds)
                {
                    item.ShowList = FundShowListCode.Primary;
                }
                db.SubmitChanges();
            }
        }
Beispiel #6
0
        public ActionResult Index(int?id, bool?testing, string email, bool?nologin, bool?login, string registertag, bool?showfamily, int?goerid, int?gsid, string source)
        {
            if (Util.IsDebug())
            {
                var q = from om in DbUtil.Db.OrganizationMembers
                        where om.OrganizationId == 89539 && om.PeopleId == 828612
                        select om;
                foreach (var om in q)
                {
                    om.Drop(DbUtil.Db, addToHistory: false);
                }
                //        DbUtil.Db.PurgePerson(om.PeopleId);
                //                var dr = DbUtil.Db.People.SingleOrDefault(mm => mm.Name == "David Roll");
                //                if (dr != null)
                //                    foreach (var mm in dr.Family.People)
                //                        if (mm.PeopleId != dr.PeopleId)
                //                            DbUtil.Db.PurgePerson(mm.PeopleId);
                DbUtil.Db.SubmitChanges();
            }
            if (DbUtil.Db.Roles.Any(rr => rr.RoleName == "disabled"))
            {
                return(Content("Site is disabled for maintenance, check back later"));
            }
            Response.NoCache();
            if (!id.HasValue)
            {
                return(Message("no organization"));
            }

            MobileAppMenuController.Source = source;
            var m = new OnlineRegModel()
            {
                Orgid = id
            };

            if (m.org == null && m.masterorg == null)
            {
                return(Message("invalid registration"));
            }

            GoerSupporter goerSupporter = null; // used for mission trips

            if (m.masterorg != null)
            {
                if (!OnlineRegModel.UserSelectClasses(m.masterorg).Any())
                {
                    return(Message("no classes available on this org"));
                }
            }
            else if (m.org != null)
            {
                if ((m.org.RegistrationTypeId ?? 0) == RegistrationTypeCode.None)
                {
                    return(Message("no registration allowed on this org"));
                }
                if (m.org.IsMissionTrip == true)
                {
                    if (gsid.HasValue) // this means that the person is a suppoter who got a support email
                    {
                        goerSupporter = DbUtil.Db.GoerSupporters.SingleOrDefault(gg => gg.Id == gsid);
                        if (goerSupporter != null)
                        {
                            m.GoerId          = goerSupporter.GoerId; // suppoert this particular goer
                            m.GoerSupporterId = gsid;
                        }
                        else
                        {
                            m.GoerId = 0; // allow this supporter to still select a goer
                        }
                    }
                    else if (goerid.HasValue)
                    {
                        m.GoerId = goerid;
                    }
                }
            }
            if (Request.Url != null)
            {
                m.URL = Request.Url.OriginalString;
            }

            SetHeaders(m);

            m.testing = testing == true || DbUtil.Db.Setting("OnlineRegTesting", Util.IsDebug() ? "true" : "false").ToBool();

            if (Util.ValidEmail(email) || login != true)
            {
                m.nologin = true;
            }

            if (m.nologin)
            {
                m.CreateList();
            }
            else
            {
                m.List = new List <OnlineRegPersonModel>();
            }

            if (Util.ValidEmail(email))
            {
                m.List[0].EmailAddress = email;
            }


            var pid = 0;

            if (registertag.HasValue())
            {
                var guid = registertag.ToGuid();
                if (guid == null)
                {
                    return(Message("invalid link"));
                }
                var ot = DbUtil.Db.OneTimeLinks.SingleOrDefault(oo => oo.Id == guid.Value);
                if (ot == null)
                {
                    return(Message("invalid link"));
                }
#if DEBUG
#else
                if (ot.Used)
                {
                    return(Message("link used"));
                }
#endif
                if (ot.Expires.HasValue && ot.Expires < DateTime.Now)
                {
                    return(Message("link expired"));
                }
                var a = ot.Querystring.Split(',');
                pid           = a[1].ToInt();
                m.registertag = registertag;
            }
            else if (User.Identity.IsAuthenticated)
            {
                pid = Util.UserPeopleId ?? 0;
            }

            if (pid > 0)
            {
                m.UserPeopleId = pid;
                var existingRegistration = m.GetExistingRegistration(pid);
                if (existingRegistration != null)
                {
                    TempData["er"] = m.UserPeopleId;
                    return(Redirect("/OnlineReg/Existing/" + existingRegistration.DatumId));
                }
                OnlineRegPersonModel p = null;
                if (showfamily != true)
                {
                    p = m.LoadExistingPerson(pid, 0);
                    OnlineRegPersonModelValidator.ValidateModelForFind(p, ModelState, m, 0);
                    p.LoggedIn = true;
                    if (m.masterorg == null)
                    {
                        if (m.List.Count == 0)
                        {
                            m.List.Add(p);
                        }
                        else
                        {
                            m.List[0] = p;
                        }
                    }
                }
                if (!ModelState.IsValid)
                {
                    return(View(m));
                }

                if (m.masterorg != null && m.masterorg.RegistrationTypeId == RegistrationTypeCode.ManageSubscriptions2)
                {
                    TempData["ms"] = m.UserPeopleId;
                    return(Redirect("/OnlineReg/ManageSubscriptions/{0}".Fmt(m.masterorgid)));
                }
                if (m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.ManageGiving)
                {
                    TempData["mg"] = m.UserPeopleId;
                    return(ManageGiving(m.Orgid.ToString(), m.testing));
                }
                if (m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.OnlinePledge)
                {
                    TempData["mp"] = m.UserPeopleId;
                    return(Redirect("/OnlineReg/ManagePledge/{0}".Fmt(m.Orgid)));
                }
                if (m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.ChooseVolunteerTimes)
                {
                    TempData["ps"] = m.UserPeopleId;
                    return(Redirect("/OnlineReg/ManageVolunteer/{0}".Fmt(m.Orgid)));
                }
                if (showfamily != true && p.org != null && p.Found == true)
                {
                    p.IsFilled = p.org.RegLimitCount(DbUtil.Db) >= p.org.Limit;
                    if (p.IsFilled)
                    {
                        ModelState.AddModelError(m.GetNameFor(mm => mm.List[0].Found), "Sorry, but registration is closed.");
                    }
                    if (p.Found == true)
                    {
                        p.FillPriorInfo();
                    }
                    p.CheckSetFee();
                    m.HistoryAdd("index, pid={0}, !showfamily, p.org, found=true".Fmt(pid));
                    return(View(m));
                }
                m.HistoryAdd("index, pid=" + pid);
                return(View(m));
            }
            m.HistoryAdd("index");
            return(View(m));
        }
Beispiel #7
0
        private ActionResult RouteRegistration(OnlineRegModel m, int pid, bool?showfamily)
        {
            if (pid == 0)
            {
                return(View(m));
            }
#if DEBUG
            m.DebugCleanUp();
#endif

            var link = RouteExistingRegistration(m, pid);
            if (link.HasValue())
            {
                return(Redirect(link));
            }

            OnlineRegPersonModel p = null;
            if (showfamily != true)
            {
                // No need to pick family, so prepare first registrant ready to answer questions
                p = m.LoadExistingPerson(pid, 0);
                if (p == null)
                {
                    throw new Exception($"No person found with PeopleId = {pid}");
                }

                p.ValidateModelForFind(ModelState, 0);
                if (m.masterorg == null)
                {
                    if (m.List.Count == 0)
                    {
                        m.List.Add(p);
                    }
                    else
                    {
                        m.List[0] = p;
                    }
                }
            }
            if (!ModelState.IsValid)
            {
                m.Log("CannotProceed");
                return(View(m));
            }

            link = RouteManageGivingSubscriptionsPledgeVolunteer(m);
            if (link.HasValue())
            {
                if (m.ManageGiving()) // use Direct ActionResult instead of redirect
                {
                    return(ManageGiving(m.Orgid.ToString(), m.testing));
                }
                else if (m.RegisterLinkMaster())
                {
                    return(Redirect(link));
                }
                else
                {
                    return(Redirect(link));
                }
            }

            // check for forcing show family, master org, or not found
            if (showfamily == true || p.org == null || p.Found != true)
            {
                return(View(m));
            }

            // ready to answer questions, make sure registration is ok to go
            m.Log("Authorized");
            if (!m.SupportMissionTrip)
            {
                p.IsFilled = p.org.RegLimitCount(DbUtil.Db) >= p.org.Limit;
            }
            if (p.IsFilled)
            {
                m.Log("Closed");
                ModelState.AddModelError(m.GetNameFor(mm => mm.List[0].Found), "Sorry, but registration is closed.");
            }

            p.FillPriorInfo();
            p.SetSpecialFee();

            m.HistoryAdd($"index, pid={pid}, !showfamily, p.org, found=true");
            return(View(m));
        }
Beispiel #8
0
        // Main page
        public ActionResult Index(int?id, int?div, bool?testing, int?o, int?d, string email, bool?nologin, bool?login, string registertag, bool?showfamily)
        {
#if DEBUG
            var om = DbUtil.Db.OrganizationMembers.SingleOrDefault(mm => mm.OrganizationId == 89469 && mm.PeopleId == 828612);
            if (om != null)
            {
                om.Drop(DbUtil.Db, false);
                DbUtil.Db.SubmitChanges();
            }
#endif
            Util.NoCache(Response);
            if (!id.HasValue && !div.HasValue)
            {
                return(Content("no organization"));
            }
            var m = new OnlineRegModel
            {
                divid = div,
                orgid = id,
            };
            if (m.org == null && m.div == null && m.masterorg == null)
            {
                return(Content("invalid registration"));
            }

            if (m.masterorg != null)
            {
                if (!OnlineRegModel.UserSelectClasses(m.masterorg).Any())
                {
                    return(Content("no classes available on this org"));
                }
            }
            else if (m.org != null)
            {
                if ((m.org.RegistrationTypeId ?? 0) == RegistrationTypeCode.None)
                {
                    return(Content("no registration allowed on this org"));
                }
            }
            else if (m.div != null)
            {
                if (!OnlineRegModel.UserSelectClasses(m.divid).Any())
                {
                    return(Content("no registration allowed on this div"));
                }
            }
            m.URL = Request.Url.OriginalString;

            SetHeaders(m);

#if DEBUG
            m.username = "******";
            m.testing  = true;
#else
            m.testing = testing;
#endif
            if (Util.ValidEmail(email) || login != true)
            {
                m.nologin = true;
            }

            if (m.nologin)
            {
                m.CreateList();
            }
            else
            {
                m.List = new List <OnlineRegPersonModel>();
            }

            if (Util.ValidEmail(email))
            {
                m.List[0].email = email;
            }

            var pid = 0;
            if (registertag.HasValue())
            {
                var guid = registertag.ToGuid();
                if (guid == null)
                {
                    return(Content("invalid link"));
                }
                var ot = DbUtil.Db.OneTimeLinks.SingleOrDefault(oo => oo.Id == guid.Value);
                if (ot == null)
                {
                    return(Content("invalid link"));
                }
#if DEBUG
#else
                if (ot.Used)
                {
                    return(Content("link used"));
                }
#endif
                if (ot.Expires.HasValue && ot.Expires < DateTime.Now)
                {
                    return(Content("link expired"));
                }
                var a       = ot.Querystring.Split(',');
                var oid     = a[0].ToInt();
                var emailid = a[2].ToInt();
                pid           = a[1].ToInt();
                m.registertag = registertag;
            }
            else if (User.Identity.IsAuthenticated)
            {
                pid = Util.UserPeopleId ?? 0;
            }

            if (pid > 0)
            {
                //m.List = new List<OnlineRegPersonModel>();
                m.UserPeopleId = pid;
                OnlineRegPersonModel p = null;
                if (showfamily != true)
                {
                    p = m.LoadExistingPerson(pid, 0);
                    p.ValidateModelForFind(ModelState, m);
                    p.LoggedIn = true;
                    if (m.masterorg == null && !m.divid.HasValue)
                    {
                        if (m.List.Count == 0)
                        {
                            m.List.Add(p);
                        }
                        else
                        {
                            m.List[0] = p;
                        }
                    }
                }
                if (!ModelState.IsValid)
                {
                    return(View(m));
                }
                if (m.masterorg != null && m.masterorg.RegistrationTypeId == RegistrationTypeCode.ManageSubscriptions2)
                {
                    TempData["ms"] = m.UserPeopleId;
                    return(Redirect("/OnlineReg/ManageSubscriptions/{0}".Fmt(m.masterorgid)));
                }
                if (m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.ManageGiving)
                {
                    TempData["mg"] = m.UserPeopleId;
                    return(Redirect("/OnlineReg/ManageGiving/{0}".Fmt(m.orgid)));
                }
                if (m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.OnlinePledge)
                {
                    TempData["mp"] = m.UserPeopleId;
                    return(Redirect("/OnlineReg/ManagePledge/{0}".Fmt(m.orgid)));
                }
                if (m.org != null && m.org.RegistrationTypeId == RegistrationTypeCode.ChooseVolunteerTimes)
                {
                    TempData["ps"] = m.UserPeopleId;
                    return(Redirect("/OnlineReg/ManageVolunteer/{0}".Fmt(m.orgid)));
                }
                if (showfamily != true && p.org != null && p.Found == true)
                {
                    p.IsFilled = p.org.OrganizationMembers.Count() >= p.org.Limit;
                    if (p.IsFilled)
                    {
                        ModelState.AddModelError(m.GetNameFor(mm => mm.List[0].Found), "Sorry, but registration is closed.");
                    }
                    if (p.Found == true)
                    {
                        p.FillPriorInfo();
                    }
                    CheckSetFee(m, p);
                    return(View(m));
                }
                return(View(m));
            }
            return(View(m));
        }
Beispiel #9
0
 public string PrepareSummaryInfo(OnlineRegPersonModel p)
 {
     this.p = p;
     om = p.GetOrgMember();
     ti = p.Parent.Transaction;
     if (ShowTransaction)
         ts = om.TransactionSummary(this.db);
     rr = p.person.GetRecReg();
 }
Beispiel #10
0
 private void PrepareFirstRegistrant(ref OnlineRegModel m, int pid, bool?showfamily, out OnlineRegPersonModel p)
 {
     p = null;
     if (showfamily != true)
     {
         // No need to pick family, so prepare first registrant ready to answer questions
         p = m.LoadExistingPerson(pid, 0);
         if (p == null)
         {
             throw new Exception($"No person found with PeopleId = {pid}");
         }
         p.ProcessType = m.ProcessType;
         p.ValidateModelForFind(ModelState, 0);
         if (m.masterorg == null)
         {
             if (m.List.Count == 0)
             {
                 m.List.Add(p);
             }
             else
             {
                 m.List[0] = p;
             }
         }
     }
 }
        public void OnEnrollTest()
        {
            var context = ContextTestUtils.CreateMockHttpContext();
            var org     = CreateOrganization();
            var person  = CreatePerson();
            var om      = OrganizationMember.AddOrgMember(db, org.OrganizationId, person.PeopleId, MemberTypeCode.Member, DateTime.Now, org.OrganizationName);

            org.UpdateRegSetting(new Settings
            {
                AskItems = new List <Ask>(new Ask[] {
                    new AskText {
                        Name = "ImportantQuestion"
                    },
                    new AskCheckboxes {
                        Name = "Options",
                        list = new List <AskCheckboxes.CheckboxItem>(new[] {
                            new AskCheckboxes.CheckboxItem {
                                Name = "Item 1"
                            }
                        })
                    }
                })
            });
            db.SubmitChanges();
            var notify = db.StaffPeopleForOrg(om.OrganizationId).First();

            var personModel = new OnlineRegModel(db)
            {
                Orgid        = om.OrganizationId,
                UserPeopleId = om.PeopleId,
            };
            var model = new OnlineRegPersonModel(db)
            {
                orgid       = om.OrganizationId,
                Parent      = personModel,
                PeopleId    = om.PeopleId,
                FirstName   = om.Person.FirstName,
                LastName    = om.Person.LastName,
                Checkbox    = new List <string>(new[] { "Item 1" }),
                QuestionsOK = true,
                Text        = new List <Dictionary <string, string> >(new[] { new Dictionary <string, string>() })
            };

            model.Text.First()["ImportantQuestion"] = "ImportantAnswer";
            var script = "OnEnrollTest";

            db.WriteContentPython(script, @"print(Data)");
            model.setting.OnEnrollScript = script;
            model.OnEnroll(om);
            model.ScriptResults.Trim().ShouldBe($@"{{
  ""PeopleId"": {om.PeopleId},
  ""OrganizationId"": {om.OrganizationId},
  ""OnlineNotifyId"": {notify.PeopleId},
  ""OnlineNotifyEmail"": ""{notify.EmailAddress}"",
  ""OnlineNotifyName"": ""{notify.Name}"",
  ""LoggedIn"": true,
  ""FirstName"": ""{person.FirstName}"",
  ""LastName"": ""{person.LastName}"",
  ""TextQuestion"": {{
    ""ImportantQuestion"": ""ImportantAnswer""
  }},
  ""Checkbox"": {{
    ""Item 1"": true
  }}
}}".Replace("\r", ""));
        }