Example #1
0
        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());
        }
Example #2
0
        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));
        }
Example #3
0
        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> 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));
            }
        }