bvcms /CmsWeb/Areas/OnlineReg/Models/OnlineRegPerson/OnlineRegPersonModel.cs

Language C# Lines 381
MD5 Hash 691408f8b9d94bfcd828d52387a2255d Estimated Cost $9,134 (why?)
Repository https://bitbucket.org/mahalowe/bvcms View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Data.Linq;
using System.Reflection;
using System.Web;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Schema;
using System.Xml.Serialization;
using CmsData;
using CmsData.API;
using UtilityExtensions;
using System.Runtime.Serialization;
using System.Web.Mvc;
using CmsData.Codes;

namespace CmsWeb.Models
{
    [Serializable]
    public partial class OnlineRegPersonModel : IXmlSerializable
    {
        public int? orgid { get; set; }
        public int? masterorgid { get; set; }
        public int? divid { get; set; }
        public int? classid { get; set; }
        public int? PeopleId { get; set; }
        public bool? Found { get; set; }
        public bool IsNew { get; set; }
        public bool OtherOK { get; set; }
        public bool LoggedIn { get; set; }
        public bool IsValidForExisting { get; set; }
        public bool ShowAddress { get; set; }
        public bool CreatingAccount { get; set; }
        public string first { get; set; }
        public string middle { get; set; }
        public string last { get; set; }
        public string suffix { get; set; }
        public string dob { get; set; }
        public string phone { get; set; }
        public string homephone { get; set; }
        public string address { get; set; }
        public string address2 { get; set; }
        public string city { get; set; }
        public string state { get; set; }
        public string zip { get; set; }
        public string country { get; set; }
        public int? gender { get; set; }
        public int? married { get; set; }
        public bool IsFilled { get; set; }
        public string shirtsize { get; set; }
        public string emcontact { get; set; }
        public string emphone { get; set; }
        public string insurance { get; set; }
        public string policy { get; set; }
        public string doctor { get; set; }
        public string docphone { get; set; }
        public string medical { get; set; }
        public string mname { get; set; }
        public string fname { get; set; }
        public bool memberus { get; set; }
        public bool otherchurch { get; set; }
        public bool? coaching { get; set; }
        public bool? tylenol { get; set; }
        public bool? advil { get; set; }
        public bool? maalox { get; set; }
        public bool? robitussin { get; set; }
        public bool? paydeposit { get; set; }
        public string request { get; set; }
        public string grade { get; set; }
        public int? ntickets { get; set; }
        public int? whatfamily { get; set; }
        public string gradeoption { get; set; }
        public bool IsFamily { get; set; }
        [DisplayFormat(DataFormatString = "{0:N2}", ApplyFormatInEditMode = true)]
        public decimal? Suggestedfee { get; set; }
        public Dictionary<int, decimal?> FundItem { get; set; }
        public List<Dictionary<string, string>> ExtraQuestion { get; set; }
        public Dictionary<string, bool?> YesNoQuestion { get; set; }
        public List<string> option { get; set; }
        public List<string> Checkbox { get; set; }
        public Dictionary<string, int?> MenuItem { get; set; }

        public void ReadXml(XmlReader reader)
        {
            var s = reader.ReadOuterXml();
            var x = XDocument.Parse(s);
            if (x.Root == null) return;

            var eqset = 0;
            foreach (var e in x.Root.Elements())
            {
                var name = e.Name.ToString();
                switch (name)
                {
                    case "FundItem":
                        if (FundItem == null)
                            FundItem = new Dictionary<int, decimal?>();
                        var fu = e.Attribute("fund");
                        if (fu != null)
                            FundItem.Add(fu.Value.ToInt(), e.Value.ToDecimal());
                        break;
                    case "ExtraQuestion":
                        if (ExtraQuestion == null)
                            ExtraQuestion = new List<Dictionary<string, string>>();
                        var eqsetattr = e.Attribute("set");
                        if(eqsetattr != null)
                            eqset = eqsetattr.Value.ToInt();
                        if (ExtraQuestion.Count == eqset)
                            ExtraQuestion.Add(new Dictionary<string, string>());
                        var eq = e.Attribute("question");
                        if (eq != null)
                            ExtraQuestion[eqset].Add(eq.Value, e.Value);
                        break;
                    case "YesNoQuestion":
                        if (YesNoQuestion == null)
                            YesNoQuestion = new Dictionary<string, bool?>();
                        var ynq = e.Attribute("question");
                        if (ynq != null)
                            YesNoQuestion.Add(ynq.Value, e.Value.ToBool());
                        break;
                    case "option":
                        if (option == null)
                            option = new List<string>();
                        option.Add(e.Value);
                        break;
                    case "Checkbox":
                        if (Checkbox == null)
                            Checkbox = new List<string>();
                        Checkbox.Add(e.Value);
                        break;
                    case "MenuItem":
                        if (MenuItem == null)
                            MenuItem = new Dictionary<string, int?>();
                        var aname = e.Attribute("name");
                        var number = e.Attribute("number");
                        if (aname != null && number != null)
                            MenuItem.Add(aname.Value, number.Value.ToInt());
                        break;
                    default:
                        Util.SetPropertyFromText(this, name, e.Value);
                        break;
                }
            }
        }

        public void WriteXml(XmlWriter writer)
        {
            var optionsAdded = false;
            var checkoxesAdded = false;
            var menuitemsAdded = false;
            var w = new APIWriter(writer);
            foreach (PropertyInfo pi in typeof(OnlineRegPersonModel).GetProperties(BindingFlags.Public | BindingFlags.Instance)
                .Where(vv => vv.CanRead && vv.CanWrite))
            {
                switch (pi.Name)
                {
                    case "FundItem":
                        if (FundItem != null && FundItem.Count > 0)
                            foreach (var f in FundItem.Where(ff => ff.Value > 0))
                            {
                                w.Start("FundItem");
                                w.Attr("fund", f.Key);
                                w.AddText(f.Value.Value.ToString());
                                w.End();
                            }
                        break;
                    case "ExtraQuestion":
                        if(ExtraQuestion != null)
                            for (var i = 0; i < ExtraQuestion.Count; i++)
                                if (ExtraQuestion[i] != null && ExtraQuestion[i].Count > 0)
                                    foreach (var q in ExtraQuestion[i])
                                    {
                                        w.Start("ExtraQuestion");
                                        w.Attr("set", i);
                                        w.Attr("question", q.Key);
                                        w.AddText(q.Value);
                                        w.End();
                                    }
                        break;
                    case "YesNoQuestion":
                        if (YesNoQuestion != null && YesNoQuestion.Count > 0)
                            foreach (var q in YesNoQuestion)
                            {
                                w.Start("YesNoQuestion");
                                w.Attr("question", q.Key);
                                w.AddText(q.Value.ToString());
                                w.End();
                            }
                        break;
                    case "option":
                        if (option != null && option.Count > 0 && !optionsAdded)
                            foreach(var o in option)
                                w.Add("option", o);
                        optionsAdded = true;
                        break;
                    case "Checkbox":
                        if (Checkbox != null && Checkbox.Count > 0 && !checkoxesAdded)
                            foreach (var c in Checkbox)
                                w.Add("Checkbox", c);
                        checkoxesAdded = true;
                        break;
                    case "MenuItem":
                        if (MenuItem != null && !menuitemsAdded)
                            foreach (var kv in MenuItem)
                            {
                                w.Start("MenuItem");
                                w.Attr("name", kv.Key);
                                w.Attr("number", kv.Value);
                                w.End();
                            }
                        menuitemsAdded = true;
                        break;
                    default:
                        w.Add(pi.Name, pi.GetValue(this, null));
                        break;
                }
            }
        }

        public OnlineRegPersonModel()
        {
            YesNoQuestion = new Dictionary<string, bool?>();
            FundItem = new Dictionary<int, decimal?>();
            Parent = HttpContext.Current.Items["OnlineRegModel"] as OnlineRegModel;
        }
        private void AfterSettingConstructor()
        {
            if (_setting == null)
                return;
            var ndd = setting.AskItems.Count(aa => aa.Type == "AskDropdown");
            if (ndd > 0 && option == null)
                option = new string[ndd].ToList();

            var neqsets = setting.AskItems.Count(aa => aa.Type == "AskExtraQuestions");
            if (neqsets > 0 && ExtraQuestion == null)
            {
                ExtraQuestion = new List<Dictionary<string, string>>();
                for(var i = 0; i < neqsets; i++)
                    ExtraQuestion.Add(new Dictionary<string, string>());
            }
            var nmi = setting.AskItems.Count(aa => aa.Type == "AskMenu");
            if (nmi > 0 && MenuItem == null)
                MenuItem = new Dictionary<string, int?>();

            var ncb = setting.AskItems.Count(aa => aa.Type == "AskCheckboxes");
            if (ncb > 0 && Checkbox == null)
                Checkbox = new List<string>();

            if (!Suggestedfee.HasValue && setting.AskVisible("AskSuggestedFee"))
                Suggestedfee = setting.Fee;
        }

        public OnlineRegModel Parent;

        public int? index;
        public int Index()
        {
            if (!index.HasValue)
                index = Parent.List.IndexOf(this);
            if (index == -1)
                index = 0;
            return index.Value;
        }

        public bool LastItem()
        {
            return Index() == Parent.List.Count - 1;
        }

        public bool SawExistingAccount;
        public bool CannotCreateAccount;
        public bool CreatedAccount;


        public string email { get; set; }
        public string fromemail
        {
            get { return first + " " + last + " <" + email + ">"; }
        }

        public int? MenuItemValue(string s)
        {
            if (MenuItem.ContainsKey(s))
                return MenuItem[s];
            return null;
        }

        public decimal? FundItemValue(int n)
        {
            if (FundItem.ContainsKey(n))
                return FundItem[n];
            return null;
        }

        private DateTime _Birthday;
        public DateTime? birthday
        {
            get
            {
                if (_Birthday == DateTime.MinValue)
                    Util.BirthDateValid(dob, out _Birthday);
                return _Birthday == DateTime.MinValue ? (DateTime?)null : _Birthday;
            }
        }
        public string NotFoundText;
        private int count;

        private Person _Person;

        public Person person
        {
            get
            {
                if (_Person == null)
                    if (PeopleId.HasValue)
                    {
                        _Person = DbUtil.Db.LoadPersonById(PeopleId.Value);
                        count = 1;
                    }
                    else
                    {
                        //_Person = SearchPeopleModel.FindPerson(first, last, birthday, email, phone, out count);

                        var list = DbUtil.Db.FindPerson(first, last, birthday, email, phone).ToList();
                        count = list.Count;
                        if (count == 1)
                            _Person = DbUtil.Db.LoadPersonById(list[0].PeopleId.Value);
                        if (_Person != null)
                            PeopleId = _Person.PeopleId;
                    }
                return _Person;
            }
        }
        public void AddPerson(Person p, int entrypoint)
        {
            Family f;
            if (p == null)
                f = new Family
                {
                    AddressLineOne = address,
                    AddressLineTwo = address2,
                    CityName = city,
                    StateCode = state,
                    ZipCode = zip,
                    CountryName = country,
                    HomePhone = homephone,
                };
            else
                f = p.Family;

            _Person = Person.Add(f, PositionInFamily.Child,
                null, first.Trim(), null, last.Trim(), dob, married == 20, gender ?? 0,
                    OriginCode.Enrollment, entrypoint);
            person.EmailAddress = email.Trim();
            person.SuffixCode = suffix;
            person.MiddleName = middle;
            person.CampusId = DbUtil.Db.Setting("DefaultCampusId", "").ToInt2();
            if (person.Age >= 18)
                person.PositionInFamilyId = PositionInFamily.PrimaryAdult;
            person.CellPhone = phone.GetDigits();

            DbUtil.Db.SubmitChanges();
            DbUtil.Db.Refresh(RefreshMode.OverwriteCurrentValues, person);
            PeopleId = person.PeopleId;
        }
        public bool IsCreateAccount()
        {
            if (org != null)
                return org.RegistrationTypeId == RegistrationTypeCode.CreateAccount;
            return false;
        }
        public XmlSchema GetSchema()
        {
            throw new System.NotImplementedException("The method or operation is not implemented.");
        }

    }
}
Back to Top