Пример #1
0
        public async Task <IActionResult> IndexAsync()
        {
            List <Users> MyUsers  = new List <Users>();
            List <Rolet> MyRolets = new List <Rolet>();

            using (var httpClient = new HttpClient())
            {
                MyUsers = await GetAPI.GetUserListAsync(httpClient);

                MyRolets = await GetAPI.GetRoletListAsync(httpClient);

                ViewBag.JsonUser = await GetJsonXml.GetJsonUser(httpClient);

                ViewBag.XmlUser = await GetJsonXml.GetXmlUser(httpClient);

                ViewBag.JsonRolet = await GetJsonXml.GetJsonRolet(httpClient);

                ViewBag.XmlRolet = await GetJsonXml.GetXmlRolet(httpClient);
            }

            foreach (var user in MyUsers)
            {
                foreach (var role in MyRolets)
                {
                    if (user.RoleId == role.RoletId)
                    {
                        user.Role = role;
                    }
                }
            }

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

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

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

                List <Rolet> MyRolets = await GetAPI.GetRoletListAsync(httpClient);

                ViewData["RoleId"] = new SelectList(MyRolets, "RoletId", "RoleName", user.RoleId);
            }

            return(View());
        }
Пример #3
0
        public async Task <IActionResult> CreateAsync()
        {
            using var httpClient = new HttpClient();
            List <Rolet> MyRolets = await GetAPI.GetRoletListAsync(httpClient);

            ViewData["RoleId"] = new SelectList(MyRolets, "RoletId", "RoleName");

            return(View());
        }
Пример #4
0
        public async Task <IActionResult> EditForm(int id)
        {
            Users user = new Users();

            using (var httpClient = new HttpClient())
            {
                user = await GetAPI.GetUserAsync(httpClient, id);

                List <Rolet> MyRolets = await GetAPI.GetRoletListAsync(httpClient);

                ViewData["RoleId"] = new SelectList(MyRolets, "RoletId", "RoleName");
            }

            return(View(user));
        }
Пример #5
0
        public async Task <IActionResult> Index()
        {
            List <Rolet> MyRolets = new List <Rolet>();

            using (var httpClient = new HttpClient())
            {
                MyRolets = await GetAPI.GetRoletListAsync(httpClient);

                ViewBag.JsonRolet = await GetJsonXml.GetJsonRolet(httpClient);

                ViewBag.XmlRolet = await GetJsonXml.GetXmlRolet(httpClient);
            }

            return(View(MyRolets));
        }
Пример #6
0
        public async Task <IActionResult> Create(Users user)
        {
            Users receivedUser = new Users();

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

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

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

                    receivedUser = JsonConvert.DeserializeObject <Users>(apiResponse);

                    string success = response.StatusCode.ToString();
                    if (success == "Created")
                    {
                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Ka ndodhur nje gabim!");
                    }

                    List <Rolet> MyRolets = await GetAPI.GetRoletListAsync(httpClient);

                    ViewData["RoleId"] = new SelectList(MyRolets, "RoletId", "RoleName", user.RoleId);
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Plotesoni te gjitha fushat!");
                }
            }

            return(View(user));
        }