Example #1
0
        public async Task <IActionResult> Edit(Lendet lendet)
        {
            using (var httpClient = new HttpClient())
            {
                if (ModelState.IsValid)
                {
                    using var response = await httpClient.PutAsJsonAsync <Lendet>(getApi + "/" + lendet.LendetId, lendet);

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

                        return(RedirectToAction(nameof(Index)));
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Plotesoni te gjitha format!");
                }

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

                ViewData["DrejtimiId"] = new SelectList(MyDrejtimets, "DrejtimetId", "EmriDrejtimit", lendet.DrejtimiId);
            }

            return(View());
        }
Example #2
0
        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));
        }
Example #3
0
        public async Task <IActionResult> CreateAsync()
        {
            using var httpClient = new HttpClient();
            List <Drejtimet> MyDrejtimets = await GetAPI.GetDrejtimiListAsync(httpClient);

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

            return(View());
        }
Example #4
0
        public async Task <IActionResult> EditForm(int id)
        {
            Lendet lendet = new Lendet();

            using (var httpClient = new HttpClient())
            {
                lendet = await GetAPI.GetLendetAsync(httpClient, id);

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

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

            return(View(lendet));
        }
Example #5
0
        public async Task <IActionResult> Index()
        {
            List <Drejtimet> MyDrejtimets = new List <Drejtimet>();

            using (var httpClient = new HttpClient())
            {
                MyDrejtimets = await GetAPI.GetDrejtimiListAsync(httpClient);

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

                ViewBag.Xml = await GetJsonXml.GetXmlDrejtimet(httpClient);
            }

            return(View(MyDrejtimets));
        }
        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));
        }
        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));
        }
        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));
        }
Example #9
0
        public async Task <IActionResult> Create(Lendet lendet)
        {
            Lendet receivedLenda = new Lendet();

            using var httpClient = new HttpClient();
            if (ModelState.IsValid)
            {
                StringContent content = new StringContent(JsonConvert.SerializeObject(lendet), Encoding.UTF8, "application/json");

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

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

                receivedLenda = JsonConvert.DeserializeObject <Lendet>(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 lendes!");
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Plotesoni te gjitha format!");
            }

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

            ViewData["DrejtimiId"] = new SelectList(MyDrejtimets, "DrejtimetId", "EmriDrejtimit", lendet.DrejtimiId);

            return(View(lendet));
        }