コード例 #1
0
        public async Task <HttpResponseMessage> GetFromCommunity(int id, string time = "all")
        {
            IStateFactory <@event, EventsCollectionState> _stateFactory = new EventsCollectionFactory(new EventLinkFactory(Request));
            var instace = EventService.GetInstance();
            OperationResult <IEnumerable <@event> > events;

            if (time == "all")
            {
                events = await instace.GetEventsByCommunityId(id);
            }
            else if (time == "past")
            {
                events = await instace.GetAllEventsFromCommunityInTime(id, EventService.Time.Past);
            }
            else if (time == "future")
            {
                events = await instace.GetAllEventsFromCommunityInTime(id, EventService.Time.Future);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new BadRequest(Request.RequestUri, "The values of query string must be 'all', 'past' or 'future'"), "application/problem+json"));
            }

            if (events.Success)
            {
                var res = events.Result.Select <@event, EventsCollectionState>(i => _stateFactory.Create(i));
                return(Request.CreateResponse(HttpStatusCode.OK, new { events = res }, "application/json"));
            }
            return(Request.CreateResponse(HttpStatusCode.NotFound, new NotFound(Request.RequestUri, events.Message), "application/problem+json"));
        }
コード例 #2
0
        /*
         * [Route("{id:int}")]
         * public async Task<HttpResponseMessage> PutEvent([FromBody]  object body)
         * {
         *  throw new NotImplementedException();
         *
         * }*/

        private async Task <HttpResponseMessage> GetUserEvents(string id, string time)
        {
            IStateFactory <@event, EventsCollectionState> _stateFactory = new EventsCollectionFactory(new EventLinkFactory(Request));
            var instace = EventService.GetInstance();
            OperationResult <IEnumerable <@event> > events = null;

            if (time == "all")
            {
                events = await instace.GetAllEventsFromUserAsync(id, EventService.Time.All);
            }
            else if (time == "past")
            {
                events = await instace.GetAllEventsFromUserAsync(id, EventService.Time.Past);
            }
            else if (time == "future")
            {
                events = await instace.GetAllEventsFromUserAsync(id, EventService.Time.Future);
            }
            else
            {
                events = new OperationResult <IEnumerable <@event> > {
                    Success = false, Message = "time parameter must be one of this: 'past', 'all' or 'future'"
                }
            };

            if (events.Success)
            {
                var res = events.Result.Select <@event, EventsCollectionState>(i => _stateFactory.Create(i));
                return(Request.CreateResponse(HttpStatusCode.OK, new { events = res }, "application/json"));
            }
            return(Request.CreateResponse(HttpStatusCode.NotFound, new NotFound(Request.RequestUri, events.Message), "application/problem+json"));
        }
コード例 #3
0
 public CommunitySingleFactory(HttpRequestMessage request)
 {
     _links         = new CommunityLinkFactory(request);
     eventFactory   = new EventsCollectionFactory(new EventLinkFactory(request));
     noticeFactory  = new NoticesCollectionFactory(new NoticeLinkFactory(request));
     userFactory    = new UsersCollectionFactory(new UserLinkFactory(request));
     commentFactory = new CommentsCollectionFactory(request);
 }
コード例 #4
0
        public async Task <HttpResponseMessage> Get()
        {
            IStateFactory <@event, EventsCollectionState> _stateFactory = new EventsCollectionFactory(new EventLinkFactory(Request));
            var instance = EventService.GetInstance();

            var events = await instance.GetAllAsync();

            if (events.Success)
            {
                var res = events.Result.Select <@event, EventsCollectionState>(i => _stateFactory.Create(i));
                return(Request.CreateResponse(HttpStatusCode.OK, new { events = res }, "application/json"));
            }
            return(Request.CreateResponse(HttpStatusCode.ServiceUnavailable, new ServiceUnvailable(Request.RequestUri, events.Message), "application/problem+json"));
        }
コード例 #5
0
        public async Task <HttpResponseMessage> GetEventsToComeFromUser()
        {
            var id = (User as ClaimsPrincipal).FindFirst("sub").Value;

            IStateFactory <@event, EventsCollectionState> _stateFactory = new EventsCollectionFactory(new EventLinkFactory(Request));
            var instance = EventService.GetInstance();
            var events   = await instance.Get_Events_To_Come_From_Communities_Which_User_Belongs(id);

            if (events.Success)
            {
                var res = events.Result.Select <@event, EventsCollectionState>(i => _stateFactory.Create(i));
                return(Request.CreateResponse(HttpStatusCode.OK, new { events = res }, "application/json"));
            }
            return(Request.CreateResponse(HttpStatusCode.NotFound, new NotFound(Request.RequestUri, events.Message), "application/problem+json"));
        }
コード例 #6
0
        public async Task <HttpResponseMessage> GetNewEvents(string date)
        {
            var id = (User as ClaimsPrincipal).FindFirst("sub").Value;

            IStateFactory <@event, EventsCollectionState> _stateFactory = new EventsCollectionFactory(new EventLinkFactory(Request));
            var instance = EventService.GetInstance();
            var events   = await instance.Get_New_Events_From_Community(id, date);

            if (events.Success)
            {
                var res = events.Result.Select <@event, EventsCollectionState>(i => _stateFactory.Create(i));
                return(Request.CreateResponse(HttpStatusCode.OK, new { events = res }, "application/json"));
            }
            return(Request.CreateResponse(HttpStatusCode.NotFound, new NotFound(Request.RequestUri, events.Message), "application/problem+json"));

            // return null; await GetUserEvents(id, time);
        }
コード例 #7
0
        public async Task <HttpResponseMessage> PostSearch([FromBody]  EventSearch body)
        {
            var instance = EventService.GetInstance();
            IStateFactory <@event, EventsCollectionState> _stateFactory = new EventsCollectionFactory(new EventLinkFactory(Request));

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

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

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

            return(Request.CreateResponse(HttpStatusCode.Conflict, new Conflict(Request.RequestUri, events.Message), "application/problem+json"));
        }
コード例 #8
0
        public async Task <HttpResponseMessage> PutSubscribe(int id)
        {
            IStateFactory <@event, EventsCollectionState> _stateFactory = new EventsCollectionFactory(new EventLinkFactory(Request));
            var instance = EventService.GetInstance();

            var token = GetToken();

            if (token == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden, new Forbidden(Request.RequestUri, "token not present in authorization header or not valid"), "application/problem+json"));
            }

            var res = await instance.InsertSubscriber(id, token);

            if (res.Success)
            {   //falta acrescentar a foto quando tiver
                return(Request.CreateResponse(HttpStatusCode.OK, new{ id = res.Result.id, name = res.Result.name, lastName = res.Result.lastName }, "application/json"));
            }

            return(Request.CreateResponse(HttpStatusCode.Conflict, new Conflict(Request.RequestUri, res.Message), "application/problem+json"));
        }
コード例 #9
0
 public SessionSingleFactory(HttpRequestMessage Request)
 {
     _links          = new SessionLinkFactory(Request);
     questionFactory = new QuestionsCollectionFactory(new QuestionLinkFactory(Request));
     eventFactory    = new EventsCollectionFactory(new EventLinkFactory(Request));
 }