public IActionResult GetRoleDropDown() { IEnumerable <RoleOutputModel> OutPutData = null; IsRoleInputModel filter = new IsRoleInputModel(); filter.IsSupervisor = true; using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseAPI + "Base/"); var responseTask = client.PostAsJsonAsync <IsRoleInputModel>("GetRoleDropDown", filter); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var content = result.Content.ReadAsStringAsync(); RoleResponseModel resutl = Newtonsoft.Json.JsonConvert.DeserializeObject <RoleResponseModel>(content.Result); OutPutData = resutl.data; } else //web api sent error response { //log response status here.. OutPutData = Enumerable.Empty <RoleOutputModel>(); ModelState.AddModelError(string.Empty, "Terjadi kesalahan. Mohon hubungi admin."); } } return(Json(OutPutData)); }
public ActionResult <RoleResponseModel> GetRole([FromBody] IsRoleInputModel data) { RoleResponseModel res = new RoleResponseModel(); try { RoleRepository repo = new RoleRepository(db); List <RoleOutputModel> res2 = new List <RoleOutputModel>(); var query = repo.GetRoleDropDown(); if (data.IsSupervisor) { res2 = (from y in query where y.Name == "SPV" select new RoleOutputModel() { RoleCode = y.Name, RoleID = y.ID, RoleName = y.NormalizedName }).ToList(); } else { res2 = (from y in query where y.Name != "SPV" select new RoleOutputModel() { RoleCode = y.Name, RoleID = y.ID, RoleName = y.NormalizedName }).ToList(); } res.data = res2; res.Message = "Success get data"; res.Response = true; return(res); } catch (Exception ex) { res.Message = ex.Message; res.Response = false; return(res); } }