public ActionResult Create(LeaveTypeInfo iLeaveTypeInfo) { try { if (string.IsNullOrWhiteSpace(iLeaveTypeInfo.LeaveTypeName)) { ModelState.AddModelError("LeaveTypeName", "Please enter leave type name"); } if (!ModelState.IsValid) { return(View()); } using (var client = new HttpClient()) { iLeaveTypeInfo.iMode = 105; client.BaseAddress = new Uri(Utility.BaseURL); var response = client.PostAsJsonAsync("SetLeaveTypeDetails", iLeaveTypeInfo).Result; Status status = response.Content.ReadAsAsync <Status>().Result; if (status.Errors == null) { TempData["JavaScriptFunction"] = string.Format("fnSuccess();"); return(View()); } else { return(View()); } } } catch { return(View()); } }
public ActionResult Edit(int id) { using (var client = new HttpClient()) { iLeaveTypeInfo.iMode = 106; iLeaveTypeInfo.LeaveTypeID = id; client.BaseAddress = new Uri(Utility.BaseURL); var response = client.PostAsJsonAsync("GetLeaveTypeDetails", iLeaveTypeInfo).Result; Status status = response.Content.ReadAsAsync <Status>().Result; if (status.Errors == null) { DataTable dt = (DataTable)JsonConvert.DeserializeObject(status.Data.ToString(), (typeof(DataTable))); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { iLeaveTypeInfo = new LeaveTypeInfo { LeaveTypeID = Convert.ToInt32(dt.Rows[i]["LeaveTypeID"]), LeaveTypeName = Convert.ToString(dt.Rows[i]["LeaveTypeName"]), isActive = Convert.ToBoolean(dt.Rows[i]["isActive"]) }; } } } } return(View(iLeaveTypeInfo)); }
public ActionResult Index() { //using (var client = new HttpClient()) //{ // iLeaveTypeInfo.iMode = 104; // var listitems = Status.InvokeWebAPI(iLeaveTypeInfo, "GetLeaveTypeDetails"); // if (listitems.Any()) // { // //ViewBag.LeaveTypeList = new SelectList(listitems, "LeaveTypeID", "LeaveTypeName"); // return View(listitems.ToList()); // } // else // return RedirectToAction("Create"); //} //if (Convert.ToString(Session["Email"]) == "") //{ // return RedirectToAction("Index", "Login"); //} using (var client = new HttpClient()) { iLeaveTypeInfo.iMode = 104; client.BaseAddress = new Uri(Utility.BaseURL); var response = client.PostAsJsonAsync("GetLeaveTypeDetails", iLeaveTypeInfo).Result; Status status = response.Content.ReadAsAsync <Status>().Result; if (status.Errors == null) { DataTable dt = (DataTable)JsonConvert.DeserializeObject(status.Data.ToString(), (typeof(DataTable))); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { iLeaveTypeInfo = new LeaveTypeInfo { LeaveTypeID = Convert.ToInt32(dt.Rows[i]["LeaveTypeID"]), LeaveTypeName = Convert.ToString(dt.Rows[i]["LeaveTypeName"]), isActive = Convert.ToBoolean(dt.Rows[i]["isActive"]) }; listMember.Add(iLeaveTypeInfo); } } } } - return(View(listMember)); }