Guest User

Untitled

a guest
Jun 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using BuildAFluentInterface.Interfaces;
  3.  
  4. namespace BuildAFluentInterface
  5. {
  6. public class DeleteQueryWithGrammar : ICanAddCondition, ICanAddWhereValue, ICanAddWhereOrRun
  7. {
  8. private readonly string _tableName;
  9. private readonly List<WhereCondition> _whereConditions = new List<WhereCondition>();
  10.  
  11. private string _currentWhereConditionColumn;
  12.  
  13. // Private constructor, to force object instantiation from the fluent method(s)
  14. private DeleteQueryWithGrammar(string tableName)
  15. {
  16. _tableName = tableName;
  17. }
  18.  
  19. #region Initiating Method(s)
  20.  
  21. public static ICanAddCondition DeleteRowsFrom(string tableName)
  22. {
  23. return new DeleteQueryWithGrammar(tableName);
  24. }
  25.  
  26. #endregion
  27.  
  28. #region Chaining Method(s)
  29.  
  30. public ICanAddWhereValue Where(string columnName)
  31. {
  32. _currentWhereConditionColumn = columnName;
  33.  
  34. return this;
  35. }
  36.  
  37. public ICanAddWhereOrRun IsEqualTo(object value)
  38. {
  39. _whereConditions.Add(new WhereCondition(_currentWhereConditionColumn, WhereCondition.ComparisonMethod.EqualTo, value));
  40.  
  41. return this;
  42. }
  43.  
  44. public ICanAddWhereOrRun IsNotEqualTo(object value)
  45. {
  46. _whereConditions.Add(new WhereCondition(_currentWhereConditionColumn, WhereCondition.ComparisonMethod.NotEqualTo, value));
  47.  
  48. return this;
  49. }
  50.  
  51. #endregion
  52.  
  53.  
  54. #region Executing Method(s)
  55.  
  56. public void AllRows()
  57. {
  58. ExecuteThisQuery();
  59. }
  60.  
  61. public void RunNow()
  62. {
  63. ExecuteThisQuery();
  64. }
  65.  
  66. #endregion
  67.  
  68. private void ExecuteThisQuery()
  69. {
  70. // Code to build and execute the delete query
  71. }
  72. }
  73. }
Add Comment
Please, Sign In to add comment