public JsonResult Post(Rolet roli)
        {
            string        query         = @"
                    insert into Roli values 
                    ('" + roli.Roli + @"')
                    ";
            DataTable     table         = new DataTable();
            string        sqlDataSource = _configuration.GetConnectionString("ElavingApp");
            SqlDataReader myReader;

            using (SqlConnection myCon = new SqlConnection(sqlDataSource))
            {
                myCon.Open();
                using (SqlCommand myCommand = new SqlCommand(query, myCon))
                {
                    myReader = myCommand.ExecuteReader();
                    table.Load(myReader);;

                    myReader.Close();
                    myCon.Close();
                }
            }

            return(new JsonResult("Added Successfully"));
        }
        public JsonResult Put(Rolet rol)
        {
            string        query         = @"
                    update Roli set 
                    Roli = '" + rol.Roli + @"'
                    where Id  = " + rol.Id + @" 
                    ";
            DataTable     table         = new DataTable();
            string        sqlDataSource = _configuration.GetConnectionString("ElavingApp");
            SqlDataReader myReader;

            using (SqlConnection myCon = new SqlConnection(sqlDataSource))
            {
                myCon.Open();
                using (SqlCommand myCommand = new SqlCommand(query, myCon))
                {
                    myReader = myCommand.ExecuteReader();
                    table.Load(myReader);;

                    myReader.Close();
                    myCon.Close();
                }
            }

            return(new JsonResult("Updated Successfully"));
        }
Exemple #3
0
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                ModelState.AddModelError(string.Empty, "There was an error while getting user!");
            }

            Users user = new Users();

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

                Rolet rolet = await GetAPI.GetRoletAsync(httpClient, id);

                user.Role = rolet;
            }

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

            return(View(user));
        }
Exemple #4
0
        public async Task <IActionResult> Create(Rolet rolet)
        {
            if (ModelState.IsValid)
            {
                Rolet receivedRolet = new Rolet();
                using (var httpClient = new HttpClient())
                {
                    StringContent content = new StringContent(JsonConvert.SerializeObject(rolet), Encoding.UTF8, "application/json");

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

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

                    receivedRolet = JsonConvert.DeserializeObject <Rolet>(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 rolit!");
                    }
                }
                return(View(receivedRolet));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Plotesoni te gjitha fushat!");
            }
            return(RedirectToAction(nameof(Index)));
        }
Exemple #5
0
        public async Task <IActionResult> EditForm(int id)
        {
            Rolet rolet = new Rolet();

            using (var httpClient = new HttpClient())
            {
                rolet = await GetAPI.GetRoletAsync(httpClient, id);
            }

            return(View(rolet));
        }
Exemple #6
0
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                ModelState.AddModelError(string.Empty, "Ka ndodhur nje gabim gjate marrjes te rolit!");
            }

            Rolet rolet = new Rolet();

            using (var httpClient = new HttpClient())
            {
                rolet = await GetAPI.GetRoletAsync(httpClient, id);
            }

            if (rolet == null)
            {
                ModelState.AddModelError(string.Empty, "Ka ndodhur nje gabim gjate marrjes te rolit!");
            }

            return(View(rolet));
        }
Exemple #7
0
        public async Task <IActionResult> Edit(Rolet rolet)
        {
            if (ModelState.IsValid)
            {
                using (var httpClient = new HttpClient())
                {
                    using var response = await httpClient.PutAsJsonAsync <Rolet>(getApi + "/" + rolet.RoletId, rolet);

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

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

            return(NotFound());
        }