<#@ include file="HelperTemplate.ttinclude" #> <#+ // Note: You can call this method from the outside of the template, // please add parameters as needed. // To include this templaate just drag this file on another editor // then call this.Template_NewTemplate1_Render() public void Render(string SolutionName,string NameSpace,Type type){ #> using System; using System.Collections.Generic; using System.Web.Http; using System.Net; using System.Net.Http; using <#=SolutionName#>.Business; using <#=SolutionName#>.Contract; using <#=SolutionName#>.Contract.DataContracts; using MyBasicLib.Collections.Generic; using MyBasicLib.Extensions; namespace <#=NameSpace#> { public class <#=GetFileName(type)#> : ApiController//, <#=type.Name#> { <#=type.Name#> service = new <#=type.Name.Substring(1)#>(); <#=type.Name.Substring(1, type.Name.Length-8)#>Data defaultData = new <#=type.Name.Substring(1, type.Name.Length-8)#>Data(); <#+ var methods= type.GetMethods(); foreach (var method in methods) {var parameters= method.GetParameters();#> public <#=ToGenericTypeString(method.ReturnType)#> <#=method.Name#>(<#+for (var i=0 ;i< parameters.Length;i++) {#><#=(method.Name.StartsWith("Get")?"[FromUri]":"")+ToGenericTypeString (parameters[i].ParameterType)#> <#= parameters[i].Name#><#= parameters[i].HasDefaultValue?" = "+(parameters[i].DefaultValue??"null"):""#><#= i==parameters.Length-1?"":","#><#+}#>) { <#+ if(method.Name.StartsWith("Post")||method.Name.StartsWith("Put")){ var parameter=parameters[parameters.Length-1]; var properties=parameter.ParameterType.GetProperties(); var ps=properties.Where(p=>p.Name=="CreateDate"||p.Name=="UpdateDate").ToArray(); foreach (var p in ps) {if(p.Name=="UpdateDate"&&method.Name.StartsWith("Put")){#> <#=parameter.Name#>.<#=p.Name#> = DateTime.Now; <#+}else{#> <#=parameter.Name#>.<#=p.Name#> = <#=parameter.Name#>.<#=p.Name#>.GetValidDate(DateTime.Now); <#+}}#> <#+if(method.Name.StartsWith("Post")&&properties.Any(p=>p.Name=="CreateUser_Id")){#> var userId = WebHelper.GetCurrentUserId(); <#=parameter.Name#>.CreateUser_Id = userId; <#+if(properties.Any(p=>p.Name=="UpdateUser_Id")){#> <#=parameter.Name#>.UpdateUser_Id = userId; <#+}#> <#+}#> <#+if(method.Name.StartsWith("Put")&&properties.Any(p=>p.Name=="UpdateUser_Id")){#> var userId = WebHelper.GetCurrentUserId(); <#=parameter.Name#>.UpdateUser_Id = userId; <#+}#> <#+}#> <#=ToGenericTypeString(method.ReturnType)=="void"?"":"return "#>service.<#=method.Name#>(<#+for (var i=0 ;i< parameters.Length;i++) {#><#= parameters[i].Name#><#= i==parameters.Length-1?"":","#><#+}#>)<#= method.ReturnType.Name==type.Name.Substring(1, type.Name.Length-8)+"Data"?"??defaultData":"" #>; } <#+}#> } } <#+} #>