public async Task <List <POI> > getPOIList(int?id) { client = PVWebApiHttpClient.GetClient(); IEnumerable <POIDTO> pois = null; var response = await client.GetAsync("api/POI/"); if (response.IsSuccessStatusCode) { pois = await response.Content.ReadAsAsync <IEnumerable <POIDTO> >(); } List <POI> poiList = new List <POI>(); foreach (POIDTO poiDTO in pois) { POI poi = DTOConverters.ConvertDTOToModel(poiDTO); if (id != null && poi.POIID != id) { poiList.Add(poi); } if (id == null) { poiList.Add(poi); } } return(poiList); }
public async Task <ActionResult> Create([Bind(Include = "PercursoID,Name,Description,StartHour,PercursoPOIsOrder")] Percurso percurso) { List <POI> list = await getPOIList(null); ViewBag.PoiList = list; if (!parsePercursoPOIs(percurso, list)) { return(View(percurso)); } var finishHour = Request.Form["FinishHour"]; if (finishHour != null) { percurso.FinishHour = percurso.StartHour.AddMinutes(double.Parse(finishHour, CultureInfo.InvariantCulture)); } percurso.Creator = PVWebApiHttpClient.getUsername(); client = PVWebApiHttpClient.GetClient(); var responseHttp = await client.PostAsJsonAsync("api/Percurso", percurso); if (responseHttp.IsSuccessStatusCode) { return(RedirectToAction("Index")); } return(View(percurso)); }
public async Task <ActionResult> Edit(int id, [Bind(Include = "PercursoID,Name,Description,Creator,FinishHour,StartHour,PercursoPOIsOrder")] Percurso percurso) { PercursoViewModel percursoModel = new PercursoViewModel(); List <POI> poiList = await getPOIList(null); percursoModel.Percurso = percurso; percursoModel.PercursoPOIs = poiList; percursoModel.PercursoOriginal = Request.Form["PercursoOriginal"].ToString(); if (!parsePercursoPOIs(percurso, poiList)) { return(View(percurso)); } var finishHour = Request.Form["Percurso.FinishHour"]; try { percurso.FinishHour = percurso.StartHour.AddMinutes(double.Parse(finishHour, CultureInfo.InvariantCulture)); }catch { // } client = PVWebApiHttpClient.GetClient(); var responseHttp = await client.PutAsJsonAsync("api/Percurso/" + id, percurso); Console.Write(responseHttp.RequestMessage); if (responseHttp.IsSuccessStatusCode) { return(RedirectToAction("Index")); } return(View(percursoModel)); }
public async Task <ActionResult> Create([Bind(Include = "POIID,Name,Description,OpenHour,CloseHour,VisitDuration,GPS_Lat,GPS_Long,Altitude,ConnectedPOIs")] POI pOI) { ViewBag.PoiList = await getPOIList(null); var connectedForm = Request.Form["ConnectedPOIs"]; parseConnectedPOIs(pOI, connectedForm); string openHour = Request.Form["OpenHour"]; pOI.OpenHour = Convert.ToDateTime(openHour); string closeHour = Request.Form["CloseHour"]; pOI.CloseHour = Convert.ToDateTime(closeHour); pOI.Creator = PVWebApiHttpClient.getUsername(); pOI.Approved = PVWebApiHttpClient.getUsername(); client = PVWebApiHttpClient.GetClient(); var responseHttp = await client.PostAsJsonAsync("api/POI", pOI); if (responseHttp.IsSuccessStatusCode) { return(RedirectToAction("Index")); } return(View()); }
public async Task <Percurso> getPercursoByID(int?id) { client = PVWebApiHttpClient.GetClient(); PercursoDTO percursoDTO = null; var response = await client.GetAsync("api/Percurso/" + id); if (response.IsSuccessStatusCode) { percursoDTO = await response.Content.ReadAsAsync <PercursoDTO>(); } Percurso percurso = DTOConverters.ConvertDTOToModel(percursoDTO); return(percurso); }
public static async Task <POI> getPOIByID(int?id) { client = PVWebApiHttpClient.GetClient(); POIDTO poiDTO = null; var response = await client.GetAsync("api/POI/" + id); if (response.IsSuccessStatusCode) { poiDTO = await response.Content.ReadAsAsync <POIDTO>(); } POI pOI = DTOConverters.ConvertDTOToModel(poiDTO); return(pOI); }
public async Task <ActionResult> Delete(int id) { client = PVWebApiHttpClient.GetClient(); var responseHttp = await client.DeleteAsync("api/POI/" + id); if (responseHttp.IsSuccessStatusCode) { return(RedirectToAction("Index")); } POI pOI = await getPOIByID(id); if (pOI == null) { return(HttpNotFound()); } return(View(pOI)); }
public async Task <ActionResult> Delete(int id) { client = PVWebApiHttpClient.GetClient(); var responseHttp = await client.DeleteAsync("api/Percurso/" + id); if (responseHttp.IsSuccessStatusCode) { return(RedirectToAction("Index")); } Percurso percurso = await getPercursoByID(id); if (percurso == null) { return(HttpNotFound()); } ViewBag.route = buildOriginalRouteString(percurso, percurso.PercursoPOIs.ToList()); return(View(percurso)); }
// GET: Percurso public async Task <ActionResult> Index() { client = PVWebApiHttpClient.GetClient(); IEnumerable <PercursoDTO> percursos = null; var response = await client.GetAsync("api/Percurso/"); if (response.IsSuccessStatusCode) { percursos = await response.Content.ReadAsAsync <IEnumerable <PercursoDTO> >(); } List <Percurso> percursosList = new List <Percurso>(); foreach (PercursoDTO percursoDTO in percursos) { Percurso percurso = DTOConverters.ConvertDTOToModel(percursoDTO); percursosList.Add(percurso); } return(View(percursosList)); }
// GET: POI public async Task <ActionResult> Index() { client = PVWebApiHttpClient.GetClient(); IEnumerable <POIDTO> pois = null; var response = await client.GetAsync("api/POI/"); if (response.IsSuccessStatusCode) { pois = await response.Content.ReadAsAsync <IEnumerable <POIDTO> >(); } List <POI> poiList = new List <POI>(); foreach (POIDTO poiDTO in pois) { POI poi = DTOConverters.ConvertDTOToModel(poiDTO); poiList.Add(poi); } return(View(poiList)); }
public async Task <ActionResult> Validate(string submit, int id) { client = PVWebApiHttpClient.GetClient(); POI pOI = await getPOIByID(id); foreach (Hashtag h in pOI.Hashtags) { h.ReferencedPOIs = new List <POI>(); } foreach (POI connected in pOI.ConnectedPOIs) { connected.GPS_Lat = 41.15M; connected.GPS_Long = -8.65M; connected.Altitude = 15; connected.VisitDuration = 60; connected.ConnectedPOIs = new List <POI>(); } if (submit == ClassLibrary.Resources.Global.Validate) { pOI.Approved = PVWebApiHttpClient.getUsername(); } if (submit == ClassLibrary.Resources.Global.Reject) { pOI.Approved = "no"; } var responseHttp = await client.PutAsJsonAsync("api/POI/" + id, pOI); if (responseHttp.IsSuccessStatusCode) { return(RedirectToAction("Index")); } return(View(pOI)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var data = new { Email = model.Email, Password = model.Password, ConfirmPassword = model.Password, Role = "Gestor" }; try { var client = PVWebApiHttpClient.GetClient(); string dataJSON = JsonConvert.SerializeObject(data); HttpContent content = new StringContent(dataJSON, System.Text.Encoding.Unicode, "application/json"); var response = await client.PostAsync("api/Account/Register", content); if (response.IsSuccessStatusCode) { return(RedirectToAction("Index", "Home")); } else { return(View(model)); } } catch { return(View(model)); } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true try { var client = PVWebApiHttpClient.GetClient(); var data = new { Email = model.Email, Password = model.Password, RememberMe = model.RememberMe }; string dataJSON = JsonConvert.SerializeObject(data); HttpContent content = new StringContent(dataJSON, System.Text.Encoding.Unicode, "application/json"); var response = await client.PostAsync("api/Account/Login", content); if (response.IsSuccessStatusCode) { TokenResponse tokenResponse = await response.Content.ReadAsAsync <TokenResponse>(); PVWebApiHttpClient.storeToken(tokenResponse); PVWebApiHttpClient.storeUsername(tokenResponse.Username); //return RedirectToAction("Index", "Home"); } else { return(View(model)); } client = PVWebApiHttpClient.GetClient(); response = await client.GetAsync("api/Account/getUserRole?email=" + PVWebApiHttpClient.getUsername()); if (response.IsSuccessStatusCode) { string dataResponse = await response.Content.ReadAsStringAsync(); //use JavaScriptSerializer from System.Web.Script.Serialization JavaScriptSerializer JSserializer = new JavaScriptSerializer(); //deserialize to your class UserDTO userResponse = JSserializer.Deserialize <UserDTO>(dataResponse); PVWebApiHttpClient.storeRoles(userResponse.Roles); return(RedirectToLocal(returnUrl)); } else { return(View(model)); } } catch { return(View(model)); } }