PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/1.31/src/Platform/Services/RoleService.cs

#
C# | 87 lines | 56 code | 6 blank | 25 comment | 4 complexity | 519c1fe484f88194f0baea1f1c908a0e MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1
  1. /****************************************************************************************************
  2. Copyright (C) 2010 RapidWebDev Organization (http://rapidwebdev.org)
  3. Author: Eunge, Legal Name: Jian Liu, Email: eunge.liu@RapidWebDev.org
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ****************************************************************************************************/
  15. using System;
  16. using System.IO;
  17. using System.Data;
  18. using System.Collections;
  19. using System.Collections.Generic;
  20. using System.Collections.ObjectModel;
  21. using System.Collections.Specialized;
  22. using System.Configuration;
  23. using System.Linq;
  24. using System.Linq.Expressions;
  25. using System.ServiceModel;
  26. using System.ServiceModel.Activation;
  27. using System.ServiceModel.Web;
  28. using System.Web;
  29. using System.Web.SessionState;
  30. using System.Web.Security;
  31. using System.Web.UI;
  32. using System.Web.UI.HtmlControls;
  33. using System.Web.UI.WebControls;
  34. using System.Web.UI.WebControls.WebParts;
  35. using System.Xml.Linq;
  36. using BaoJianSoft.Common;
  37. using BaoJianSoft.Common.Caching;
  38. using BaoJianSoft.Common.Web;
  39. using BaoJianSoft.Platform.Linq;
  40. namespace BaoJianSoft.Platform.Services
  41. {
  42. /// <summary>
  43. /// The service implementation to search roles
  44. /// </summary>
  45. [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  46. public class RoleService : IRoleService
  47. {
  48. private static ICache cache = SpringContext.Current.GetObject<ICache>();
  49. private static IOrganizationApi organizationApi = SpringContext.Current.GetObject<IOrganizationApi>();
  50. private static IRoleApi roleApi = SpringContext.Current.GetObject<IRoleApi>();
  51. /// <summary>
  52. /// Get all roles associated to the specified organization.
  53. /// </summary>
  54. /// <param name="organizationId"></param>
  55. /// <returns></returns>
  56. public Collection<RoleObject> FindByOrganizationIdJson(string organizationId)
  57. {
  58. if (string.IsNullOrEmpty(organizationId))
  59. throw new BadRequestException("The parameter \"organizationId\" is not specified.");
  60. Guid organizationIdValue = Guid.Empty;
  61. try
  62. {
  63. organizationIdValue = new Guid(organizationId);
  64. }
  65. catch
  66. {
  67. throw new BadRequestException("The parameter \"organizationId\" is invalid.");
  68. }
  69. OrganizationObject organizationObject = organizationApi.GetOrganization(organizationIdValue);
  70. if (organizationObject == null)
  71. throw new BadRequestException("The parameter \"organizationId\" is invalid.");
  72. int recordCount;
  73. Expression<Func<Role, bool>> predicate = role => role.RolesInOrganizationTypes.Any(rolesInOrganizationType => rolesInOrganizationType.OrganizationTypeId == organizationObject.OrganizationTypeId);
  74. IEnumerable<RoleObject> results = roleApi.FindRoles(predicate, null, "RoleName ASC", 0, int.MaxValue, out recordCount);
  75. return new Collection<RoleObject>(results.ToList());
  76. }
  77. }
  78. }