PageRenderTime 62ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/V4-3-RC/Templates/CSLA40DAL/CSharp/DataPortalDelete_DalObject.asp

#
ASP | 134 lines | 130 code | 4 blank | 0 comment | 22 complexity | 766f6645aff13769bc7ad6a1fdaf53d0 MD5 | raw file
Possible License(s): LGPL-2.0, CC-BY-SA-3.0, Apache-2.0, MIT, GPL-3.0
  1. <%
  2. if (Info.GenerateDataPortalDelete)
  3. {
  4. foreach (Criteria c in Info.CriteriaObjects)
  5. {
  6. if (c.DeleteOptions.DataPortal)
  7. {
  8. if (isFirstMethod)
  9. isFirstMethod = false;
  10. else
  11. Response.Write(Environment.NewLine);
  12. if (usesDTO)
  13. {
  14. %>
  15. /// <summary>
  16. /// Deletes the <%= Info.ObjectName %> object from database.
  17. /// </summary>
  18. <%
  19. if (c.Properties.Count > 1)
  20. {
  21. foreach (Property prop in c.Properties)
  22. {
  23. string param = FormatCamel(prop.Name);
  24. %>
  25. /// <param name="<%= param %>">The <%= param %> parameter of the <%= Info.ObjectName %> to delete.</param>
  26. <%
  27. }
  28. }
  29. else if (c.Properties.Count > 0)
  30. {
  31. %>
  32. /// <param name="<%= c.Properties.Count > 1 ? "crit" : HookSingleCriteria(c, "crit") %>">The delete criteria.</param>
  33. <%
  34. }
  35. if (c.Properties.Count > 1)
  36. {
  37. %>
  38. public void Delete(<%= ReceiveMultipleCriteria(c) %>)
  39. <%
  40. }
  41. else
  42. {
  43. %>
  44. public void Delete(<%= ReceiveSingleCriteria(c, "crit") %>)
  45. <%
  46. }
  47. }
  48. else
  49. {
  50. string strDeleteCritParams = string.Empty;
  51. string strDeleteComment = string.Empty;
  52. bool deleteIsFirst = true;
  53. for (int i = 0; i < c.Properties.Count; i++)
  54. {
  55. if (!deleteIsFirst)
  56. strDeleteCritParams += ", ";
  57. else
  58. deleteIsFirst = false;
  59. TypeCodeEx propType = c.Properties[i].PropertyType;
  60. strDeleteCritParams += string.Concat(GetDataTypeGeneric(c.Properties[i], propType), " ", FormatCamel(c.Properties[i].Name));
  61. strDeleteComment += "/// <param name=\"" + FormatCamel(c.Properties[i].Name) + "\">The " + CslaGenerator.Metadata.PropertyHelper.SplitOnCaps(c.Properties[i].Name) + ".</param>" + System.Environment.NewLine + new string(' ', 8);
  62. }
  63. %>
  64. /// <summary>
  65. /// Deletes the <%= Info.ObjectName %> object from database.
  66. /// </summary>
  67. <%= strDeleteComment %>public void Delete(<%= strDeleteCritParams %>)
  68. <%
  69. }
  70. %>
  71. {
  72. <%= GetConnection(Info, false) %>
  73. {
  74. <%= GetCommand(Info, c.DeleteOptions.ProcedureName) %>
  75. {
  76. <%
  77. if (Info.CommandTimeout != string.Empty)
  78. {
  79. %>
  80. cmd.CommandTimeout = <%= Info.CommandTimeout %>;
  81. <%
  82. }
  83. %>
  84. cmd.CommandType = CommandType.StoredProcedure;
  85. <%
  86. foreach (CriteriaProperty p in c.Properties)
  87. {
  88. if (!usesDTO)
  89. {
  90. %>
  91. cmd.Parameters.AddWithValue("@<%= p.ParameterName %>", <%= GetParameterSet(Info, p, false, true) %><%= (p.PropertyType == TypeCodeEx.SmartDate ? ".DBValue" : "") %>).DbType = DbType.<%= TypeHelper.GetDbType(p.PropertyType) %>;
  92. <%
  93. }
  94. else
  95. {
  96. if (c.Properties.Count > 1)
  97. {
  98. %>
  99. cmd.Parameters.AddWithValue("@<%= p.ParameterName %>", <%= GetParameterSet(p, false, false, false) %><%= (p.PropertyType == TypeCodeEx.SmartDate ? ".DBValue" : "") %>).DbType = DbType.<%= TypeHelper.GetDbType(p.PropertyType) %>;
  100. <%
  101. }
  102. else
  103. {
  104. %>
  105. cmd.Parameters.AddWithValue("@<%= p.ParameterName %>", <%= AssignSingleCriteria(c, "crit") %><%= (p.PropertyType == TypeCodeEx.SmartDate ? ".DBValue" : "") %>).DbType = DbType.<%= TypeHelper.GetDbType(p.PropertyType) %>;
  106. <%
  107. }
  108. }
  109. }
  110. string hookArgs = string.Empty;
  111. if (c.Properties.Count > 1)
  112. {
  113. hookArgs = ", crit";
  114. }
  115. else if (c.Properties.Count > 0)
  116. {
  117. hookArgs = ", " + HookSingleCriteria(c, "crit");
  118. }
  119. %>
  120. var rowsAffected = cmd.ExecuteNonQuery();
  121. if (rowsAffected == 0)
  122. throw new DataNotFoundException("<%= Info.ObjectName %>");
  123. }
  124. }
  125. }
  126. <%
  127. }
  128. }
  129. }
  130. %>