PageRenderTime 1461ms CodeModel.GetById 148ms app.highlight 270ms RepoModel.GetById 212ms app.codeStats 806ms

/Plugins/GizmoBeach.Components/UI/AspNetMvcUILayerObjectsForDbContextBase.cs

http://github.com/kahanu/CondorXE
C# | 704 lines | 627 code | 75 blank | 2 comment | 14 complexity | c73490d6da4cdae266ee6ba0aa7f7c7c MD5 | raw file
  1using System;
  2using System.Linq;
  3using Condor.Core;
  4using Condor.Core.Interfaces;
  5using MyMeta;
  6
  7namespace GizmoBeach.Components.UI
  8{
  9    public class AspNetMvcUILayerObjectsForDbContextBase : RenderBase, IUIObjects
 10    {
 11        #region ctors
 12
 13        private readonly UICriteria _criteria;
 14
 15        private readonly IAutoMapperFramework _autoMapperFramework;
 16        private readonly ProgressDialogWrapper _dialog;
 17        private readonly IDatabase _database;
 18        private readonly RequestContext _context;
 19
 20        public AspNetMvcUILayerObjectsForDbContextBase(RequestContext context)
 21            : this(context, null)
 22        {
 23
 24        }
 25        
 26        public AspNetMvcUILayerObjectsForDbContextBase(RequestContext context, IAutoMapperFramework autoMapperFramework)
 27            :this(context, autoMapperFramework, new UICriteria())
 28        {
 29        }
 30
 31        public AspNetMvcUILayerObjectsForDbContextBase(RequestContext context, IAutoMapperFramework autoMapperFramework, UICriteria criteria)
 32            : base(context.Zeus.Output)
 33        {
 34            this._criteria = criteria;
 35            this._autoMapperFramework = autoMapperFramework;
 36            this._context = context;
 37            this._dialog = context.Dialog;
 38            this._database = context.Database;
 39        }
 40
 41        #endregion
 42
 43        #region IRenderObject Members
 44
 45        public void Render()
 46        {
 47            _dialog.InitDialog();
 48            _context.FileList.Add("");
 49            _context.FileList.Add("Generated UI MVC ViewData classes:");
 50
 51            bool useUIDtos = false;
 52            if (_autoMapperFramework != null)
 53                useUIDtos = true;
 54
 55            foreach (string tableName in _script.Tables)
 56            {
 57                MyMeta.ITable table = _database.Tables[tableName];
 58                BuildViewDataClass(table, useUIDtos);
 59            }
 60
 61            _dialog.InitDialog(3);
 62            _dialog.Display("Processing UI MVC BaseViewData class.");
 63            BuildBaseViewDataClass();
 64
 65            _dialog.Display("Processing UI MVC BaseViewDataBuilder class.");
 66            BuildBaseViewDataBuilderClass();
 67
 68            _dialog.Display("Processing UI MVC ViewDataFactory class.");
 69            BuildViewDataFactory();
 70
 71            CreateCommonClass();
 72
 73            CreateConfigSettingsClass();
 74
 75            CreateJsonResponseClass();
 76
 77            BuildControllerCodeTemplate();
 78
 79            BuildBaseController();
 80
 81            BuildAutoMapperFramework();
 82        }
 83
 84        private void BuildAutoMapperFramework()
 85        {
 86            if (_autoMapperFramework != null)
 87            {
 88                bool useWebService = false;
 89                _autoMapperFramework.RenderAutoMapperExtensionClass(useWebService);
 90                _autoMapperFramework.RenderAutoMapperConfiguration(useWebService);
 91                _autoMapperFramework.RenderAutoMapperAppStart();
 92
 93                foreach (string tableName in _script.Tables)
 94                {
 95                    ITable table = _database.Tables[tableName];
 96                    _autoMapperFramework.BuildModelClass(table, useWebService);
 97                }
 98            }
 99        }
100
101        private void BuildBaseController()
102        {
103
104            _hdrUtil.WriteClassHeader(_output);
105
106            _output.autoTabLn("using " + _script.Settings.ServiceLayer.ServiceNamespace + ".Interfaces;");
107            _output.autoTabLn("using System.Linq;");
108            _output.autoTabLn("using System.Web.Mvc;");
109            _output.autoTabLn("");
110            _output.autoTabLn("namespace " + _script.Settings.UI.UINamespace + ".Controllers");
111            _output.autoTabLn("{");
112            _output.tabLevel++;
113            _output.autoTabLn("public class BaseController : Controller");
114            _output.autoTabLn("{");
115            _output.autoTabLn("");
116            _output.tabLevel++;
117            _output.autoTabLn("#region DI stuff");
118
119            foreach (string tableName in _script.Tables)
120            {
121                if (tableName == "SiteSetting")
122                {
123                    _output.autoTabLn("private ISiteSettingService siteSettingService;");
124                    _output.autoTabLn("");
125                    _output.autoTabLn("public BaseController(ISiteSettingService siteSettingService)");
126                    _output.autoTabLn("{");
127                    _output.tabLevel++;
128                    _output.autoTabLn("this.siteSettingService = siteSettingService;");
129                    _output.tabLevel--;
130                    _output.autoTabLn("}");
131                }
132            }
133
134
135
136            _output.autoTabLn("");
137            _output.autoTabLn("public BaseController()");
138            _output.autoTabLn("{");
139            _output.autoTabLn("");
140            _output.autoTabLn("}");
141            _output.autoTabLn("");
142            _output.autoTabLn("#endregion");
143            _output.autoTabLn("");
144
145            foreach (string tableName in _script.Tables)
146            {
147                if (tableName == "SiteSetting")
148                {
149                    _output.autoTabLn("#region Public Methods");
150                    _output.autoTabLn("");
151                    _output.autoTabLn("/// <summary>");
152                    _output.autoTabLn("/// Get the value of a SiteSetting.");
153                    _output.autoTabLn("/// </summary>");
154                    _output.autoTabLn("/// <param name=\"key\"></param>");
155                    _output.autoTabLn("/// <returns></returns>");
156                    _output.autoTabLn("public string GetSetting(string key)");
157                    _output.autoTabLn("{");
158                    _output.tabLevel++;
159                    _output.autoTabLn("string result = string.Empty;");
160                    _output.autoTabLn("");
161                    _output.autoTabLn("var query = siteSettingService.GetByKey(key);");
162                    _output.autoTabLn("");
163                    _output.autoTabLn("return result;");
164                    _output.tabLevel--;
165                    _output.autoTabLn("}");
166                    _output.autoTabLn("");
167                    _output.autoTabLn("#endregion");
168                    _output.autoTabLn("");
169                }
170            }
171
172
173
174            _output.autoTabLn("#region Overrides");
175            _output.autoTabLn("/// <summary>");
176            _output.autoTabLn("/// This provides simple feedback to the modelstate in the case of errors.");
177            _output.autoTabLn("/// </summary>");
178            _output.autoTabLn("/// <param name=\"filterContext\"></param>");
179            _output.autoTabLn("protected override void OnActionExecuted(ActionExecutedContext filterContext)");
180            _output.autoTabLn("{");
181            _output.tabLevel++;
182            _output.autoTabLn("if (filterContext.Result is RedirectToRouteResult)");
183            _output.autoTabLn("{");
184            _output.tabLevel++;
185            _output.autoTabLn("// put the ModelState into TempData");
186            _output.autoTabLn("TempData.Add(\"_MODELSTATE\", ModelState);");
187            _output.tabLevel--;
188            _output.autoTabLn("}");
189            _output.autoTabLn("else if (filterContext.Result is ViewResult && TempData.ContainsKey(\"_MODELSTATE\"))");
190            _output.autoTabLn("{");
191            _output.tabLevel++;
192            _output.autoTabLn("// merge modelstate from TempData");
193            _output.autoTabLn("var modelState = TempData[\"_MODELSTATE\"] as ModelStateDictionary;");
194            _output.autoTabLn("foreach (var item in modelState)");
195            _output.autoTabLn("{");
196            _output.tabLevel++;
197            _output.autoTabLn("if (!ModelState.ContainsKey(item.Key))");
198            _output.tabLevel++;
199            _output.autoTabLn("ModelState.Add(item);");
200            _output.tabLevel--;
201            _output.tabLevel--;
202            _output.autoTabLn("}");
203            _output.tabLevel--;
204            _output.autoTabLn("}");
205            _output.autoTabLn("base.OnActionExecuted(filterContext);");
206            _output.tabLevel--;
207            _output.autoTabLn("}");
208            _output.autoTabLn("#endregion");
209            _output.autoTabLn("");
210            _output.tabLevel--;
211            _output.autoTabLn("}");
212            _output.tabLevel--;
213            _output.autoTabLn("}");
214
215            _context.FileList.Add("    BaseController.cs");
216            SaveOutput(CreateFullPath(_script.Settings.UI.UINamespace + "\\Controllers", "BaseController.cs"), SaveActions.DontOverwrite);
217
218
219            // Now create the WebApi base class
220            _hdrUtil.WriteClassHeader(_output);
221
222            _output.autoTabLn("using System;");
223            _output.autoTabLn("using System.Collections.Generic;");
224            _output.autoTabLn("using System.Linq;");
225            _output.autoTabLn("using System.Net;");
226            _output.autoTabLn("using System.Net.Http;");
227            _output.autoTabLn("using System.Web.Http;");
228            _output.autoTabLn("using " + _script.Settings.DataOptions.DataObjectsNamespace + ";");
229            _output.autoTabLn("using " + _script.Settings.ServiceLayer.ServiceNamespace + ".Generated;");
230            _output.autoTabLn("");
231            _output.autoTabLn("namespace " + _script.Settings.UI.UINamespace + ".Controllers.api");
232            _output.autoTabLn("{");
233            _output.tabLevel++;
234            _output.autoTabLn("/// <summary>");
235            _output.autoTabLn("/// This is the common base ApiController used for all controllers.");
236            _output.autoTabLn("/// It will be used primarily for GET operations, even though it has");
237            _output.autoTabLn("/// the other CRUD operations enabled.  Other operations such as POST,");
238            _output.autoTabLn("/// PUT, DELETE, etc., should be used only where absolutely necessary,");
239            _output.autoTabLn("/// and only in the Admin Area, not the public site.");
240            _output.autoTabLn("/// </summary>");
241            _output.autoTabLn("/// <typeparam name=\"T\">a business object type</typeparam>");
242            _output.autoTabLn("public class BaseController<T> : ApiController where T : class");
243            _output.autoTabLn("{");
244            _output.tabLevel++;
245            _output.autoTabLn("#region ctors");
246            _output.autoTabLn("private readonly IService<T> _service;");
247            _output.autoTabLn("private readonly IUnitOfWork _unitOfWork;");
248            _output.autoTabLn("");
249            _output.autoTabLn("public BaseController(IService<T> service, IUnitOfWork unitOfWork)");
250            _output.autoTabLn("{");
251            _output.tabLevel++;
252            _output.autoTabLn("this._unitOfWork = unitOfWork;");
253            _output.autoTabLn("this._service = service;");
254            _output.tabLevel--;
255            _output.autoTabLn("}");
256            _output.autoTabLn("");
257            _output.autoTabLn("#endregion");
258            _output.autoTabLn("");
259            _output.autoTabLn("#region Basic CRUD");
260            _output.autoTabLn("");
261            _output.autoTabLn("/// <summary>");
262            _output.autoTabLn("/// Get all the Products in the repository.");
263            _output.autoTabLn("/// </summary>");
264            _output.autoTabLn("/// <returns></returns>");
265            _output.autoTabLn("public IEnumerable<T> Get()");
266            _output.autoTabLn("{");
267            _output.tabLevel++;
268            _output.autoTabLn("return _service.Get();");
269            _output.tabLevel--;
270            _output.autoTabLn("}");
271            _output.autoTabLn("");
272            _output.autoTabLn("/// <summary>");
273            _output.autoTabLn("/// Get the selected Entity.");
274            _output.autoTabLn("/// </summary>");
275            _output.autoTabLn("/// <param name=\"id\">Id</param>");
276            _output.autoTabLn("/// <returns></returns>");
277            _output.autoTabLn("public T Get(int id)");
278            _output.autoTabLn("{");
279            _output.tabLevel++;
280            _output.autoTabLn("T model = _service.GetById(id);");
281            _output.autoTabLn("if (model == null)");
282            _output.tabLevel++;
283            _output.autoTabLn("throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));");
284            _output.tabLevel--;
285            _output.autoTabLn("");
286            _output.autoTabLn("return model;");
287            _output.tabLevel--;
288            _output.autoTabLn("}");
289            _output.autoTabLn("");
290            _output.autoTabLn("/// <summary>");
291            _output.autoTabLn("/// Insert a new Product into the repository.");
292            _output.autoTabLn("/// </summary>");
293            _output.autoTabLn("/// <param name=\"model\">Product</param>");
294            _output.autoTabLn("/// <returns></returns>");
295            _output.autoTabLn("/// ");
296            _output.autoTabLn("[Authorize]");
297            _output.autoTabLn("public HttpResponseMessage Post(T model)");
298            _output.autoTabLn("{");
299            _output.tabLevel++;
300            _output.autoTabLn("if (ModelState.IsValid)");
301            _output.autoTabLn("{");
302            _output.tabLevel++;
303            _output.autoTabLn("_service.Insert(model);");
304            _output.autoTabLn("_unitOfWork.Db.Commit();");
305            _output.autoTabLn("");
306            _output.autoTabLn("var response = Request.CreateResponse(HttpStatusCode.Created, model);");
307            _output.autoTabLn("//response.Headers.Location = new Uri(Url.Link(\"DefaultApi\", new { controller = \"" + " id = model.Id }));");
308            _output.autoTabLn("");
309            _output.autoTabLn("return response;");
310            _output.tabLevel--;
311            _output.autoTabLn("}");
312            _output.autoTabLn("else");
313            _output.autoTabLn("{");
314            _output.tabLevel++;
315            _output.autoTabLn("throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));");
316            _output.tabLevel--;
317            _output.autoTabLn("}");
318            _output.tabLevel--;
319            _output.autoTabLn("}");
320            _output.autoTabLn("");
321            _output.autoTabLn("/// <summary>");
322            _output.autoTabLn("/// Update the selected Product.");
323            _output.autoTabLn("/// </summary>");
324            _output.autoTabLn("/// <param name=\"id\">Id</param>");
325            _output.autoTabLn("/// <param name=\"model\">Product</param>");
326            _output.autoTabLn("/// <returns></returns>");
327            _output.autoTabLn("/// ");
328            _output.autoTabLn("[Authorize]");
329            _output.autoTabLn("public HttpResponseMessage Put(T model)");
330            _output.autoTabLn("{");
331            _output.tabLevel++;
332            _output.autoTabLn("if (ModelState.IsValid)");
333            _output.autoTabLn("{");
334            _output.tabLevel++;
335            _output.autoTabLn("try");
336            _output.autoTabLn("{");
337            _output.tabLevel++;
338            _output.autoTabLn("_service.Update(model);");
339            _output.autoTabLn("_unitOfWork.Db.Commit();");
340            _output.tabLevel--;
341            _output.autoTabLn("}");
342            _output.autoTabLn("catch (Exception)");
343            _output.autoTabLn("{");
344            _output.tabLevel++;
345            _output.autoTabLn("return Request.CreateResponse(HttpStatusCode.NotFound);");
346            _output.tabLevel--;
347            _output.autoTabLn("}");
348            _output.autoTabLn("return Request.CreateResponse(HttpStatusCode.OK, model);");
349            _output.tabLevel--;
350            _output.autoTabLn("}");
351            _output.autoTabLn("else");
352            _output.autoTabLn("{");
353            _output.tabLevel++;
354            _output.autoTabLn("return Request.CreateResponse(HttpStatusCode.BadRequest);");
355            _output.tabLevel--;
356            _output.autoTabLn("}");
357            _output.tabLevel--;
358            _output.autoTabLn("}");
359            _output.autoTabLn("");
360            _output.autoTabLn("/// <summary>");
361            _output.autoTabLn("/// Delete the selected Product.");
362            _output.autoTabLn("/// </summary>");
363            _output.autoTabLn("/// <param name=\"id\">Id</param>");
364            _output.autoTabLn("/// <returns></returns>");
365            _output.autoTabLn("/// ");
366            _output.autoTabLn("[Authorize]");
367            _output.autoTabLn("public HttpResponseMessage Delete(int id)");
368            _output.autoTabLn("{");
369            _output.tabLevel++;
370            _output.autoTabLn("T model = _service.GetById(id);");
371            _output.autoTabLn("if (model == null)");
372            _output.autoTabLn("{");
373            _output.tabLevel++;
374            _output.autoTabLn("return Request.CreateResponse(HttpStatusCode.NotFound);");
375            _output.tabLevel--;
376            _output.autoTabLn("}");
377            _output.autoTabLn("");
378            _output.autoTabLn("try");
379            _output.autoTabLn("{");
380            _output.tabLevel++;
381            _output.autoTabLn("_service.Delete(model);");
382            _output.autoTabLn("_unitOfWork.Db.Commit();");
383            _output.tabLevel--;
384            _output.autoTabLn("}");
385            _output.autoTabLn("catch (Exception)");
386            _output.autoTabLn("{");
387            _output.tabLevel++;
388            _output.autoTabLn("return Request.CreateResponse(HttpStatusCode.NotFound);");
389            _output.tabLevel--;
390            _output.autoTabLn("}");
391            _output.autoTabLn("");
392            _output.autoTabLn("return Request.CreateResponse(HttpStatusCode.OK, model);");
393            _output.tabLevel--;
394            _output.autoTabLn("}");
395            _output.autoTabLn("#endregion");
396            _output.tabLevel--;
397            _output.autoTabLn("");
398            _output.autoTabLn("}");
399            _output.tabLevel--;
400            _output.autoTabLn("");
401            _output.autoTabLn("");
402            _output.autoTabLn("}");
403
404            _context.FileList.Add("    api\\BaseController.cs");
405            SaveOutput(CreateFullPath(_script.Settings.UI.UINamespace + "\\Controllers\\api", "BaseController.cs"), SaveActions.DontOverwrite);
406        }
407
408        private void BuildControllerCodeTemplate()
409        {
410            // Am I building a PIA patterned code template, no. (false)
411            bool useDtos = false;
412            if (_autoMapperFramework != null)
413                useDtos = true;
414
415            
416
417            ICodeTemplateBuilder builder;
418            if (_criteria == null)
419            {
420                builder = new KingsMvcServiceLibraryCodeTemplatesForDbContext(_context, false, useDtos);
421                builder.RenderControllerTemplate();
422                builder.RenderAspNetViewTemplates();
423                builder.RenderRazorViewTemplates();
424                builder.RenderWebApiTemplates();
425            }
426            else
427            {
428                if (_criteria.MvcVersion >= 5.0)
429                {
430                    builder = new KingsMvc5ServiceLibraryCodeTemplatesForDbContext(_context, _criteria);
431                    builder.RenderControllerTemplate();
432                    builder.RenderAspNetViewTemplates();
433                    builder.RenderRazorViewTemplates();
434                    builder.RenderWebApiTemplates();    
435                }
436                else
437                {
438                    builder = new KingsMvcServiceLibraryCodeTemplatesForDbContext(_context, false, useDtos);
439                    builder.RenderControllerTemplate();
440                    builder.RenderAspNetViewTemplates();
441                    builder.RenderRazorViewTemplates();
442                    builder.RenderWebApiTemplates();
443                }
444            }
445
446
447
448        }
449
450        private void CreateJsonResponseClass()
451        {
452
453            _hdrUtil.WriteClassHeader(_output);
454
455            _output.autoTabLn("using System;");
456            _output.autoTabLn("using System.Collections.Generic;");
457            _output.autoTabLn("using System.Linq;");
458            _output.autoTabLn("using System.Web;");
459            _output.autoTabLn("");
460            _output.autoTabLn("namespace " + _script.Settings.UI.UINamespace + ".ViewData");
461            _output.autoTabLn("{");
462            _output.tabLevel++;
463            _output.autoTabLn("public class JsonResponse");
464            _output.autoTabLn("{");
465            _output.tabLevel++;
466            _output.autoTabLn("public bool Success { get; set; }");
467            _output.autoTabLn("public string Message { get; set; }");
468            _output.autoTabLn("public bool Exists { get; set; }");
469            _output.tabLevel--;
470            _output.autoTabLn("}");
471            _output.tabLevel--;
472            _output.autoTabLn("}");
473
474            _context.FileList.Add("    JsonResponse.cs");
475            SaveOutput(CreateFullPath(_script.Settings.UI.UINamespace + "\\ViewData", "JsonResponse.cs"), SaveActions.DontOverwrite);
476        }
477
478        private void CreateConfigSettingsClass()
479        {
480
481            _hdrUtil.WriteClassHeader(_output);
482
483            _output.autoTabLn("using System;");
484            _output.autoTabLn("using System.Configuration;");
485            _output.autoTabLn("");
486            _output.autoTabLn("namespace " + _script.Settings.Namespace + ".Core");
487            _output.autoTabLn("{");
488            _output.tabLevel++;
489            _output.autoTabLn("public class ConfigSettings");
490            _output.autoTabLn("{");
491            _output.tabLevel++;
492            _output.autoTabLn("public static string SiteTitle { get { return ConfigurationManager.AppSettings[\"SiteTitle\"]; } }");
493            _output.autoTabLn("public static string MetaKeywords { get { return ConfigurationManager.AppSettings[\"MetaKeywords\"]; } }");
494            _output.autoTabLn("public static string MetaDescription { get { return ConfigurationManager.AppSettings[\"MetaDescription\"]; } }");
495            _output.autoTabLn("public static string FromEmail { get { return ConfigurationManager.AppSettings[\"FromEmail\"]; } }");
496            _output.tabLevel--;
497            _output.autoTabLn("}");
498            _output.tabLevel--;
499            _output.autoTabLn("}");
500
501            _context.FileList.Add("    ConfigSettings.cs");
502            SaveOutput(CreateFullPath(_script.Settings.Namespace + ".Core", "ConfigSettings.cs"), SaveActions.DontOverwrite);
503        }
504
505        private void CreateCommonClass()
506        {
507
508            _hdrUtil.WriteClassHeader(_output);
509
510            _output.autoTabLn("using System.Web;");
511            _output.autoTabLn("");
512            _output.autoTabLn("namespace " + _script.Settings.Namespace + ".Core");
513            _output.autoTabLn("{");
514            _output.tabLevel++;
515            _output.autoTabLn("public class Common");
516            _output.autoTabLn("{");
517            _output.tabLevel++;
518            _output.autoTabLn("public static string GetSiteUrl()");
519            _output.autoTabLn("{");
520            _output.tabLevel++;
521            _output.autoTabLn("HttpContext current = HttpContext.Current;");
522            _output.autoTabLn("string str = current.Request.ServerVariables[\"SERVER_PORT\"];");
523            _output.autoTabLn("switch (str)");
524            _output.autoTabLn("{");
525            _output.tabLevel++;
526            _output.autoTabLn("case null:");
527            _output.autoTabLn("case \"80\":");
528            _output.autoTabLn("case \"443\":");
529            _output.tabLevel++;
530            _output.autoTabLn("str = \"\";");
531            _output.autoTabLn("break;");
532            _output.tabLevel--;
533            _output.autoTabLn("");
534            _output.autoTabLn("default:");
535            _output.tabLevel++;
536            _output.autoTabLn("str = \":\" + str;");
537            _output.autoTabLn("break;");
538            _output.tabLevel--;
539            _output.autoTabLn("}");
540            _output.autoTabLn("string str2 = current.Request.ServerVariables[\"SERVER_PORT_SECURE\"];");
541            _output.autoTabLn("switch (str2)");
542            _output.autoTabLn("{");
543            _output.tabLevel++;
544            _output.autoTabLn("case null:");
545            _output.autoTabLn("case \"0\":");
546            _output.tabLevel++;
547            _output.autoTabLn("str2 = \"http://\";");
548            _output.autoTabLn("break;");
549            _output.tabLevel--;
550            _output.autoTabLn("");
551            _output.autoTabLn("default:");
552            _output.tabLevel++;
553            _output.autoTabLn("str2 = \"https://\";");
554            _output.autoTabLn("break;");
555            _output.tabLevel--;
556            _output.autoTabLn("}");
557            _output.autoTabLn("string applicationPath = current.Request.ApplicationPath;");
558            _output.autoTabLn("if (applicationPath == \"/\")");
559            _output.autoTabLn("{");
560            _output.tabLevel++;
561            _output.autoTabLn("applicationPath = \"\";");
562            _output.tabLevel--;
563            _output.autoTabLn("}");
564            _output.autoTabLn("return (str2 + current.Request.ServerVariables[\"SERVER_NAME\"] + str + applicationPath);");
565            _output.tabLevel--;
566            _output.autoTabLn("}");
567            _output.tabLevel--;
568            _output.autoTabLn("}");
569            _output.tabLevel--;
570            _output.autoTabLn("}");
571
572            _context.FileList.Add("    Common.cs");
573            SaveOutput(CreateFullPath(_script.Settings.Namespace + ".Core", "Common.cs"), SaveActions.DontOverwrite);
574        }
575
576        private void BuildViewDataFactory()
577        {
578
579            _hdrUtil.WriteClassHeader(_output);
580
581            _output.autoTabLn("namespace " + _script.Settings.UI.UINamespace + ".ViewData");
582            _output.autoTabLn("{");
583            _output.tabLevel++;
584            _output.autoTabLn("public class ViewDataFactory : BaseViewDataBuilder");
585            _output.autoTabLn("{");
586            _output.tabLevel++;
587            _output.autoTabLn("public static T CreateBaseViewData<T>(string pageTitle) where T : BaseViewData, new()");
588            _output.autoTabLn("{");
589            _output.tabLevel++;
590            _output.autoTabLn("T viewData = CreateViewData<T>(pageTitle);");
591            _output.autoTabLn("");
592            _output.autoTabLn("return viewData;");
593            _output.tabLevel--;
594            _output.autoTabLn("}");
595            _output.tabLevel--;
596            _output.autoTabLn("}");
597            _output.tabLevel--;
598            _output.autoTabLn("}");
599
600            _context.FileList.Add("    ViewDataFactory.cs");
601            SaveOutput(CreateFullPath(_script.Settings.UI.UINamespace + "\\ViewData", "ViewDataFactory.cs"), SaveActions.DontOverwrite);
602        }
603
604        private void BuildBaseViewDataBuilderClass()
605        {
606
607            _hdrUtil.WriteClassHeader(_output);
608
609            _output.autoTabLn("using " + _script.Settings.Namespace + ".Core;");
610            _output.autoTabLn("");
611            _output.autoTabLn("namespace " + _script.Settings.UI.UINamespace + ".ViewData");
612            _output.autoTabLn("{");
613            _output.tabLevel++;
614            _output.autoTabLn("public class BaseViewDataBuilder");
615            _output.autoTabLn("{");
616            _output.tabLevel++;
617            _output.autoTabLn("public static T CreateViewData<T>(string pageTitle) where T : BaseViewData, new()");
618            _output.autoTabLn("{");
619            _output.tabLevel++;
620            _output.autoTabLn("T viewData = new T");
621            _output.autoTabLn("{");
622            _output.tabLevel++;
623            _output.autoTabLn("SiteTitle = ConfigSettings.SiteTitle,");
624            _output.autoTabLn("MetaKeywords = ConfigSettings.MetaKeywords,");
625            _output.autoTabLn("MetaDescription = ConfigSettings.MetaDescription,");
626            _output.autoTabLn("PageTitle = pageTitle");
627            _output.tabLevel--;
628            _output.autoTabLn("};");
629            _output.autoTabLn("return viewData;");
630            _output.tabLevel--;
631            _output.autoTabLn("}");
632            _output.tabLevel--;
633            _output.autoTabLn("}");
634            _output.tabLevel--;
635            _output.autoTabLn("}");
636
637            _context.FileList.Add("    BaseViewDataBuilder.cs");
638            SaveOutput(CreateFullPath(_script.Settings.UI.UINamespace + "\\ViewData", "BaseViewDataBuilder.cs"), SaveActions.DontOverwrite);
639        }
640
641        private void BuildBaseViewDataClass()
642        {
643
644            _hdrUtil.WriteClassHeader(_output);
645
646            _output.autoTabLn("namespace " + _script.Settings.UI.UINamespace + ".ViewData");
647            _output.autoTabLn("{");
648            _output.tabLevel++;
649            _output.autoTabLn("public abstract class BaseViewData");
650            _output.autoTabLn("{");
651            _output.tabLevel++;
652            _output.autoTabLn("public string SiteTitle { get; set; }");
653            _output.autoTabLn("public string MetaKeywords { get; set; }");
654            _output.autoTabLn("public string MetaDescription { get; set; }");
655            _output.autoTabLn("public string PageTitle { get; set; }");
656            _output.autoTabLn("public bool IsAdmin { get; set; }");
657            _output.tabLevel--;
658            _output.autoTabLn("}");
659            _output.tabLevel--;
660            _output.autoTabLn("}");
661
662            _context.FileList.Add("    BaseViewData.cs");
663            SaveOutput(CreateFullPath(_script.Settings.UI.UINamespace + "\\ViewData", "BaseViewData.cs"), SaveActions.DontOverwrite);
664        }
665
666        private void BuildViewDataClass(MyMeta.ITable table, bool useUIDtos)
667        {
668
669            _hdrUtil.WriteClassHeader(_output);
670
671            _output.autoTabLn("using System;");
672            _output.autoTabLn("using System.Collections.Generic;");
673            _output.autoTabLn("using System.Linq;");
674            _output.autoTabLn("using System.Web;");
675            _output.autoTabLn("");
676            if (useUIDtos)
677            {
678                _output.autoTabLn("using " + _script.Settings.UI.UINamespace + ".Models;");
679            }
680            else
681            {
682                _output.autoTabLn("using " + _script.Settings.BusinessObjects.BusinessObjectsNamespace + ";");
683            }
684            _output.autoTabLn("");
685            _output.autoTabLn("namespace " + _script.Settings.UI.UINamespace + ".ViewData");
686            _output.autoTabLn("{");
687            _output.tabLevel++;
688            _output.autoTabLn("public class " + StringFormatter.CleanUpClassName(table.Name) + "ViewData : BaseViewData");
689            _output.autoTabLn("{");
690            _output.tabLevel++;
691            _output.autoTabLn("public " + StringFormatter.CleanUpClassName(table.Name) + ((useUIDtos) ? "Model" : "") + " " + StringFormatter.CleanUpClassName(table.Name) + " { get; set; }");
692            _output.autoTabLn("public List<" + StringFormatter.CleanUpClassName(table.Name) + ((useUIDtos) ? "Model" : "") + "> " + StringFormatter.CleanUpClassName(table.Name) + "List { get; set; }");
693            _output.tabLevel--;
694            _output.autoTabLn("}");
695            _output.tabLevel--;
696            _output.autoTabLn("}");
697
698            _context.FileList.Add("    " + StringFormatter.CleanUpClassName(table.Name) + "ViewData.cs");
699            SaveOutput(CreateFullPath(_script.Settings.UI.UINamespace + "\\ViewData", StringFormatter.CleanUpClassName(table.Name) + "ViewData.cs"), SaveActions.DontOverwrite);
700        }
701
702        #endregion
703    }
704}