public async Task <IActionResult> Index() { List <Profesoret> MyProfesorets = new List <Profesoret>(); List <Lendet> MyLendets = new List <Lendet>(); using (var httpClient = new HttpClient()) { MyProfesorets = await GetAPI.GetProfesoretListAsync(httpClient); MyLendets = await GetAPI.GetLendetListAsync(httpClient); ViewBag.JsonProfesoret = await GetJsonXml.GetJsonProfesoret(httpClient); ViewBag.XmlProfesoret = await GetJsonXml.GetXmlProfesoret(httpClient); ViewBag.JsonLendet = await GetJsonXml.GetJsonLendet(httpClient); ViewBag.XmlLendet = await GetJsonXml.GetXmlLendet(httpClient); } foreach (var profesor in MyProfesorets) { foreach (var lende in MyLendets) { if (profesor.LendaId == lende.LendetId) { profesor.Lenda = lende; } } } return(View(MyProfesorets)); }
public async Task <IActionResult> Index() { List <Lendet> MyLendets = new List <Lendet>(); List <Drejtimet> MyDrejtimets = new List <Drejtimet>(); using (var httpClient = new HttpClient()) { MyLendets = await GetAPI.GetLendetListAsync(httpClient); MyDrejtimets = await GetAPI.GetDrejtimiListAsync(httpClient); ViewBag.JsonDrejtimet = await GetJsonXml.GetJsonDrejtimet(httpClient); ViewBag.XmlDrejtimet = await GetJsonXml.GetXmlDrejtimet(httpClient); ViewBag.JsonLendet = await GetJsonXml.GetJsonLendet(httpClient); ViewBag.XmlLendet = await GetJsonXml.GetXmlLendet(httpClient); } foreach (var lende in MyLendets) { foreach (var drejtim in MyDrejtimets) { if (lende.DrejtimiId == drejtim.DrejtimetId) { lende.Drejtimi = drejtim; } } } return(View(MyLendets)); }
public async Task <IActionResult> Edit(Profesoret profesoret) { using (var httpClient = new HttpClient()) { if (ModelState.IsValid) { using var response = await httpClient.PutAsJsonAsync <Profesoret>(getApi + "/" + profesoret.ProfesoretId, profesoret); if (response.IsSuccessStatusCode) { ViewBag.Result = "Success"; return(RedirectToAction(nameof(Index))); } } else { ModelState.AddModelError(string.Empty, "Plotesoni te gjitha format!"); } List <Lendet> MyLendets = await GetAPI.GetLendetListAsync(httpClient); ViewData["LendaId"] = new SelectList(MyLendets, "LendetId", "EmriLendes", profesoret.LendaId); } return(View(profesoret)); }
public async Task <IActionResult> CreateAsync() { using var httpClient = new HttpClient(); List <Lendet> MyLendets = await GetAPI.GetLendetListAsync(httpClient); ViewData["LendaId"] = new SelectList(MyLendets, "LendetId", "EmriLendes"); return(View()); }
public async Task <IActionResult> CreateAsync() { 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); ViewData["LendaId"] = new SelectList(MyLendets, "LendetId", "EmriLendes"); ViewData["StudentiId"] = new SelectList(MyStudentis, "StudentId", "FullName"); ViewData["ProfesoriId"] = new SelectList(MyProfesorets, "ProfesoretId", "EmriProfesorit"); return(View()); }
public async Task <IActionResult> EditForm(int id) { Profesoret profesoret = new Profesoret(); using (var httpClient = new HttpClient()) { profesoret = await GetAPI.GetProfesoretAsync(httpClient, id); List <Lendet> MyLendets = await GetAPI.GetLendetListAsync(httpClient); ViewData["LendaId"] = new SelectList(MyLendets, "LendetId", "EmriLendes"); } return(View(profesoret)); }
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(Profesoret profesoret) { Profesoret receivedPofesori = new Profesoret(); using var httpClient = new HttpClient(); if (ModelState.IsValid) { StringContent content = new StringContent(JsonConvert.SerializeObject(profesoret), Encoding.UTF8, "application/json"); using var response = await httpClient.PostAsync(getApi, content); string apiResponse = await response.Content.ReadAsStringAsync(); receivedPofesori = JsonConvert.DeserializeObject <Profesoret>(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 profesorit!"); } } else { ModelState.AddModelError(string.Empty, "Plotesoni te gjitha format!"); } List <Lendet> MyLendets = await GetAPI.GetLendetListAsync(httpClient); ViewData["LendaId"] = new SelectList(MyLendets, "LendetId", "EmriLendes", profesoret.LendaId); return(View(profesoret)); }
public async Task <IActionResult> Index() { List <Provimet> MyProvimets = new List <Provimet>(); List <Lendet> MyLendets = new List <Lendet>(); List <Studenti> MyStudentis = new List <Studenti>(); List <Profesoret> MyProfesorets = new List <Profesoret>(); using (var httpClient = new HttpClient()) { MyProvimets = await GetAPI.GetProvimetListAsync(httpClient); MyLendets = await GetAPI.GetLendetListAsync(httpClient); MyStudentis = await GetAPI.GetStudentiListAsync(httpClient); MyProfesorets = await GetAPI.GetProfesoretListAsync(httpClient); ViewBag.JsonProvimet = await GetJsonXml.GetJsonProvimet(httpClient); ViewBag.XmlProvimet = await GetJsonXml.GetXmlProvimet(httpClient); ViewBag.JsonLendet = await GetJsonXml.GetJsonLendet(httpClient); ViewBag.XmlLendet = await GetJsonXml.GetXmlLendet(httpClient); ViewBag.JsonProfesoret = await GetJsonXml.GetJsonProfesoret(httpClient); ViewBag.XmlProfesoret = await GetJsonXml.GetXmlProfesoret(httpClient); ViewBag.JsonStudenti = await GetJsonXml.GetJsonStudenti(httpClient); ViewBag.XmlStudenti = await GetJsonXml.GetXmlStudenti(httpClient); } foreach (var provim in MyProvimets) { foreach (var lenda in MyLendets) { if (provim.LendaId == lenda.LendetId) { provim.Lenda = lenda; } } foreach (var student in MyStudentis) { if (provim.StudentiId == student.StudentId) { provim.Studenti = student; } } foreach (var prof in MyProfesorets) { if (provim.ProfesoriId == prof.ProfesoretId) { provim.Profesori = prof; } } } return(View(MyProvimets)); }
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)); }