public async Task <ActionResult> CreateNews(News news)
        {
            if (ModelState.IsValid)
            {
                NoticeService service = NoticeService.GetInstance();

                CreateNotice newNews = new CreateNotice()
                {
                    title       = news.Title,
                    communityId = news.CommunityId,
                    description = news.Description,
                    initialDate = DateTime.Now,
                    userId      = User.Identity.GetUserId()
                };
                var res = await service.PostNoticeAsync(newNews);// retorna o id do evento que foi criado se quiser fazer redirect falta o nome da comunidade

                if (res.Success)
                {
                    return(Json(new { url = Constants.WebAPPAddress + "/community/" + news.CommunityName }));
                }

                else
                {
                    //tratar do erro que ainda falta pode dar um erro na inserção
                    ViewBag.Error   = true;
                    ViewBag.Message = res.Message;
                }
            }

            return(PartialView("_CreateEvent", news));
        }
Example #2
0
        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"));
        }
Example #3
0
        public async Task <HttpResponseMessage> Get(int id)
        {
            IStateFactory <notice, NoticeSingleState> _stateFactory = new NoticeSingleFactory(Request);
            var instance = NoticeService.GetInstance();

            var notice = await instance.GetByIdAsync(id);

            if (notice.Success)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, _stateFactory.Create(notice.Result), "application/json"));
            }

            return(Request.CreateResponse(HttpStatusCode.NotFound, new NotFound(Request.RequestUri, notice.Message), "application/problem+json"));
        }
 public void initialize()
 {
     noticeService = NoticeService.GetInstance();
 }