Exemple #1
0
        public ActionResult Update(MenuRolesRelationModel cm)
        {
            try
            {
                List <MenuRolesRelationModel> MenuRolesRelationInfo = new List <MenuRolesRelationModel>();
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Baseurl);
                    //HTTP GET
                    var responseTask = client.PutAsJsonAsync("api/MenuRolesRelation/update", cm);
                    responseTask.Wait();

                    var result = responseTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        //Storing the response details recieved from web api
                        var MenuRolesRelationResponse = result.Content.ReadAsStringAsync().Result;

                        //Deserializing the response recieved from web api and storing into the Sub SORType  list
                        MenuRolesRelationInfo = JsonConvert.DeserializeObject <List <MenuRolesRelationModel> >(MenuRolesRelationResponse);
                    }
                }

                return(RedirectToAction("Index", "Roles"));
            }
            catch (Exception ex)
            {
                ExceptionLogHandler.LogData(ex);

                throw ex;
            }
        }
Exemple #2
0
        public async Task <ActionResult> Insert(List <int> MenuSelect, int rId)
        {
            try
            {
                List <MenuRolesRelationModel> roleModel = new List <MenuRolesRelationModel>();

                //  var sSelect = Request.Form["MenuSelect"].Split(',');

                foreach (var item in MenuSelect)
                {
                    roleModel.Add(new MenuRolesRelationModel {
                        Id = 0, menuId = Convert.ToInt32(item), roleId = rId
                    });
                }
                MenuRolesRelationModel MenuRolesRelationInfo = new MenuRolesRelationModel();
                using (var client = new HttpClient())
                {
                    foreach (MenuRolesRelationModel cm in roleModel)
                    {
                        //Passing service base url
                        client.BaseAddress = new Uri(Baseurl);

                        client.DefaultRequestHeaders.Clear();

                        var obj = JsonConvert.SerializeObject(cm);

                        // Define request data format
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                        //Sending request to find web api REST service resource GetAllComapnies using HttpClient
                        HttpResponseMessage Res = await client.PostAsync("api/MenuRolesRelation/insert", new StringContent(obj, Encoding.UTF8, "application/json"));

                        //Checking the response is successful or not which is sent using HttpClient
                        if (Res.IsSuccessStatusCode)
                        {
                            //Storing the response details recieved from web api
                            var MenuRolesRelationResponse = Res.Content.ReadAsStringAsync().Result;

                            //Deserializing the response recieved from web api and storing into the Company list
                            MenuRolesRelationInfo = JsonConvert.DeserializeObject <MenuRolesRelationModel>(MenuRolesRelationResponse);
                        }
                    }
                    //returning the company list to view
                    return(RedirectToAction("Index", "Roles"));
                }
            }
            catch (Exception ex)
            {
                ExceptionLogHandler.LogData(ex);

                throw ex;
            }
        }