/* * [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")); }
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")); }
public CommunitySingleState Create(community model) { var community = new CommunitySingleState { id = model.id, name = model.name, local = model.local, description = model.description, avatar = model.avatar, foundationDate = model.foundationDate.Value, events = [email protected] <@event, EventsCollectionState>(i => eventFactory.Create(i)), notices = model.notice.Select <notice, NoticesCollectionState>(i => noticeFactory.Create(i)), admins = model.admins.Select <userInfo, UsersCollectionState>(i => userFactory.Create(i)), members = model.members.Select <userInfo, UsersCollectionState>(i => userFactory.Create(i)), comments = model.comment.Select <comment, CommentsCollectionState>(i => commentFactory.Create(i)), tags = model.tag.Select <tag, string>(i => i.name), _Links = new CommunitySingleState.Link() }; //Add hyperMedia community._Links.Self = _links.Self(model.id); community._Links.Events = _links.Events(model.id); community._Links.PastEvents = _links.PastEvents(model.id); community._Links.FutureEvents = _links.FutureEvents(model.id); community._Links.Members = _links.Members(model.id); community._Links.Admins = _links.Admins(model.id); community._Links.Notices = _links.Notices(model.id); community._Links.Comments = _links.Comments(model.id); return(community); }
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")); }
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")); }
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); }
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")); }
public SessionSingleState Create(session model) { var session = new SessionSingleState { id = model.id, description = model.description, initialDate = model.initialDate, endDate = model.endDate.Value, speaker = model.speakerName + " " + model.lastName, title = model.title, profileSpeaker = model.linkOfSpeaker, _event = eventFactory.Create(model.@event), questions = model.question.Select <question, QuestionsCollectionState>(i => questionFactory.Create(i)), _links = new SessionSingleState.Link() }; session._links.self = _links.Self(model.id); session._links.questions = _links.Questions(model.id); session._links._event = _links.Event(model.eventId.Value); return(session); }