AppendixService.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using GreenTree.Nachtragsmanagement.Core.Data;
  7. using GreenTree.Nachtragsmanagement.Core.Domain.Appendix;
  8. using GreenTree.Nachtragsmanagement.Core.Domain.Invoice;
  9. namespace GreenTree.Nachtragsmanagement.Services.Appendix
  10. {
  11. public class AppendixService : IAppendixService
  12. {
  13. #region Fields
  14. private readonly IRepository<Core.Domain.Appendix.Appendix> _appendixRepository;
  15. private readonly IRepository<Category> _categoryRepository;
  16. private readonly IRepository<Invoice> _invoiceRepository;
  17. private readonly IRepository<State> _stateRepository;
  18. #endregion
  19. #region Ctor
  20. /// <summary>
  21. /// Initializes a new instance of the AppendixService class
  22. /// </summary>
  23. public AppendixService(
  24. IRepository<Core.Domain.Appendix.Appendix> appendixRepository,
  25. IRepository<Category> categoryRepository,
  26. IRepository<Invoice> invoiceRepository,
  27. IRepository<State> stateRepository)
  28. {
  29. _appendixRepository = appendixRepository;
  30. _categoryRepository = categoryRepository;
  31. _invoiceRepository = invoiceRepository;
  32. _stateRepository = stateRepository;
  33. }
  34. #endregion
  35. #region Appendix
  36. /// <summary>
  37. /// Gets all appendices
  38. /// </summary>
  39. public IList<Core.Domain.Appendix.Appendix> GetAllAppendices()
  40. {
  41. return _appendixRepository.Table.ToList();
  42. }
  43. /// <summary>
  44. /// Gets all appendices where the user is assigned to the corresponding site if the current role only allows assigned sites
  45. /// </summary>
  46. public IList<Core.Domain.Appendix.Appendix> GetAllUserAssignedAppendices(Core.Domain.User.User user)
  47. {
  48. if (user == null || (user != null && user.CurrentRole == null))
  49. return new List<Core.Domain.Appendix.Appendix>();
  50. if (user.CurrentRole.SeeOnlyAssigned)
  51. {
  52. return
  53. _appendixRepository.Table
  54. .Where(a => a.Site != null && a.Site.Users
  55. .Select(u => u.Id).Contains(user.Id))
  56. .ToList();
  57. }
  58. else
  59. return GetAllAppendices();
  60. }
  61. /// <summary>
  62. /// Gets a appendix by specified Id
  63. /// </summary>
  64. /// <param name="id">Appendix identifier.</param>
  65. public Core.Domain.Appendix.Appendix GetAppendixById(int id)
  66. {
  67. return _appendixRepository.GetById(id);
  68. }
  69. /// <summary>
  70. /// Gets all appendices to the specified ids
  71. /// </summary>
  72. public IList<Core.Domain.Appendix.Appendix> GetAppendicesByIds(int[] ids)
  73. {
  74. return _appendixRepository.Table
  75. .Where(u => ids.Contains(u.Id))
  76. .ToList();
  77. }
  78. /// <summary>
  79. /// Gets a appendix by specified custom number
  80. /// </summary>
  81. /// <param name="customNumber">Customer number.</param>
  82. public Core.Domain.Appendix.Appendix GetAppendixByCustomNumber(string customNumber)
  83. {
  84. return _appendixRepository
  85. .Table.FirstOrDefault(u => u.CustomNumber == customNumber);
  86. }
  87. /// <summary>
  88. /// Insert a appendix
  89. /// </summary>
  90. /// <param name="appendix">Appendix.</param>
  91. public void InsertAppendix(Core.Domain.Appendix.Appendix appendix)
  92. {
  93. _appendixRepository.Insert(appendix);
  94. }
  95. /// <summary>
  96. /// Update a appendix
  97. /// </summary>
  98. /// <param name="appendix">Appendix.</param>
  99. public void UpdateAppendix(Core.Domain.Appendix.Appendix appendix)
  100. {
  101. _appendixRepository.Update(appendix);
  102. }
  103. /// <summary>
  104. /// Delete a appendix
  105. /// </summary>
  106. /// <param name="appendix">Appendix.</param>
  107. public void DeleteAppendix(Core.Domain.Appendix.Appendix appendix)
  108. {
  109. _appendixRepository.Delete(appendix);
  110. }
  111. #endregion
  112. #region Category
  113. /// <summary>
  114. /// Gets all categories
  115. /// </summary>
  116. public IList<Category> GetAllCategories()
  117. {
  118. return _categoryRepository.Table.ToList();
  119. }
  120. /// <summary>
  121. /// Gets a category by specified Id
  122. /// </summary>
  123. /// <param name="id">Category identifier.</param>
  124. public Category GetCategoryById(int id)
  125. {
  126. return _categoryRepository.GetById(id);
  127. }
  128. /// <summary>
  129. /// Gets all categories to the specified ids
  130. /// </summary>
  131. public IList<Category> GetCategoriesByIds(int[] ids)
  132. {
  133. return _categoryRepository.Table
  134. .Where(r => ids.Contains(r.Id))
  135. .ToList();
  136. }
  137. /// <summary>
  138. /// Insert a appendix
  139. /// </summary>
  140. /// <param name="category">Category.</param>
  141. public void InsertCategory(Category category)
  142. {
  143. _categoryRepository.Insert(category);
  144. }
  145. /// <summary>
  146. /// Update a category
  147. /// </summary>
  148. /// <param name="category">Category.</param>
  149. public void UpdateCategory(Category category)
  150. {
  151. _categoryRepository.Update(category);
  152. }
  153. /// <summary>
  154. /// Delete a category
  155. /// </summary>
  156. /// <param name="category">Category.</param>
  157. public void DeleteCategory(Category category)
  158. {
  159. _categoryRepository.Delete(category);
  160. }
  161. #endregion
  162. #region Invoice
  163. /// <summary>
  164. /// Gets all invoices
  165. /// </summary>
  166. public IList<Invoice> GetAllInvoices()
  167. {
  168. return _invoiceRepository.Table.ToList();
  169. }
  170. /// <summary>
  171. /// Gets a invoice by specified Id
  172. /// </summary>
  173. /// <param name="id">Invoice identifier.</param>
  174. public Invoice GetInvoiceById(int id)
  175. {
  176. return _invoiceRepository.GetById(id);
  177. }
  178. /// <summary>
  179. /// Gets all invoices to the specified ids
  180. /// </summary>
  181. public IList<Invoice> GetInvoicesByIds(int[] ids)
  182. {
  183. return _invoiceRepository.Table
  184. .Where(r => ids.Contains(r.Id))
  185. .ToList();
  186. }
  187. /// <summary>
  188. /// Insert a appendix
  189. /// </summary>
  190. /// <param name="invoice">Invoice.</param>
  191. public void InsertInvoice(Invoice invoice)
  192. {
  193. _invoiceRepository.Insert(invoice);
  194. }
  195. /// <summary>
  196. /// Update a invoice
  197. /// </summary>
  198. /// <param name="invoice">Invoice.</param>
  199. public void UpdateInvoice(Invoice invoice)
  200. {
  201. _invoiceRepository.Update(invoice);
  202. }
  203. /// <summary>
  204. /// Delete a invoice
  205. /// </summary>
  206. /// <param name="invoice">Invoice.</param>
  207. public void DeleteInvoice(Invoice invoice)
  208. {
  209. _invoiceRepository.Delete(invoice);
  210. }
  211. #endregion
  212. #region State
  213. /// <summary>
  214. /// Gets all states
  215. /// </summary>
  216. public IList<State> GetAllStates()
  217. {
  218. return _stateRepository.Table.ToList();
  219. }
  220. /// <summary>
  221. /// Gets a state by specified Id
  222. /// </summary>
  223. /// <param name="id">State identifier.</param>
  224. public State GetStateById(int id)
  225. {
  226. return _stateRepository.GetById(id);
  227. }
  228. /// <summary>
  229. /// Gets all states to the specified ids
  230. /// </summary>
  231. public IList<State> GetStatesByIds(int[] ids)
  232. {
  233. return _stateRepository.Table
  234. .Where(r => ids.Contains(r.Id))
  235. .ToList();
  236. }
  237. /// <summary>
  238. /// Gets all appendices to the specified with the specified status id
  239. /// </summary>
  240. /// <param name="id">State identifier.</param>
  241. public IList<Core.Domain.Appendix.Appendix> GetAppendicesByState(int id)
  242. {
  243. return _appendixRepository.Table
  244. .Where(d => d.StateId == id)
  245. .ToList();
  246. }
  247. /// <summary>
  248. /// Gets the state which is defaultly selected
  249. /// </summary>
  250. public State GetDefaultState()
  251. {
  252. return _stateRepository.Table
  253. .FirstOrDefault(s => s.IsDefault);
  254. }
  255. /// <summary>
  256. /// Insert a appendix
  257. /// </summary>
  258. /// <param name="state">State.</param>
  259. public void InsertState(State state)
  260. {
  261. _stateRepository.Insert(state);
  262. }
  263. /// <summary>
  264. /// Update a state
  265. /// </summary>
  266. /// <param name="state">State.</param>
  267. public void UpdateState(State state)
  268. {
  269. _stateRepository.Update(state);
  270. }
  271. /// <summary>
  272. /// Delete a state
  273. /// </summary>
  274. /// <param name="state">State.</param>
  275. public void DeleteState(State state)
  276. {
  277. _stateRepository.Delete(state);
  278. }
  279. #endregion
  280. }
  281. }