public async Task <DelegatedManager> getDelegateByUserID(int id) { DelegatedManager delegatedManager = new DelegatedManager(); using (var httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync(api_delegate_url + "/getDelegateByUserID/" + id)) { string apiResponse = await response.Content.ReadAsStringAsync(); delegatedManager = JsonConvert.DeserializeObject <DelegatedManager>(apiResponse); } } return(delegatedManager); }
public async Task <IActionResult> AddDelegate(DelegatedManager delegatedManager) { int deptID = (int)HttpContext.Session.GetInt32("DeptId"); bool isActive = false; string fromDate = delegatedManager.FromDate.ToString("dd-MM-yyyy", CultureInfo.InvariantCulture); string toDate = delegatedManager.ToDate.ToString("dd-MM-yyyy", CultureInfo.InvariantCulture); using (var httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync(api_delegate_url + "/isActiveDelegateByDateNDepID/" + deptID + "/" + fromDate + "/" + toDate)) { string apiResponse = await response.Content.ReadAsStringAsync(); if (apiResponse != "") { isActive = JsonConvert.DeserializeObject <bool>(apiResponse); } } } if (!isActive) { using (var httpClient = new HttpClient()) { #region save StringContent content = new StringContent(JsonConvert.SerializeObject(delegatedManager), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync(api_delegate_url + "/SaveDelegatedManager", content)) { string apiResponse = await response.Content.ReadAsStringAsync(); } #endregion } msg = "Assigned Successfully!"; } else { msg = "Cannot Assign for this date!"; } return(RedirectToAction("AddDelegate", new { message = msg })); }
public async Task <bool> isActiveDelegateByDateNDepID(DelegatedManager delegatedManager) { int deptID = (int)HttpContext.Session.GetInt32("DeptId"); bool isActive = false; string fromDate = delegatedManager.FromDate.ToString("dd-MM-yyyy", CultureInfo.InvariantCulture); string toDate = delegatedManager.ToDate.ToString("dd-MM-yyyy", CultureInfo.InvariantCulture); using (var httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync(api_delegate_url + "/isActiveDelegateByDateNDepID/" + deptID + "/" + fromDate + "/" + toDate)) { string apiResponse = await response.Content.ReadAsStringAsync(); if (apiResponse != "") { isActive = JsonConvert.DeserializeObject <bool>(apiResponse); } } } return(isActive); }