public async Task <ActionResult> Get(string id) { CommunityService service = CommunityService.GetInstance(); var res = await service.GetByNameAsync(id); if (res.Success) { var principal = await Request.GetOwinContext().Authentication.AuthenticateAsync("OAuth"); if (principal == null) { ViewBag.token = "none"; } else { var token = principal.Identity.FindFirst("access_token").Value; ViewBag.token = token; } ViewBag.hasEvents = [email protected] != 0 ? true : false; ViewBag.hasNotices = res.Result.notice.Count != 0 ? true : false; ViewBag.Owner = res.Result.admins.Any(u => u.id == User.Identity.GetUserId()); ViewBag.Twitter = getCommunityTwitterFromDB(res.Result); res.Result.@event = [email protected](x => x.initDate).Reverse().ToList(); res.Result.notice = res.Result.notice.OrderBy(x => x.initialDate).Reverse().ToList(); return(View(res.Result)); } //mandar no viewBag a mensagem de erro para depois ser apresentada na view do Index ViewBag.Error = true; ViewBag.ErrorMessage = res.Message; return(RedirectToAction("index")); }
public async Task <ActionResult> PutCommunity(Community community) { CommunityService service = CommunityService.GetInstance(); CreateCommunity newCommunity = new CreateCommunity() { Id = community.Id, Name = community.Name, Description = community.Description, Local = community.Local, FoundationDate = community.date, Site = community.Site, GitHub = community.GitHub, Mail = community.Mail, Avatar = community.Avatar == null ?null: community.Avatar.InputStream, UserId = User.Identity.GetUserId() }; var updated = await service.UpdateCommunity(newCommunity); if (updated.Success) { return(Redirect(Request.UrlReferrer.PathAndQuery)); } return(PartialView("_UpdateCommunity", community)); }
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> PostSocialNetwork([FromBody] SocialNet body, int id) { var adminId = GetToken(); var instance = CommunityService.GetInstance(); var accessToken = await getLongLiveToken(body.Token, body); if (adminId == null) { return(Request.CreateResponse(HttpStatusCode.Forbidden, new Forbidden(Request.RequestUri, "token not present in authorization header or not valid"), "application/problem+json")); } if (body == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new BadRequest(Request.RequestUri, "The body must not be null"), "application/problem+json")); } var res = await instance.InsertSocialNetwork(new CreateCommunitySocial { adminId = adminId, social = body.Social, token = accessToken, url = body.Url, communityId = id }); if (res.Success) { return(Request.CreateResponse(HttpStatusCode.OK, new { }, "application/json")); } else { return(Request.CreateResponse(HttpStatusCode.Conflict, new Conflict(Request.RequestUri, res.Message), "application/problem+json")); } }
public async Task <ActionResult> Search() { //fazer verificação CommunityService service = CommunityService.GetInstance(); var result = await service.GetAllAsync(); return(View(result.Result)); }
public async Task <HttpResponseMessage> Get(int id) { IStateFactory <community, CommunitySingleState> _stateFactory = new CommunitySingleFactory(Request); var instance = CommunityService.GetInstance(); var community = await instance.GetByIdAsync(id); if (community.Success) { return(Request.CreateResponse(HttpStatusCode.OK, _stateFactory.Create(community.Result), "application/json")); } return(Request.CreateResponse(HttpStatusCode.NotFound, new NotFound(Request.RequestUri, community.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")); }
public async Task <ActionResult> Create(Community community) { if (ModelState.IsValid) { CommunityService service = CommunityService.GetInstance(); //ImageCommunityService imgService = new ImageCommunityService(service); CreateCommunity newCommunity = new CreateCommunity() { Name = community.Name, Description = community.Description, Local = community.Local, FoundationDate = community.date, Avatar = community.Avatar == null?null:community.Avatar.InputStream, UserId = User.Identity.GetUserId(), Latitude = community.Latitude, Longitude = community.Longitude }; var res = await service.CreateCommunity(newCommunity); if (res.Success) { return(RedirectToAction("Get", new { id = community.Name })); } else { ViewBag.Error = true; ViewBag.Message = res.Message; } return(View(community)); } else { return(View(community)); } }
public async Task <ActionResult> DeleteCommunity(DeleteCommunity community) { CommunityService service = CommunityService.GetInstance(); var res = await service.GetByIdAsync(community.Id); if (res.Success) { if (res.Result.name == community.Name) { var deleted = await service.DeleteCommunity(new CreateCommunity { Id = community.Id, UserId = User.Identity.GetUserId() }); if (deleted.Success) { return(RedirectToAction("Index", "Home")); } } else { return(PartialView("_DeleteCommunity", community)); } } return(View()); }
public async Task <HttpResponseMessage> PutUser([FromBody] InputModel body, int id) { IStateFactory <community, CommunitiesCollectionState> _stateFactory = new CommunitiesCollectionFactory(new CommunityLinkFactory(Request)); var instance = CommunityService.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")); } if (body == null || body.Type == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new BadRequest(Request.RequestUri, "The body must have a type with value:'member' or 'admin'"), "application/problem+json")); } string type = body.Type; if (type == "member") { var res = await instance.InsertMember(id, token); if (res.Success) { return(Request.CreateResponse(HttpStatusCode.OK, new { }, "application/json")); } else { return(Request.CreateResponse(HttpStatusCode.Conflict, new Conflict(Request.RequestUri, res.Message), "application/problem+json")); } } else if (type == "organizer") { var res = await instance.InsertAdmin(id, GetToken(), body.UserId); } return(Request.CreateResponse(HttpStatusCode.BadRequest, new BadRequest(Request.RequestUri, "The body must have a type with value:'member' or 'admin'"), "application/problem+json")); }
public void initialize() { communityService = CommunityService.GetInstance(); }