Пример #1
0
        public async Task <IActionResult> DeleteDetails(int?id)
        {
            if (id == null)
            {
                ModelState.AddModelError(string.Empty, "There was an error while getting student!");
            }

            Studenti studenti = new Studenti();

            using (var httpClient = new HttpClient())
            {
                studenti = await GetAPI.GetStudentiAsync(httpClient, id);

                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;
                    }
                }
            }

            if (studenti == null)
            {
                ModelState.AddModelError(string.Empty, "There was an error while getting student!");
            }

            return(View(studenti));
        }
Пример #2
0
        public async Task <IActionResult> Edit(Studenti studenti)
        {
            using (var httpClient = new HttpClient())
            {
                if (ModelState.IsValid)
                {
                    using var response = await httpClient.PutAsJsonAsync <Studenti>(getApi + "/" + studenti.StudentId, studenti);

                    if (response.IsSuccessStatusCode)
                    {
                        ViewBag.Result = "Success";

                        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());
        }
Пример #3
0
        public async Task <IActionResult> CreateAsync()
        {
            using var httpClient = new HttpClient();
            List <Drejtimet> MyDrejtimets = await GetAPI.GetDrejtimiListAsync(httpClient);

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

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

            return(View());
        }
Пример #4
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));
        }
Пример #5
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));
        }
Пример #6
0
        public async Task <IActionResult> EditForm(int id)
        {
            Studenti studenti = new Studenti();

            using (var httpClient = new HttpClient())
            {
                studenti = await GetAPI.GetStudentiAsync(httpClient, id);

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

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

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

            return(View(studenti));
        }
Пример #7
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());
        }