public ResponseResource DragAndDropRule(IPrincipal principal, DragAndDropMembershipRuleRequest request)
        {
            var user        = _dependencies.UserService.GetAuthenticatedUser(principal);
            var draggedRule = GetMembershipRule(request.DraggedMembershipRuleId);
            var permissionsForDraggedRule = _dependencies.OrganisationService.GetMemberPermissions(user, draggedRule);

            if (!permissionsForDraggedRule.Contains(ShurahOrganisationPermission.EditMembershipRules.ToString()))
            {
                return(new ResponseResource {
                    HasError = true, Error = "Access Denied!"
                });
            }
            var droppedRule = GetMembershipRule(request.DroppedMembershipRuleId);
            var permissionsForDroppedRule = _dependencies.OrganisationService.GetMemberPermissions(user, droppedRule);

            if (!permissionsForDroppedRule.Contains(ShurahOrganisationPermission.EditMembershipRules.ToString()))
            {
                return(new ResponseResource {
                    HasError = true, Error = "Access Denied!"
                });
            }
            var siblingRules = droppedRule.MembershipRuleSection.MembershipRules.OrderBy(x => x.Sequence).ToList();

            Enumerable.Range(0, siblingRules.Count()).ToList().ForEach(i =>
            {
                siblingRules[i].Sequence = i * 2;
            });
            draggedRule.Sequence = droppedRule.Sequence + 1;
            draggedRule.MembershipRuleSection   = droppedRule.MembershipRuleSection;
            draggedRule.MembershipRuleSectionId = draggedRule.MembershipRuleSectionId;
            _dependencies.StorageService.SaveChanges();
            return(new ResponseResource());
        }
 public ResponseResource Post(DragAndDropMembershipRuleRequest request)
 {
     return(_service.DragAndDropRule(User, request));
 }
Пример #3
0
 public HttpResponseMessage Post(DragAndDropMembershipRuleRequest request)
 {
     return(Request.CreateResponse(HttpStatusCode.OK, _service.DragAndDropRule(User, request)));
 }