Ejemplo n.º 1
0
        public ResponseResource DragDropRuleSection(IPrincipal principal, DragDropMembershipRuleSectionRequest request)
        {
            var user           = _dependencies.UserService.GetAuthenticatedUser(principal);
            var draggedSection = GetMembershipRuleSection(request.DraggedMembershipRuleSectionId);
            var permissions    = _dependencies.OrganisationService.GetMemberPermissions(user, draggedSection);

            if (!permissions.Contains(ShurahOrganisationPermission.EditMembershipRules.ToString()))
            {
                return(new ResponseResource {
                    HasError = true, Error = "Access Denied!"
                });
            }
            var droppedOnSection = GetMembershipRuleSection(request.DroppedOnMembershipRuleSectionId);
            var dropPermissions  = _dependencies.OrganisationService.GetMemberPermissions(user, droppedOnSection);

            if (!dropPermissions.Contains(ShurahOrganisationPermission.EditMembershipRules.ToString()))
            {
                return(new ResponseResource {
                    HasError = true, Error = "Access Denied!"
                });
            }
            var siblingSections = droppedOnSection.ShurahBasedOrganisation.MembershipRuleSections.Where(s =>
                                                                                                        (s.ParentMembershipRuleSection == null && droppedOnSection.ParentMembershipRuleSection == null) ||
                                                                                                        (s.ParentMembershipRuleSection != null && droppedOnSection.ParentMembershipRuleSection != null &&
                                                                                                         s.ParentMembershipRuleSection.ParentMembershipRuleSectionId ==
                                                                                                         droppedOnSection.ParentMembershipRuleSection.ParentMembershipRuleSectionId)
                                                                                                        ).OrderBy(x => x.Sequence).ToList();

            Enumerable.Range(0, siblingSections.Count()).ToList().ForEach(i =>
            {
                siblingSections[i].Sequence = i * 2;
            });

            if (draggedSection.ParentMembershipRuleSection == null &&
                droppedOnSection.ParentMembershipRuleSection != null)
            {
                draggedSection.ParentMembershipRuleSection = new MembershipRuleSectionRelationship();
            }

            if (draggedSection.ParentMembershipRuleSection != null && droppedOnSection.ParentMembershipRuleSection != null)
            {
                draggedSection.ParentMembershipRuleSection.ParentMembershipRuleSectionId
                    = droppedOnSection.ParentMembershipRuleSection.ParentMembershipRuleSectionId;
            }
            if (HasNoRootSection(droppedOnSection))
            {
                return(new ResponseResource {
                    HasError = true, Error = "cannot paste section on itself"
                });
            }
            if (draggedSection.ParentMembershipRuleSection != null && droppedOnSection.ParentMembershipRuleSection == null)
            {
                _dependencies.StorageService.SetOf <MembershipRuleSectionRelationship>().Remove(draggedSection.ParentMembershipRuleSection);
            }
            draggedSection.Sequence = droppedOnSection.Sequence + 1;
            _dependencies.StorageService.SaveChanges();
            return(new ResponseResource());
        }
Ejemplo n.º 2
0
 public ResponseResource Post(DragDropMembershipRuleSectionRequest request)
 {
     return(_service.DragDropRuleSection(User, request));
 }
 public HttpResponseMessage Post(DragDropMembershipRuleSectionRequest request)
 {
     return(Request.CreateResponse(HttpStatusCode.OK, _service.DragDropRuleSection(User, request)));
 }