public async Task <IActionResult> Details(int?id) { if (id == null) { ModelState.AddModelError(string.Empty, "There was an error while getting student!"); } Provimet provimi = new Provimet(); using (var httpClient = new HttpClient()) { provimi = await GetAPI.GetProvimetAsync(httpClient, id); Lendet lendet = await GetAPI.GetLendetAsync(httpClient, provimi.LendaId); Studenti studenti = await GetAPI.GetStudentiAsync(httpClient, provimi.StudentiId); Profesoret profesoret = await GetAPI.GetProfesoretAsync(httpClient, provimi.ProfesoriId); provimi.Lenda = lendet; provimi.Studenti = studenti; provimi.Profesori = profesoret; } if (provimi == null) { ModelState.AddModelError(string.Empty, "There was an error while getting student!"); } return(View(provimi)); }
public async Task <IActionResult> EditForm(int id) { Provimet provimi = new Provimet(); using (var httpClient = new HttpClient()) { provimi = await GetAPI.GetProvimetAsync(httpClient, id); List <Lendet> MyLendets = await GetAPI.GetLendetListAsync(httpClient); List <Studenti> MyStudentis = await GetAPI.GetStudentiListAsync(httpClient); List <Profesoret> MyProfesorets = await GetAPI.GetProfesoretListAsync(httpClient); ViewData["LendaId"] = new SelectList(MyLendets, "LendetId", "EmriLendes"); ViewData["StudentiId"] = new SelectList(MyStudentis, "StudentId", "FullName"); ViewData["ProfesoriId"] = new SelectList(MyProfesorets, "ProfesoretId", "EmriProfesorit"); } return(View(provimi)); }
public async Task <IActionResult> Edit(Provimet provimet) { using (var httpClient = new HttpClient()) { List <Lendet> MyLendets = await GetAPI.GetLendetListAsync(httpClient); List <Studenti> MyStudentis = await GetAPI.GetStudentiListAsync(httpClient); List <Profesoret> MyProfesorets = await GetAPI.GetProfesoretListAsync(httpClient); foreach (var profesor in MyProfesorets) { if (profesor.LendaId == provimet.LendaId) { provimet.ProfesoriId = profesor.ProfesoretId; } } if (ModelState.IsValid) { using var response = await httpClient.PutAsJsonAsync <Provimet>(getApi + "/" + provimet.ProvimetId, provimet); if (response.IsSuccessStatusCode) { ViewBag.Result = "Success"; return(RedirectToAction(nameof(Index))); } } else { ModelState.AddModelError(string.Empty, "Plotesoni te gjitha fushat!"); } ViewData["LendaId"] = new SelectList(MyLendets, "LendetId", "EmriLendes", provimet.LendaId); ViewData["StudentiId"] = new SelectList(MyStudentis, "StudentId", "FullName", provimet.StudentiId); } return(View()); }
public async Task <IActionResult> Create(Provimet provimet) { Provimet receivedProvimi = new Provimet(); using (var httpClient = new HttpClient()) { List <Provimet> MyProvimets = await GetAPI.GetProvimetListAsync(httpClient); List <Lendet> MyLendets = await GetAPI.GetLendetListAsync(httpClient); List <Studenti> MyStudentis = await GetAPI.GetStudentiListAsync(httpClient); List <Profesoret> MyProfesorets = await GetAPI.GetProfesoretListAsync(httpClient); var checkProvimet = MyProvimets.Any(f => f.LendaId == provimet.LendaId && f.StudentiId == provimet.StudentiId); if (checkProvimet != true) { foreach (var profesor in MyProfesorets) { if (profesor.LendaId == provimet.LendaId) { provimet.ProfesoriId = profesor.ProfesoretId; } } if (ModelState.IsValid) { StringContent content = new StringContent(JsonConvert.SerializeObject(provimet), Encoding.UTF8, "application/json"); using var response = await httpClient.PostAsync(getApi, content); string apiResponse = await response.Content.ReadAsStringAsync(); receivedProvimi = JsonConvert.DeserializeObject <Provimet>(apiResponse); string success = response.StatusCode.ToString(); if (success == "Created") { return(RedirectToAction(nameof(Index))); } else { ModelState.AddModelError(string.Empty, "Ka ndodhur nje gabim gjate regjistrimit te provimit!"); } } else { ModelState.AddModelError(string.Empty, "Plotesoni te gjitha fushat!"); } } else { ModelState.AddModelError(string.Empty, "Provimi ekziston!"); } ViewData["LendaId"] = new SelectList(MyLendets, "LendetId", "EmriLendes", provimet.LendaId); ViewData["StudentiId"] = new SelectList(MyStudentis, "StudentId", "FullName", provimet.StudentiId); } return(View(provimet)); }