UserService.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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.User;
  8. namespace GreenTree.Nachtragsmanagement.Services.User
  9. {
  10. /// <summary>
  11. /// User service
  12. /// </summary>
  13. public class UserService : IUserService
  14. {
  15. #region Fields
  16. private readonly IRepository<Core.Domain.User.User> _userRepository;
  17. private readonly IRepository<Role> _roleRepository;
  18. private readonly IRepository<Function> _functionRepository;
  19. #endregion
  20. #region Ctor
  21. /// <summary>
  22. /// Initializes a new instance of the UserService class
  23. /// </summary>
  24. public UserService(
  25. IRepository<Core.Domain.User.User> userRepository,
  26. IRepository<Role> roleRepository,
  27. IRepository<Function> functionRepository)
  28. {
  29. _userRepository = userRepository;
  30. _roleRepository = roleRepository;
  31. _functionRepository = functionRepository;
  32. }
  33. #endregion
  34. #region User
  35. /// <summary>
  36. /// Gets all users
  37. /// </summary>
  38. public IList<Core.Domain.User.User> GetAllUsers()
  39. {
  40. return _userRepository.Table.ToList();
  41. }
  42. /// <summary>
  43. /// Gets a user by specified Id
  44. /// </summary>
  45. /// <param name="id">User identifier.</param>
  46. public Core.Domain.User.User GetUserById(int id)
  47. {
  48. return _userRepository.GetById(id);
  49. }
  50. /// <summary>
  51. /// Gets all users to the specified ids
  52. /// </summary>
  53. public IList<Core.Domain.User.User> GetUsersByIds(int[] ids)
  54. {
  55. return _userRepository.Table
  56. .Where(u => ids.Contains(u.Id))
  57. .ToList();
  58. }
  59. /// <summary>
  60. /// Gets a user by specified custom number
  61. /// </summary>
  62. /// <param name="customNumber">Customer number.</param>
  63. public Core.Domain.User.User GetUserByCustomNumber(string customNumber)
  64. {
  65. return _userRepository
  66. .Table.FirstOrDefault(u => u.CustomNumber == customNumber);
  67. }
  68. /// <summary>
  69. /// Insert a user
  70. /// </summary>
  71. /// <param name="user">User.</param>
  72. public void InsertUser(Core.Domain.User.User user)
  73. {
  74. _userRepository.Insert(user);
  75. }
  76. /// <summary>
  77. /// Update a user
  78. /// </summary>
  79. /// <param name="user">User.</param>
  80. public void UpdateUser(Core.Domain.User.User user)
  81. {
  82. _userRepository.Update(user);
  83. }
  84. /// <summary>
  85. /// Delete a user
  86. /// </summary>
  87. /// <param name="user">User.</param>
  88. public void DeleteUser(Core.Domain.User.User user)
  89. {
  90. _userRepository.Delete(user);
  91. }
  92. #endregion
  93. #region Role
  94. /// <summary>
  95. /// Gets all roles
  96. /// </summary>
  97. public IList<Role> GetAllRoles()
  98. {
  99. return _roleRepository.Table.ToList();
  100. }
  101. /// <summary>
  102. /// Gets a role by specified Id
  103. /// </summary>
  104. /// <param name="id">Role identifier.</param>
  105. public Role GetRoleById(int id)
  106. {
  107. return _roleRepository.GetById(id);
  108. }
  109. /// <summary>
  110. /// Gets all roles to the specified ids
  111. /// </summary>
  112. public IList<Role> GetRolesByIds(int[] ids)
  113. {
  114. return _roleRepository.Table
  115. .Where(r => ids.Contains(r.Id))
  116. .ToList();
  117. }
  118. /// <summary>
  119. /// Insert a user
  120. /// </summary>
  121. /// <param name="role">Role.</param>
  122. public void InsertRole(Role role)
  123. {
  124. _roleRepository.Insert(role);
  125. }
  126. /// <summary>
  127. /// Update a role
  128. /// </summary>
  129. /// <param name="role">Role.</param>
  130. public void UpdateRole(Role role)
  131. {
  132. _roleRepository.Update(role);
  133. }
  134. /// <summary>
  135. /// Delete a role
  136. /// </summary>
  137. /// <param name="role">Role.</param>
  138. public void DeleteRole(Role role)
  139. {
  140. _roleRepository.Delete(role);
  141. }
  142. #endregion
  143. #region Function
  144. /// <summary>
  145. /// Gets all functions
  146. /// </summary>
  147. public IList<Function> GetAllFunctions()
  148. {
  149. return _functionRepository.Table.ToList();
  150. }
  151. /// <summary>
  152. /// Gets a function by specified Id
  153. /// </summary>
  154. /// <param name="id">Function identifier.</param>
  155. public Function GetFunctionById(int id)
  156. {
  157. return _functionRepository.GetById(id);
  158. }
  159. /// <summary>
  160. /// Gets all functions to the specified ids
  161. /// </summary>
  162. public IList<Function> GetFunctionsByIds(int[] ids)
  163. {
  164. return _functionRepository.Table
  165. .Where(f => ids.Contains(f.Id))
  166. .ToList();
  167. }
  168. /// <summary>
  169. /// Insert a function
  170. /// </summary>
  171. /// <param name="function">Function.</param>
  172. public void InsertFunction(Function function)
  173. {
  174. _functionRepository.Insert(function);
  175. }
  176. /// <summary>
  177. /// Update a function
  178. /// </summary>
  179. /// <param name="function">Function.</param>
  180. public void UpdateFunction(Function function)
  181. {
  182. _functionRepository.Update(function);
  183. }
  184. /// <summary>
  185. /// Delete a function
  186. /// </summary>
  187. /// <param name="function">Function.</param>
  188. public void DeleteFunction(Function function)
  189. {
  190. _functionRepository.Delete(function);
  191. }
  192. #endregion
  193. }
  194. }