public IHttpActionResult PutProviderUser(StudentDataDto data) { StudentUser user = db.Users.FirstOrDefault(u => u.Email == User.Identity.Name) as StudentUser; if (user == null) { return(NotFound()); } user.Name = data.Name; user.Surname = data.Surname; user.Location = data.Location; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(Ok()); }
public ActionResult Save([Bind(Prefix = "Item1")] StudentDataDto model, string submitButton) { if (submitButton == "No") { // delegate sending to another controller action return(RedirectToAction("Info", "Profile")); } using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://projektnet.mini.pw.edu.pl/LanguageSchoolWeb/api/"); string accessToken = null; try { accessToken = Request.Cookies["token"].Value; } catch { return(View("~/Views/Shared/AccessDenied.cshtml")); } client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); //HTTP PUT if (model.PhoneNumber == null) { model.PhoneNumber = ""; } var postTask = client.PutAsJsonAsync <StudentDataDto>("student/info", model); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Info")); } } ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); return(View(model)); }
public ActionResult Index() { StudentDataDto model = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://projektnet.mini.pw.edu.pl/LanguageSchoolWeb/api/"); HttpCookie cookie = Request.Cookies["token"]; if (cookie != null) { string accessToken = cookie.Value; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); //HTTP GET var responseTask = client.GetAsync("student/info"); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <StudentDataDto>(); readTask.Wait(); model = readTask.Result; } else //web api sent error response { //log response status here.. model = new StudentDataDto(); ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); } } } return(View(model)); }
public ActionResult Info() { StudentDataDto model = null; IEnumerable <ClassBasicDataDto> studentClasses = null; string charge = "?"; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://projektnet.mini.pw.edu.pl/LanguageSchoolWeb/api/"); string accessToken = null; try { accessToken = Request.Cookies["token"].Value; } catch { return(View("~/Views/Shared/AccessDenied.cshtml")); } client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); //HTTP GET var responseTask = client.GetAsync("student/info"); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <StudentDataDto>(); readTask.Wait(); model = readTask.Result; } else //web api sent error response { //log response status here.. model = new StudentDataDto(); ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); } client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); responseTask = client.GetAsync("student/classes"); responseTask.Wait(); result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <IList <ClassBasicDataDto> >(); readTask.Wait(); studentClasses = readTask.Result; } else //web api sent error response { //log response status here.. studentClasses = Enumerable.Empty <ClassBasicDataDto>(); ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); } responseTask = client.GetAsync("student/charge"); responseTask.Wait(); result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <string>(); readTask.Wait(); charge = readTask.Result; } else //web api sent error response { //log response status here.. charge = "?"; ModelState.AddModelError(string.Empty, "Server error. Please contact administrator."); } } return(View(Tuple.Create(model, GetClassesLists(studentClasses), charge))); }