CondorXE /Plugins/WebApi4.Components/WebApi4.Components/ServiceLayer/WebApiServiceLayerObjects.cs

Language C# Lines 526
MD5 Hash 8984437a2e3fb8c01df146d2b1512c10 Estimated Cost $12,775 (why?)
Repository git://github.com/kahanu/CondorXE.git View Raw File
  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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
using System;
using System.Linq;
using Condor.Core;
using Condor.Core.Interfaces;
using MyMeta;

namespace WebApi4.Components.ServiceLayer
{
    public class WebApiServiceLayerObjects : RenderBase, IServiceObjects
    {
        #region ctors
        private readonly RequestContext _context;

        public WebApiServiceLayerObjects(RequestContext context)
            : base(context.Zeus.Output)
        {
            this._context = context;
        }
        #endregion

        #region IRenderObject Members

        public void Render()
        {
            _context.Dialog.InitDialog(_script.Tables.Count);
            _context.FileList.Add("");

            //RenderFormatterClass();
            //RenderRouteConfigClass();
            //RenderGlobalAsaxClass();
            RenderUnityWebApiConfigurationClass();
            RenderBaseControllerClass();

            _context.Dialog.InitDialog(_script.Tables.Count);
            _context.FileList.Add("");
            _context.FileList.Add("Generated WebApi4 Controller classes: ");
            foreach (string tableName in _script.Tables)
            {
                _context.Dialog.Display("Adding " + tableName + "Controller class");
                ITable table = _context.Database.Tables[tableName];
                RenderApiControllerClass(table);
            }
        }


        #endregion

        #region Private Methods

        private void RenderApiControllerClass(ITable table)
        {
            _hdrUtil.WriteClassHeader(_output);

            _output.autoTabLn("using System;");
            _output.autoTabLn("using System.Collections.Generic;");
            _output.autoTabLn("using System.Linq;");
            _output.autoTabLn("using System.Linq.Expressions;");
            _output.autoTabLn("");
            _output.autoTabLn("using " + _script.Settings.BusinessObjects.BusinessObjectsNamespace + ";");
            _output.autoTabLn("using " + _script.Settings.DataOptions.DataObjectsNamespace + ";");
            _output.autoTabLn("using " + _script.Settings.DataOptions.DataObjectsNamespace + ".Interfaces;");
            _output.autoTabLn("");
            _output.autoTabLn("namespace " + _script.Settings.ServiceLayer.ServiceNamespace + ".Controllers");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// This is the WebApi controller for the " + StringFormatter.CleanUpClassName(table.Name) + " entity.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("public class " + StringFormatter.CleanUpClassName(table.Name) + "Controller : BaseController<" + StringFormatter.CleanUpClassName(table.Name) + ">");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("#region ctors");
            _output.autoTabLn("private readonly I" + StringFormatter.CleanUpClassName(table.Name) + _script.Settings.DataOptions.ClassSuffix.Name + " _" + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + ";");
            _output.autoTabLn("private readonly IUnitOfWork _unitOfWork;");
            _output.autoTabLn("");
            _output.autoTabLn("public " + StringFormatter.CleanUpClassName(table.Name) + "Controller(I" + StringFormatter.CleanUpClassName(table.Name) + _script.Settings.DataOptions.ClassSuffix.Name + " " + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + ", IUnitOfWork unitOfWork) : base(" + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + ", unitOfWork)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("this._unitOfWork = unitOfWork;");
            _output.autoTabLn("this._" + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + " = " + StringFormatter.CamelCasing(StringFormatter.CleanUpClassName(table.Name)) + _script.Settings.DataOptions.ClassSuffix.Name + ";");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("");
            _output.autoTabLn("#endregion");
            _output.autoTabLn("");
            _output.autoTabLn("#region Custom Actions");
            _output.autoTabLn("");
            _output.autoTabLn("///// <summary>");
            _output.autoTabLn("///// This is a custom action that returns Product by category.");
            _output.autoTabLn("///// Check how the route is created in the RouteConfig.cs file in the App_Start folder.");
            _output.autoTabLn("///// </summary>");
            _output.autoTabLn("///// <param name=\"category\">Category Name</param>");
            _output.autoTabLn("///// <returns></returns>");
            _output.autoTabLn("//public List<Product> GetProductsByCategory(string category)");
            _output.autoTabLn("//{");
            _output.autoTabLn("//	Expression<Func<Product, bool>> exp = null;");
            _output.autoTabLn("//	if (!string.IsNullOrEmpty(category))");
            _output.autoTabLn("//		exp = c => c.Category.CategoryName.ToLower() == category.ToLower();");
            _output.autoTabLn("");
            _output.autoTabLn("//	return _productRepository.Get(exp).ToList();");
            _output.autoTabLn("//}");
            _output.autoTabLn("");
            _output.autoTabLn("///// <summary>");
            _output.autoTabLn("///// Get a Product by name.  Check the RouteConfig.cs file for routing.");
            _output.autoTabLn("///// </summary>");
            _output.autoTabLn("///// <param name=\"name\">Product Name</param>");
            _output.autoTabLn("///// <returns></returns>");
            _output.autoTabLn("//public Product GetProductByName(string name)");
            _output.autoTabLn("//{");
            _output.autoTabLn("");
            _output.autoTabLn("//	Product product = _productRepository.Get(p => p.Name.ToLower() == name.ToLower()).SingleOrDefault();");
            _output.autoTabLn("//	if (product == null)");
            _output.autoTabLn("//		throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));");
            _output.autoTabLn("");
            _output.autoTabLn("//	return product;");
            _output.autoTabLn("//}");
            _output.autoTabLn("");
            _output.autoTabLn("///// <summary>");
            _output.autoTabLn("///// Calculate the tax for a product. (Example PUT method.)");
            _output.autoTabLn("///// </summary>");
            _output.autoTabLn("///// <param name=\"name\">Product model</param>");
            _output.autoTabLn("///// <returns></returns>");
            _output.autoTabLn("//[HttpPut]");
            _output.autoTabLn("//public Product CalculateTax(Product model)");
            _output.autoTabLn("//{");
            _output.autoTabLn("//	if (ModelState.IsValid)");
            _output.autoTabLn("//	{");
            _output.autoTabLn("//		try");
            _output.autoTabLn("//		{");
            _output.autoTabLn("//			var tax = model.Amount * _taxRate;");
            _output.autoTabLn("//			_groupDao.UpdateTax(tax);");
            _output.autoTabLn("//			_unitOfWork.ActionEntities.Commit();");
            _output.autoTabLn("//			");
            _output.autoTabLn("//		}");
            _output.autoTabLn("//		catch (Exception)");
            _output.autoTabLn("//		{");
            _output.autoTabLn("//			return Request.CreateResponse(HttpStatusCode.NotFound);");
            _output.autoTabLn("//		}");
            _output.autoTabLn("//		return Request.CreateResponse(HttpStatusCode.OK, model);");
            _output.autoTabLn("//	}");
            _output.autoTabLn("//	else");
            _output.autoTabLn("//	{");
            _output.autoTabLn("//		return Request.CreateResponse(HttpStatusCode.BadRequest);");
            _output.autoTabLn("//	}");
            _output.autoTabLn("//}");
            _output.autoTabLn("");
            _output.autoTabLn("#endregion");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");

            _context.FileList.Add("    " + StringFormatter.CleanUpClassName(table.Name) + "Controller.cs");
            SaveOutput(CreateFullPath(_script.Settings.ServiceLayer.ServiceNamespace + "\\Controllers", StringFormatter.CleanUpClassName(table.Name) + "Controller.cs"), SaveActions.DontOverwrite);
        }

        private void RenderBaseControllerClass()
        {
            _hdrUtil.WriteClassHeader(_output);

            _output.autoTabLn("using System;");
            _output.autoTabLn("using System.Collections.Generic;");
            _output.autoTabLn("using System.Linq;");
            _output.autoTabLn("using System.Net;");
            _output.autoTabLn("using System.Net.Http;");
            _output.autoTabLn("using System.Web.Http;");
            _output.autoTabLn("using " + _script.Settings.BusinessObjects.BusinessObjectsNamespace + ";");
            _output.autoTabLn("using " + _script.Settings.DataOptions.DataObjectsNamespace + ";");
            _output.autoTabLn("using " + _script.Settings.DataOptions.DataObjectsNamespace + ".Generated;");
            _output.autoTabLn("");
            _output.autoTabLn("namespace " + _script.Settings.ServiceLayer.ServiceNamespace + ".Controllers");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// This is the common base ApiController used for all controllers.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("/// <typeparam name=\"T\"></typeparam>");
            _output.autoTabLn("public class BaseController<T> : ApiController where T : Entity");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("#region ctors");
            _output.autoTabLn("private readonly IRepository<T> _repository;");
            _output.autoTabLn("private readonly IUnitOfWork _unitOfWork;");
            _output.autoTabLn("");
            _output.autoTabLn("public BaseController(IRepository<T> repository, IUnitOfWork unitOfWork)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("this._unitOfWork = unitOfWork;");
            _output.autoTabLn("this._repository = repository;");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("");
            _output.autoTabLn("#endregion");
            _output.autoTabLn("");
            _output.autoTabLn("#region Basic CRUD");
            _output.autoTabLn("");
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// Get all the Products in the repository.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("/// <returns></returns>");
            _output.autoTabLn("public IEnumerable<T> Get()");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("return _repository.Get();");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("");
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// Get the selected Product.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("/// <param name=\"id\">Id</param>");
            _output.autoTabLn("/// <returns></returns>");
            _output.autoTabLn("public T Get(int id)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("T model = _repository.GetById(id);");
            _output.autoTabLn("if (model == null)");
            _output.tabLevel++;
            _output.autoTabLn("throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));");
            _output.tabLevel--;
            _output.autoTabLn("");
            _output.autoTabLn("return model;");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("");
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// Insert a new Product into the repository.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("/// <param name=\"model\">Product</param>");
            _output.autoTabLn("/// <returns></returns>");
            _output.autoTabLn("public HttpResponseMessage Post(T model)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("if (ModelState.IsValid)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("_repository.Insert(model);");
            _output.autoTabLn("_unitOfWork." + _script.Settings.DataOptions.DataContext.Name + ".Commit();");
            _output.autoTabLn("");
            _output.autoTabLn("var response = Request.CreateResponse(HttpStatusCode.Created, model);");
            _output.autoTabLn("response.Headers.Location = new Uri(Url.Link(\"DefaultApi\", new { id = model.Id }));");
            _output.autoTabLn("");
            _output.autoTabLn("return response;");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("else");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("");
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// Update the selected Product.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("/// <param name=\"id\">Id</param>");
            _output.autoTabLn("/// <param name=\"model\">Product</param>");
            _output.autoTabLn("/// <returns></returns>");
            _output.autoTabLn("public HttpResponseMessage Put(T model)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("if (ModelState.IsValid)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("try");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("_repository.Update(model);");
            _output.autoTabLn("_unitOfWork." + _script.Settings.DataOptions.DataContext.Name + ".Commit();");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("catch (Exception)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("return Request.CreateResponse(HttpStatusCode.NotFound);");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("return Request.CreateResponse(HttpStatusCode.OK, model);");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("else");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("return Request.CreateResponse(HttpStatusCode.BadRequest);");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("");
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// Delete the selected Product.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("/// <param name=\"id\">Id</param>");
            _output.autoTabLn("/// <returns></returns>");
            _output.autoTabLn("public HttpResponseMessage Delete(int id)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("T model = _repository.GetById(id);");
            _output.autoTabLn("if (model == null)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("return Request.CreateResponse(HttpStatusCode.NotFound);");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("");
            _output.autoTabLn("try");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("_repository.Delete(model);");
            _output.autoTabLn("_unitOfWork." + _script.Settings.DataOptions.DataContext.Name + ".Commit();");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("catch (Exception)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("return Request.CreateResponse(HttpStatusCode.NotFound);");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("");
            _output.autoTabLn("return Request.CreateResponse(HttpStatusCode.OK, model);");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("#endregion");
            _output.autoTabLn("");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");

            _context.FileList.Add("    BaseController.cs");
            SaveOutput(CreateFullPath(_script.Settings.ServiceLayer.ServiceNamespace + "\\Controllers", "BaseController.cs"), SaveActions.Overwrite);
        }

        private void RenderGlobalAsaxClass()
        {
            _output.autoTabLn("using System;");
            _output.autoTabLn("using System.Linq;");
            _output.autoTabLn("using System.Web.Http;");
            _output.autoTabLn("using System.Web.Routing;");
            _output.autoTabLn("using " + _script.Settings.ServiceLayer.ServiceNamespace + ".App_Start;");
            _output.autoTabLn("");
            _output.autoTabLn("namespace " + _script.Settings.ServiceLayer.ServiceNamespace);
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("public class Global : System.Web.HttpApplication");
            _output.autoTabLn("{");
            _output.autoTabLn("");
            _output.tabLevel++;
            _output.autoTabLn("protected void Application_Start(object sender, EventArgs e)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("RouteConfig.RegisterRoutes(RouteTable.Routes);");
            _output.autoTabLn("FormattersConfig.RegisterFormatters(GlobalConfiguration.Configuration);");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");

            _context.FileList.Add("    Global.asax.cs");
            SaveOutput(CreateFullPath(_script.Settings.ServiceLayer.ServiceNamespace, "Global.asax.cs"), SaveActions.DontOverwrite);

            _output.writeln("<%@ Application Codebehind=\"Global.asax.cs\" Inherits=\"" + _script.Settings.ServiceLayer.ServiceNamespace + ".Global\" Language=\"C#\" %>");
            SaveOutput(CreateFullPath(_script.Settings.ServiceLayer.ServiceNamespace, "Global.asax"), SaveActions.DontOverwrite);
        }

        private void RenderUnityWebApiConfigurationClass()
        {
            _hdrUtil.WriteClassHeader(_output);

            _output.autoTabLn("[assembly: WebActivator.PreApplicationStartMethod(typeof(" + _script.Settings.ServiceLayer.ServiceNamespace + ".App_Start.UnityWebApi), \"Start\")]");
            _output.autoTabLn("[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(" + _script.Settings.ServiceLayer.ServiceNamespace + ".App_Start.UnityWebApi), \"Stop\")]");
            _output.autoTabLn("");
            _output.autoTabLn("");
            _output.autoTabLn("namespace " + _script.Settings.ServiceLayer.ServiceNamespace + ".App_Start");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("using System;");
            _output.autoTabLn("using System.Linq;");
            _output.autoTabLn("using System.Web.Http;");
            _output.autoTabLn("using " + _script.Settings.DataOptions.DataObjectsNamespace + ";");
            _output.autoTabLn("using " + _script.Settings.DataOptions.DataObjectsNamespace + ".Interfaces;");
            _output.autoTabLn("using " + _script.Settings.DataOptions.DataObjectsNamespace + ".Repositories;");
            _output.autoTabLn("using Microsoft.Practices.Unity;");
            _output.autoTabLn("");
            _output.autoTabLn("public static class UnityWebApi");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("private static IUnityContainer container;");
            _output.autoTabLn("");
            _output.autoTabLn("#region Public Methods");
            _output.autoTabLn("public static void Start()");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("Initialise();");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("");
            _output.autoTabLn("public static void Stop()");
            _output.autoTabLn("{");
            _output.autoTabLn("");
            _output.autoTabLn("} ");
            _output.autoTabLn("#endregion");
            _output.autoTabLn("");
            _output.autoTabLn("#region Private Methods");
            _output.autoTabLn("private static void Initialise()");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("container = BuildUnityContainer();");
            _output.autoTabLn("");
            _output.autoTabLn("GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.autoTabLn("");
            _output.autoTabLn("private static IUnityContainer BuildUnityContainer()");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("var container = new UnityContainer();");
            _output.autoTabLn("");

            foreach (string tableName in _script.Tables)
            {
                ITable table = _context.Database.Tables[tableName];
                _output.autoTabLn("container.RegisterType<I" + StringFormatter.CleanUpClassName(table.Name) + _script.Settings.DataOptions.ClassSuffix.Name + ", " + StringFormatter.CleanUpClassName(table.Name) + _script.Settings.DataOptions.ClassSuffix.Name + ">();");
            }
            _output.autoTabLn("container.RegisterType<IUnitOfWork, UnitOfWork>(new HierarchicalLifetimeManager());");

            _output.autoTabLn("");
            _output.autoTabLn("return container;");
            _output.tabLevel--;
            _output.autoTabLn("} ");
            _output.autoTabLn("#endregion");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");

            _context.FileList.Add("    UnityWebApi.cs");
            SaveOutput(CreateFullPath(_script.Settings.ServiceLayer.ServiceNamespace + "\\App_Start", "UnityWebApi.cs"), SaveActions.Overwrite);
        }

        private void RenderRouteConfigClass()
        {
            _hdrUtil.WriteClassHeader(_output);

            _output.autoTabLn("using System;");
            _output.autoTabLn("using System.Linq;");
            _output.autoTabLn("using System.Web.Http;");
            _output.autoTabLn("using System.Web.Routing;");
            _output.autoTabLn("");
            _output.autoTabLn("namespace " + _script.Settings.ServiceLayer.ServiceNamespace + ".App_Start");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// Register your routes here.");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("public class RouteConfig");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("public static void RegisterRoutes(RouteCollection routes)");
            _output.autoTabLn("{");
            _output.autoTabLn("");
            _output.tabLevel++;
            _output.autoTabLn("// This is the default route.");
            _output.autoTabLn("routes.MapHttpRoute(");
            _output.tabLevel++;
            _output.autoTabLn("name: \"DefaultApi\",");
            _output.autoTabLn("routeTemplate: \"api/{controller}/{id}\",");
            _output.autoTabLn("defaults: new { id = RouteParameter.Optional }");
            _output.tabLevel--;
            _output.autoTabLn(");");
            _output.autoTabLn("");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");

            _context.FileList.Add("    RouteConfig.cs");
            SaveOutput(CreateFullPath(_script.Settings.ServiceLayer.ServiceNamespace + "\\App_Start", "RouteConfig.cs"), SaveActions.DontOverwrite);
        }

        private void RenderFormatterClass()
        {
            _hdrUtil.WriteClassHeader(_output);

            _output.autoTabLn("using System;");
            _output.autoTabLn("using System.Linq;");
            _output.autoTabLn("using System.Web.Http;");
            _output.autoTabLn("using WebApiContrib.Formatting.Jsonp;");
            _output.autoTabLn("");
            _output.autoTabLn("namespace " + _script.Settings.ServiceLayer.ServiceNamespace + ".App_Start");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("/// <summary>");
            _output.autoTabLn("/// Register your formatters here.");
            _output.autoTabLn("/// For the Jsonp formatter, install the NuGet package: install-package WebApiContrib.Formatting.Jsonp");
            _output.autoTabLn("/// </summary>");
            _output.autoTabLn("public class FormattersConfig");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("public static void RegisterFormatters(HttpConfiguration config)");
            _output.autoTabLn("{");
            _output.tabLevel++;
            _output.autoTabLn("config.Formatters.Insert(0, new JsonpMediaTypeFormatter());");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");
            _output.tabLevel--;
            _output.autoTabLn("}");

            _context.FileList.Add("    FormattersConfig.cs");
            SaveOutput(CreateFullPath(_script.Settings.ServiceLayer.ServiceNamespace + "\\App_Start", "FormattersConfig.cs"), SaveActions.DontOverwrite);
        }


        #endregion
    }
}
Back to Top