private string Create_Controller_Code_Add(string template) { StringBuilder sb = new StringBuilder(); sb.AppendLine(" /// <summary>"); sb.AppendLine(" /// Add a new " + entity_name); sb.AppendLine(" /// </summary>"); sb.AppendLine(" /// <returns></returns>"); sb.AppendLine(" [Route(\"api/" + entity_sub_namespace + "/Post\")]"); sb.AppendLine(" [PermissionVerify(new CommonEnum.Operations[] { CommonEnum.Operations.Setup })]"); sb.AppendLine(" [HttpPost]"); sb.AppendLine(" public IHttpActionResult Post(" + NameHelper.Get_ViewModel_AddModel(entity_name) + " model)"); sb.AppendLine(" {"); sb.AppendLine(" var userInfo = WebData.GetSimpleLoginedUserInfo(LoginUser);"); sb.AppendLine(" if (userInfo == null) { return Json(new ApiActionResult() { Success = false, Message = \"登录信息失效,请重新登录\" }); }"); sb.AppendLine(" var command = new AddCommand()"); sb.AppendLine(" {"); //foreach (var p in entity_properties.Where(x => x.Name != entity_id_properties.Name).ToList()) foreach (var p in entity_properties.ToList()) { if ("Organization_Id".Equals(NameHelper.Get_Property_Name_For_Command(p.Name))) { sb.AppendLine(" " + NameHelper.Get_Property_Name_For_Command(p.Name) + " = userInfo.OrganizationId.Value,"); } else if ("Created_Time".Equals(NameHelper.Get_Property_Name_For_Command(p.Name))) { sb.AppendLine(" " + NameHelper.Get_Property_Name_For_Command(p.Name) + " = DateTime.Now,"); } else if ("Created_User_Id".Equals(NameHelper.Get_Property_Name_For_Command(p.Name))) { sb.AppendLine(" " + NameHelper.Get_Property_Name_For_Command(p.Name) + " = userInfo.Id,"); } else if ("Id".Equals(NameHelper.Get_Property_Name_For_Command(p.Name))) { sb.AppendLine(" " + NameHelper.Get_Property_Name_For_Command(p.Name) + " = Guid.NewGuid(),"); } else { sb.AppendLine(" " + NameHelper.Get_Property_Name_For_Command(p.Name) + " = model." + NameHelper.Get_Property_Name_For_ViewModel(p.Name) + ","); } } sb.AppendLine(" };"); sb.AppendLine(" CommandBus.Send(command);"); //sb.AppendLine(""); sb.AppendLine(" if (NeedRecordSystemLog(Operations.Create)) "); sb.AppendLine(" {"); sb.AppendLine(" RecordSystemLog(null, JsonConvert.SerializeObject(command), \"All\", Operations.Create);"); sb.AppendLine(" }"); //sb.AppendLine(""); sb.AppendLine(" return CommandResult(command.ExecuteResult);"); sb.Append(" }"); template = template.Replace("{{Add-Actions}}", sb.ToString()); return(template); }