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> GetFromCommunity(int id) { IStateFactory <notice, NoticesCollectionState> _stateFactory = new NoticesCollectionFactory(new NoticeLinkFactory(Request)); var instace = NoticeService.GetInstance(); var notices = await instace.GetNoticesFromCommunity(id); if (notices.Success) { var res = notices.Result.Select <notice, NoticesCollectionState>(i => _stateFactory.Create(i)); return(Request.CreateResponse(HttpStatusCode.OK, new { notices = res }, "application/json")); } return(Request.CreateResponse(HttpStatusCode.NotFound, new NotFound(Request.RequestUri, notices.Message), "application/problem+json")); }