コード例 #1
0
        public async Task <ActionResult> GetMemberships([FromHeader] string Authentication, [FromQuery] string groupId)
        {
            if (SessionManager.GetSessionState(Authentication) != SessionManager.SessionState.Authorized)
            {
                return(Unauthorized());
            }
            SessionInfo sessionInfo = SessionManager.GetSessionInfo(Authentication);

            if (sessionInfo == null)
            {
                return(Unauthorized());
            }


            using (UnitOfWork uow = new UnitOfWork())
            {
                MembershipRepository        membershipsRepo = new MembershipRepository(uow);
                IEnumerable <MembershipDTO> memberships     = null;

                int groupIdInt = 0;
                if (string.IsNullOrEmpty(groupId) || !int.TryParse(groupId, out groupIdInt) || groupIdInt <= 0)
                {
                    //get by user
                    memberships = await membershipsRepo.GetAllByUserId(sessionInfo.UserId);
                }
                else
                {
                    //get by group
                    memberships = await membershipsRepo.GetAllByGroupId(groupIdInt);
                }

                return(Ok(memberships));
            }
        }
コード例 #2
0
        public async Task <ActionResult> Delete([FromHeader] string Authentication, [FromQuery] string Id)
        {
            if (SessionManager.GetSessionState(Authentication) != SessionManager.SessionState.Authorized)
            {
                return(Unauthorized());
            }
            SessionInfo sessionInfo = SessionManager.GetSessionInfo(Authentication);

            if (sessionInfo == null)
            {
                return(Unauthorized());
            }

            int groupId = 0;

            if (!int.TryParse(Id, out groupId) || groupId <= 0)
            {
                return(BadRequest());
            }

            using (UnitOfWork uow = new UnitOfWork())
            {
                MembershipRepository        membershipRepository = new MembershipRepository(uow);
                IEnumerable <MembershipDTO> memberships          = await membershipRepository.GetAllByGroupId(groupId);

                if (memberships == null)
                {
                    return(NotFound());
                }

                foreach (var membership in memberships)
                {
                    await membershipRepository.Remove(membership.Id);
                }

                GroupsRepository groupsRepository = new GroupsRepository(uow);
                await groupsRepository.Remove(groupId);

                uow.Commit();
            }

            return(Ok());
        }