PageRenderTime 38ms CodeModel.GetById 16ms app.highlight 14ms RepoModel.GetById 2ms app.codeStats 0ms

/CmsWeb/Areas/OnlineReg/Controllers/ConfirmTest.cs

https://bitbucket.org/mahalowe/bvcms
C# | 164 lines | 97 code | 2 blank | 65 comment | 6 complexity | 531393ef47c36daf16a4741c56f88d9a MD5 | raw file
  1using System;
  2using System.Collections.Generic;
  3using System.Linq;
  4using System.Web;
  5using System.Web.Mvc;
  6using System.Web.Mvc.Ajax;
  7using CmsData;
  8using CmsWeb.Models;
  9using UtilityExtensions;
 10using System.Configuration;
 11using System.Net.Mail;
 12using System.Runtime.Serialization;
 13using System.IO;
 14using System.Text;
 15using System.Text.RegularExpressions;
 16using CmsWeb.Areas.Manage.Controllers;
 17using System.Xml.Linq;
 18
 19namespace CmsWeb.Areas.OnlineReg.Controllers
 20{
 21    public partial class OnlineRegController
 22    {
 23        public class ConfirmTestInfo
 24        {
 25            public ExtraDatum ed;
 26            public OnlineRegModel m;
 27        }
 28        public class TransactionTestInfo
 29        {
 30            public ExtraDatum ed;
 31            public TransactionInfo ti;
 32        }
 33        private string EleVal(XElement r, string name)
 34        {
 35            var e = r.Element(name);
 36            if (e != null)
 37                return e.Value;
 38            return null;
 39        }
 40        [Authorize(Roles = "Admin")]
 41        public ActionResult ConfirmTest(int? start, int? count)
 42        {
 43            IEnumerable<ExtraDatum> q;
 44            q = from ed in DbUtil.Db.ExtraDatas
 45                where ed.Data.StartsWith("<?") && ed.Data.Contains("<OnlineRegModel")
 46                orderby ed.Stamp descending
 47                select ed;
 48            var list = q.Skip(start ?? 0).Take(count ?? 200).ToList();
 49            var q2 = new List<ConfirmTestInfo>();
 50            foreach (var ed in list)
 51            {
 52                try
 53                {
 54                    var m = Util.DeSerialize<OnlineRegModel>(ed.Data);
 55                    var i = new ConfirmTestInfo
 56                    {
 57                        ed = ed,
 58                        m = m
 59                    };
 60                    q2.Add(i);
 61                }
 62                catch (Exception)
 63                {
 64                }
 65            }
 66            return View(q2);
 67        }
 68        [Authorize(Roles = "Admin")]
 69        public ActionResult ConfirmTestXml(int id)
 70        {
 71            var ed = (from i in DbUtil.Db.ExtraDatas
 72                where i.Id == id
 73                select i).SingleOrDefault();
 74            if (ed == null)
 75                return Content("no data");
 76            var m = Util.DeSerialize<OnlineRegModel>(ed.Data);
 77            return Content(ed.Data, contentType: "text/xml");
 78        }
 79        //[Authorize(Roles = "Admin")]
 80        //public ActionResult ConfirmTest(int? start, int? count)
 81        //{
 82        //    IEnumerable<ExtraDatum> q;
 83        //    q = from ed in DbUtil.Db.ExtraDatas
 84        //        //where ed.Data.Contains("<OnlineRegModel ")
 85        //        where ed.Data.Contains("<OnlineRegModel xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"")
 86        //        orderby ed.Stamp descending
 87        //        select ed;
 88        //    var list = q.Skip(start ?? 0).Take(count ?? 200).ToList();
 89        //    var q2 = new List<ConfirmTestInfo>();
 90        //    foreach (var ed in list)
 91        //    {
 92        //        var xml = ed.Data.Replace(@"<OnlineRegModel xmlns=""http://schemas.datacontract.org/2004/07/CmsWeb.Models"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">", @"<OnlineRegModel>")
 93        //            .Replace(" i:", " ")
 94        //            .Replace(@"xmlns:a=""http://schemas.datacontract.org/2004/07/CmsData""", "")
 95        //            .Replace(@"xmlns:a=""http://schemas.microsoft.com/2003/10/Serialization/Arrays""", "")
 96        //            .Replace(@"_x003E_k__BackingField", "")
 97        //            .Replace(@"_x003C_", "")
 98        //            .Replace(@"<_", "<")
 99        //            .Replace(@"</_", "</")
100        //            .Replace(@" a:", " ")
101        //            .Replace(@"<a:", "<")
102        //            .Replace(@"</a:", "</")
103        //            ;
104        //        var x = XDocument.Parse(xml);
105        //        var m = new OnlineRegModel();
106        //        m.divid = EleVal(x.Root, "Divid").ToInt2();
107        //        m.orgid = EleVal(x.Root,"Orgid").ToInt2();
108        //        m.masterorgid = EleVal(x.Root,"Masterorgid").ToInt2();
109        //        m.username = (EleVal(x.Root, "Username") ?? EleVal(x.Root, "username"));
110        //        m.List = new List<OnlineRegPersonModel>();
111        //        foreach (var e in x.Descendants("OnlineRegPersonModel"))
112        //        {
113        //            m.List.Add(new OnlineRegPersonModel
114        //            {
115        //                PeopleId = e.Element("PeopleId").Value.ToInt2(),
116        //                first = e.Element("first").Value,
117        //                last = e.Element("last").Value,
118        //                orgid = e.Element("orgid").Value.ToInt2(),
119        //                dob = e.Element("dob").Value,
120        //                phone = e.Element("phone").Value,
121        //                email = e.Element("email").Value,
122        //                mname = e.Element("mname").Value,
123        //                fname = e.Element("fname").Value,
124        //                ShowAddress = e.Element("ShowAddress").Value.ToBool(),
125        //                address = e.Element("address").Value,
126        //                city = e.Element("city").Value,
127        //            });
128        //        }
129
130        //        try
131        //        {
132        //            var i = new ConfirmTestInfo
133        //            {
134        //                ed = ed,
135        //                m = m
136        //            };
137        //            q2.Add(i);
138        //        }
139        //        catch (Exception)
140        //        {
141        //        }
142        //    }
143        //    return View(q2);
144        //}
145        [Authorize(Roles = "Admin")]
146        public ActionResult TransactionTest(int? id, int? count)
147        {
148            var q = from ed in DbUtil.Db.ExtraDatas
149                    where ed.Data.StartsWith("<TransactionInfo ")
150                    where ed.Id >= id
151                    orderby ed.Stamp descending
152                    select ed;
153            var list = q.Take(count ?? 1000).ToList();
154            var q2 = from ed in list
155                     let s = ed.Data.Replace("CMSWeb.Models", "CmsWeb.Models")
156                     select new TransactionTestInfo
157                     {
158                         ed = ed,
159                         ti = Util.DeSerialize<TransactionInfo>(s) as TransactionInfo
160                     };
161            return View(q2);
162        }
163    }
164}