Пример #1
0
        public virtual ResponseResource CreateRuleSection(IPrincipal principal, CreateMembershipRuleSectionRequest request)
        {
            var user         = _dependencies.UserService.GetAuthenticatedUser(principal);
            var organisation = _dependencies.OrganisationService.GetOrganisation(request.OrganisationId);
            var permissions  = _dependencies.OrganisationService.GetMemberPermissions(user, organisation);

            if (!permissions.Contains(ShurahOrganisationPermission.EditMembershipRules.ToString()))
            {
                return(new ResponseResource {
                    HasError = true, Error = "Access Denied!"
                });
            }
            if (organisation.MembershipRuleSections.Any(s => s.UniqueInOrganisationName == request.UniqueUrlSlug))
            {
                return(new ResponseResource {
                    HasError = true, Error = "Url id not unique!"
                });
            }
            var ruleSection = _dependencies.StorageService.SetOf <MembershipRuleSection>().Create();

            _dependencies.StorageService.SetOf <MembershipRuleSection>().Add(ruleSection);
            if (request.ParentSectionId.HasValue)
            {
                var parentSection =
                    organisation.MembershipRuleSections.FirstOrDefault(x => x.Id == request.ParentSectionId);
                if (parentSection != null)
                {
                    ruleSection.ParentMembershipRuleSection = new MembershipRuleSectionRelationship
                    {
                        ParentMembershipRuleSectionId = parentSection.Id,
                    };
                }
            }
            ruleSection.ShurahBasedOrganisationId = organisation.Id;
            ruleSection.UniqueInOrganisationName  = request.UniqueUrlSlug;
            ruleSection.PublishedDateTimeUtc      = DateTime.UtcNow;
            ruleSection.Title = request.Title;
            _dependencies.StorageService.SaveChanges();
            return(new ResponseResource());
        }
Пример #2
0
 public ResponseResource Post(CreateMembershipRuleSectionRequest request)
 {
     return(_service.CreateRuleSection(User, request));
 }
 public HttpResponseMessage Post(CreateMembershipRuleSectionRequest request)
 {
     return(Request.CreateResponse(HttpStatusCode.OK, _service.CreateRuleSection(User, request)));
 }