PageRenderTime 3558ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/XERP.Domain/XERP.Domain.MenuSecurityDomain/Services/MenuItemServiceAgent.cs

http://xerpdotnet.codeplex.com
C# | 274 lines | 231 code | 41 blank | 2 comment | 19 complexity | fd4405762ab567dc09f30c732a71e3b3 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Data.Services.Client;
  5. using XERP.Domain.MenuSecurityDomain.MenuSecurityDataService;
  6. namespace XERP.Domain.MenuSecurityDomain.Services
  7. {
  8. public class MenuItemServiceAgent : XERP.Domain.MenuSecurityDomain.Services.IMenuItemServiceAgent
  9. {
  10. #region Initialize Service
  11. public MenuItemServiceAgent()
  12. {
  13. ServiceUtility serviceUtility = new ServiceUtility();
  14. _rootUri = serviceUtility.BaseUri;
  15. //this context will be used for read only gets...
  16. _context = new MenuSecurityEntities(_rootUri);
  17. _context.MergeOption = MergeOption.NoTracking;
  18. }
  19. #endregion Initialize Service
  20. #region Properties
  21. private Uri _rootUri;
  22. private MenuSecurityEntities _context;
  23. #endregion Properties
  24. #region Read Only Methods No Repository Required
  25. public bool MenuItemRepositoryIsDirty()
  26. {
  27. return MenuItemSingletonRepository.Instance.RepositoryIsDirty();
  28. }
  29. public bool MenuItemTypeRepositoryIsDirty()
  30. {
  31. return MenuItemTypeSingletonRepository.Instance.RepositoryIsDirty();
  32. }
  33. public bool MenuItemCodeRepositoryIsDirty()
  34. {
  35. return MenuItemCodeSingletonRepository.Instance.RepositoryIsDirty();
  36. }
  37. public IEnumerable<MenuItemType> GetMenuItemTypesReadOnly(string companyID)
  38. {
  39. _context.MergeOption = MergeOption.NoTracking;
  40. _context.IgnoreResourceNotFoundException = true;
  41. var queryResult = (from q in _context.MenuItemTypes
  42. where q.CompanyID == companyID
  43. select q);
  44. return queryResult;
  45. }
  46. public IEnumerable<MenuItemCode> GetMenuItemCodesReadOnly(string companyID)
  47. {
  48. _context.MergeOption = MergeOption.NoTracking;
  49. _context.IgnoreResourceNotFoundException = true;
  50. var queryResult = (from q in _context.MenuItemCodes
  51. where q.CompanyID == companyID
  52. select q);
  53. return queryResult;
  54. }
  55. public IEnumerable<DBStoredImage> GetDBStoredImagesReadOnly(string companyID)
  56. {
  57. _context.MergeOption = MergeOption.NoTracking;
  58. _context.IgnoreResourceNotFoundException = true;
  59. var queryResult = (from q in _context.DBStoredImages
  60. where q.CompanyID == companyID
  61. select q);
  62. return queryResult;
  63. }
  64. public IEnumerable<ExecutableProgram> GetExecutableProgramsReadOnly(string companyID)
  65. {
  66. _context.MergeOption = MergeOption.NoTracking;
  67. _context.IgnoreResourceNotFoundException = true;
  68. var queryResult = (from q in _context.ExecutablePrograms
  69. where q.CompanyID == companyID
  70. select q);
  71. return queryResult;
  72. }
  73. public bool MenuItemExists(string menuItemID, string companyID)
  74. {
  75. _context.MergeOption = MergeOption.NoTracking;
  76. _context.IgnoreResourceNotFoundException = true;
  77. var queryResult = (from q in _context.MenuItems
  78. where q.MenuItemID == menuItemID &&
  79. q.CompanyID == companyID
  80. select q).ToList();
  81. if (queryResult != null && queryResult.Count() > 0)
  82. return true;
  83. return false;
  84. }
  85. public bool MenuItemTypeExists(string menuItemTypeID, string companyID)
  86. {
  87. _context.MergeOption = MergeOption.NoTracking;
  88. _context.IgnoreResourceNotFoundException = true;
  89. var queryResult = (from q in _context.MenuItemTypes
  90. where q.MenuItemTypeID == menuItemTypeID
  91. where q.CompanyID == companyID
  92. select q).ToList();
  93. if (queryResult != null && queryResult.Count() > 0)
  94. return true;
  95. return false;
  96. }
  97. public bool MenuItemCodeExists(string menuItemCodeID, string companyID)
  98. {
  99. _context.MergeOption = MergeOption.NoTracking;
  100. _context.IgnoreResourceNotFoundException = true;
  101. var queryResult = (from q in _context.MenuItemCodes
  102. where q.MenuItemCodeID == menuItemCodeID &&
  103. q.CompanyID == companyID
  104. select q).ToList();
  105. if (queryResult != null && queryResult.Count() > 0)
  106. return true;
  107. return false;
  108. }
  109. public IEnumerable<Temp> GetMetaData(string tableName)
  110. {//WCF Data Services does not allow for Complex query where you need to mine linked table data
  111. //with the same query so I have opted to use a webget sever side and do the query their...
  112. _context.IgnoreResourceNotFoundException = true;
  113. _context.MergeOption = MergeOption.NoTracking;
  114. var query = _context.CreateQuery<Temp>("GetMetaData").AddQueryOption("TableName", "'" + tableName + "'");
  115. return query;
  116. }
  117. #endregion Read Only Methods No Repository Required
  118. #region MenuItem Repository CRUD
  119. public IEnumerable<MenuItem> RefreshMenuItem(string autoIDs)
  120. {
  121. return MenuItemSingletonRepository.Instance.Refresh(autoIDs);
  122. }
  123. public IEnumerable<MenuItem> GetMenuItems(string companyID)
  124. {
  125. return MenuItemSingletonRepository.Instance.GetMenuItems(companyID);
  126. }
  127. public IEnumerable<MenuItem> GetMenuItems(MenuItem menuItemQuerryObject, string companyID)
  128. {
  129. return MenuItemSingletonRepository.Instance.GetMenuItems(menuItemQuerryObject, companyID);
  130. }
  131. public IEnumerable<MenuItem> GetMenuItemByID(string menuItemID, string companyID)
  132. {
  133. return MenuItemSingletonRepository.Instance.GetMenuItemByID(menuItemID, companyID);
  134. }
  135. public void CommitMenuItemRepository()
  136. {
  137. MenuItemSingletonRepository.Instance.CommitRepository();
  138. }
  139. public void UpdateMenuItemRepository(MenuItem menuItem)
  140. {
  141. MenuItemSingletonRepository.Instance.UpdateRepository(menuItem);
  142. }
  143. public void AddToMenuItemRepository(MenuItem menuItem)
  144. {
  145. MenuItemSingletonRepository.Instance.AddToRepository(menuItem);
  146. }
  147. public void DeleteFromMenuItemRepository(MenuItem menuItem)
  148. {
  149. MenuItemSingletonRepository.Instance.DeleteFromRepository(menuItem);
  150. }
  151. public EntityStates GetMenuItemEntityState(MenuItem menuItem)
  152. {
  153. return MenuItemSingletonRepository.Instance.GetMenuItemEntityState(menuItem);
  154. }
  155. #endregion MenuItem Repository CRUD
  156. #region MenuItemType Repository CRUD
  157. public IEnumerable<MenuItemType> RefreshMenuItemType(string autoIDs)
  158. {
  159. return MenuItemTypeSingletonRepository.Instance.Refresh(autoIDs);
  160. }
  161. public IEnumerable<MenuItemType> GetMenuItemTypes(string companyID)
  162. {
  163. return MenuItemTypeSingletonRepository.Instance.GetMenuItemTypes(companyID);
  164. }
  165. public IEnumerable<MenuItemType> GetMenuItemTypes(MenuItemType menuItemTypeQuerryObject, string companyID)
  166. {
  167. return MenuItemTypeSingletonRepository.Instance.GetMenuItemTypes(menuItemTypeQuerryObject, companyID);
  168. }
  169. public IEnumerable<MenuItemType> GetMenuItemTypeByID(string menuItemTypeID, string companyID)
  170. {
  171. return MenuItemTypeSingletonRepository.Instance.GetMenuItemTypeByID(menuItemTypeID, companyID);
  172. }
  173. public void CommitMenuItemTypeRepository()
  174. {
  175. MenuItemTypeSingletonRepository.Instance.CommitRepository();
  176. }
  177. public void UpdateMenuItemTypeRepository(MenuItemType menuItemType)
  178. {
  179. MenuItemTypeSingletonRepository.Instance.UpdateRepository(menuItemType);
  180. }
  181. public void AddToMenuItemTypeRepository(MenuItemType menuItemType)
  182. {
  183. MenuItemTypeSingletonRepository.Instance.AddToRepository(menuItemType);
  184. }
  185. public void DeleteFromMenuItemTypeRepository(MenuItemType menuItemType)
  186. {
  187. MenuItemTypeSingletonRepository.Instance.DeleteFromRepository(menuItemType);
  188. }
  189. public EntityStates GetMenuItemTypeEntityState(MenuItemType menuItemType)
  190. {
  191. return MenuItemTypeSingletonRepository.Instance.GetMenuItemTypeEntityState(menuItemType);
  192. }
  193. #endregion MenuItemType Repository CRUD
  194. #region MenuItemCode Repository CRUD
  195. public IEnumerable<MenuItemCode> RefreshMenuItemCode(string autoIDs)
  196. {
  197. return MenuItemCodeSingletonRepository.Instance.Refresh(autoIDs);
  198. }
  199. public IEnumerable<MenuItemCode> GetMenuItemCodes(string companyID)
  200. {
  201. return MenuItemCodeSingletonRepository.Instance.GetMenuItemCodes(companyID);
  202. }
  203. public IEnumerable<MenuItemCode> GetMenuItemCodes(MenuItemCode menuItemCodeQuerryObject, string companyID)
  204. {
  205. return MenuItemCodeSingletonRepository.Instance.GetMenuItemCodes(menuItemCodeQuerryObject, companyID);
  206. }
  207. public IEnumerable<MenuItemCode> GetMenuItemCodeByID(string menuItemCodeID, string companyID)
  208. {
  209. return MenuItemCodeSingletonRepository.Instance.GetMenuItemCodeByID(menuItemCodeID, companyID);
  210. }
  211. public void CommitMenuItemCodeRepository()
  212. {
  213. MenuItemCodeSingletonRepository.Instance.CommitRepository();
  214. }
  215. public void UpdateMenuItemCodeRepository(MenuItemCode menuItemCode)
  216. {
  217. MenuItemCodeSingletonRepository.Instance.UpdateRepository(menuItemCode);
  218. }
  219. public void AddToMenuItemCodeRepository(MenuItemCode menuItemCode)
  220. {
  221. MenuItemCodeSingletonRepository.Instance.AddToRepository(menuItemCode);
  222. }
  223. public void DeleteFromMenuItemCodeRepository(MenuItemCode menuItemCode)
  224. {
  225. MenuItemCodeSingletonRepository.Instance.DeleteFromRepository(menuItemCode);
  226. }
  227. public EntityStates GetMenuItemCodeEntityState(MenuItemCode menuItemCode)
  228. {
  229. return MenuItemCodeSingletonRepository.Instance.GetMenuItemCodeEntityState(menuItemCode);
  230. }
  231. #endregion MenuItemCode Repository CRUD
  232. }
  233. }