Пример #1
0
        public EventSingleState Create(@event model)
        {
            var eve = new EventSingleState
            {
                id          = model.id,
                title       = model.title,
                local       = model.local,
                initDate    = model.initDate,
                endDate     = model.endDate,
                description = model.description,
                nrOfTickets = model.nrOfTickets.Value,
                community   = communityFactory.Create(model.community),
                subscribers = model.eventSubscribers.Select <eventSubscribers, UsersCollectionState>(i => userFactory.Create(i.userInfo)),
                session     = model.session.Select <session, SessionsCollectionState>(i => sessionFactory.Create(i)),
                comments    = model.comment.Select <comment, CommentsCollectionState>(i => commentFactory.Create(i)),
                survey      = surveyFactory.Create(model.survey),
                tag         = model.tag.Select <tag, string>(i => i.name),
                _links      = new EventSingleState.Link()
            };

            //add hypermedia
            eve._links.self                = _links.Self(model.id);
            eve._links.sessions            = _links.Sessions(model.id);
            eve._links.community           = _links.Community(model.communityId.Value);
            eve._links.comments            = _links.Comments(model.id);
            eve._links.subscribers         = _links.Subscribers(model.id);
            eve._links.subscriberCheckedIn = _links.SubscribersCheckedIn(model.id);

            return(eve);
        }
        private async Task <HttpResponseMessage> GetUserCommunities(string id, string type)
        {
            IStateFactory <community, CommunitiesCollectionState> _stateFactory = new CommunitiesCollectionFactory(new CommunityLinkFactory(Request));
            var instance = CommunityService.GetInstance();

            OperationResult <IEnumerable <community> > communities = null;

            if (type == "member")
            {
                communities = await instance.GetCommunitiesFromUserByRole(id, Services.Models.Roles.Role.Member);
            }
            else if (type == "admin")
            {
                communities = await instance.GetCommunitiesFromUserByRole(id, Services.Models.Roles.Role.Admin);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new BadRequest(Request.RequestUri, "The values of query string must be 'member' or 'admin"), "application/problem+json"));
            }

            if (communities.Success)
            {
                var res = communities.Result.Select <community, CommunitiesCollectionState>(i => _stateFactory.Create(i));
                return(Request.CreateResponse(HttpStatusCode.OK, new { communities = res }, "application/json"));
            }
            return(Request.CreateResponse(HttpStatusCode.NotFound, new NotFound(Request.RequestUri, communities.Message), "application/problem+json"));
        }
        public async Task <HttpResponseMessage> Get()
        {
            IStateFactory <community, CommunitiesCollectionState> _stateFactory = new CommunitiesCollectionFactory(new CommunityLinkFactory(Request));
            var instance = CommunityService.GetInstance();

            var communities = await instance.GetAllAsync();

            if (communities.Success)
            {
                var res = communities.Result.Select <community, CommunitiesCollectionState>(i => _stateFactory.Create(i));
                return(Request.CreateResponse(HttpStatusCode.OK, new { communities = res }, "application/json"));
            }
            return(Request.CreateResponse(HttpStatusCode.ServiceUnavailable, new ServiceUnvailable(Request.RequestUri, communities.Message), "application/problem+json"));
        }
        public async Task <HttpResponseMessage> PostSearch([FromBody]  CommunitySearch body)
        {
            var instance = CommunityService.GetInstance();
            IStateFactory <community, CommunitiesCollectionState> _stateFactory = new CommunitiesCollectionFactory(new CommunityLinkFactory(Request));

            if (body.isEmpty())
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new BadRequest(Request.RequestUri, "The body must not be null"), "application/problem+json"));
            }

            var communities = await instance.Search(body.location, body.name, body.tags);

            if (communities.Success)
            {
                var res = communities.Result.Select <community, CommunitiesCollectionState>(i => _stateFactory.Create(i));
                return(Request.CreateResponse(HttpStatusCode.OK, res, "application/json"));
            }

            return(Request.CreateResponse(HttpStatusCode.Conflict, new Conflict(Request.RequestUri, communities.Message), "application/problem+json"));
        }