예제 #1
0
        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());
        }
예제 #2
0
        public async Task <IActionResult> Index()
        {
            List <Studenti>  MyStudents   = new List <Studenti>();
            List <Drejtimet> MyDrejtimets = new List <Drejtimet>();
            List <Statuset>  MyStatusets  = new List <Statuset>();

            using (var httpClient = new HttpClient())
            {
                MyStudents = await GetAPI.GetStudentiListAsync(httpClient);

                MyDrejtimets = await GetAPI.GetDrejtimiListAsync(httpClient);

                MyStatusets = await GetAPI.GetStatusiListAsync(httpClient);

                ViewBag.JsonStudenti = await GetJsonXml.GetJsonStudenti(httpClient);

                ViewBag.XmlStudenti = await GetJsonXml.GetXmlStudenti(httpClient);

                ViewBag.JsonDrejtimet = await GetJsonXml.GetJsonDrejtimet(httpClient);

                ViewBag.XmlDrejtimet = await GetJsonXml.GetXmlDrejtimet(httpClient);

                ViewBag.JsonStatusi = await GetJsonXml.GetJsonStatusi(httpClient);

                ViewBag.XmlStatusi = await GetJsonXml.GetXmlStatusi(httpClient);
            }

            foreach (var student in MyStudents)
            {
                foreach (var drejtim in MyDrejtimets)
                {
                    if (student.DrejtimiId == drejtim.DrejtimetId)
                    {
                        student.Drejtimi = drejtim;
                    }
                }

                foreach (var status in MyStatusets)
                {
                    if (student.StatusiId == status.StatusiId)
                    {
                        student.Statusi = status;
                    }
                }
            }

            return(View(MyStudents));
        }
예제 #3
0
        public async Task <IActionResult> Create(Studenti studenti)
        {
            Studenti receivedStudenti = new Studenti();

            using var httpClient = new HttpClient();
            if (ModelState.IsValid)
            {
                List <Studenti> MyStudentis = await GetAPI.GetStudentiListAsync(httpClient);

                var checkStudentIndex = MyStudentis.Where(f => f.Indeksi == studenti.Indeksi).ToList();

                if (checkStudentIndex.Count > 0)
                {
                    ModelState.AddModelError(string.Empty, "Ekziston student me Indeks te tille!");
                }
                else
                {
                    StringContent content = new StringContent(JsonConvert.SerializeObject(studenti), Encoding.UTF8, "application/json");

                    using var response = await httpClient.PostAsync(getApi, content);

                    string apiResponse = await response.Content.ReadAsStringAsync();

                    receivedStudenti = JsonConvert.DeserializeObject <Studenti>(apiResponse);

                    string success = response.StatusCode.ToString();
                    if (success == "Created")
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Plotesoni te gjitha fushat!");
            }

            List <Drejtimet> MyDrejtimets = await GetAPI.GetDrejtimiListAsync(httpClient);

            List <Statuset> MyStatusets = await GetAPI.GetStatusiListAsync(httpClient);

            ViewData["DrejtimiId"] = new SelectList(MyDrejtimets, "DrejtimetId", "EmriDrejtimit", studenti.DrejtimiId);
            ViewData["StatusiId"]  = new SelectList(MyStatusets, "StatusiId", "Statusi", studenti.StatusiId);

            return(View(studenti));
        }
예제 #4
0
        public async Task <IActionResult> GetSingleStudent(string index)
        {
            if (ModelState.IsValid)
            {
                Studenti studenti = new Studenti();
                using (var httpClient = new HttpClient())
                {
                    List <Studenti> MyStudents = await GetAPI.GetStudentiListAsync(httpClient);

                    foreach (var student in MyStudents)
                    {
                        if (student.Indeksi == index)
                        {
                            studenti = student;
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, "Nuk ekziston student me Indeks te tille!");
                        }
                    }

                    Drejtimet drejtimet = await GetAPI.GetDrejtimiAsync(httpClient, studenti.DrejtimiId);

                    List <Statuset> MyStatusets = await GetAPI.GetStatusiListAsync(httpClient);

                    studenti.Drejtimi = drejtimet;

                    foreach (var status in MyStatusets)
                    {
                        if (studenti.StatusiId == status.StatusiId)
                        {
                            studenti.Statusi = status;
                        }
                    }
                }

                return(View(studenti));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "There was an error while getting student!");
            }
            return(View());
        }
예제 #5
0
        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));
        }
예제 #6
0
        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());
        }
예제 #7
0
        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));
        }
예제 #8
0
        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));
        }