public JqgridResult UpdateEmployee(List <EmployeeModel> empList, string Age, int EmpId, string Name, string Salary, int id, string oper) { #region Validation string data = ""; int age; decimal salary; bool result; //age validation result = int.TryParse(Age.ToString(), out age); if (!result) { data += "Please type the valid age."; } //name validation if (Name.Length == 0) { data += "," + "Please type the name."; } //salary validation result = decimal.TryParse(Salary, out salary); if (!result) { data += "," + "Please type the valid salary."; } #endregion //update employee record if (string.IsNullOrEmpty(data)) { EmployeeModel obj = (from emp in empList where emp.ID == EmpId select emp).FirstOrDefault(); EmployeeModel updateObj = obj; empList.Remove(obj); //update updateObj.Name = Name; updateObj.Age = age; updateObj.Salary = salary; empList.Add(updateObj); JqgridResult updateResult = new JqgridResult(); updateResult.EmpList = empList; updateResult.Result = "Employee updated successfully."; return(updateResult); } return(null); }
public JqgridResult AddEmployee(List <EmployeeModel> empList, string Age, string Name, string Salary) { #region Validation string data = ""; int age; decimal salary; bool result; //age validation result = int.TryParse(Age, out age); if (!result) { data += "Please type the valid age."; } //name validation if (Name.Length == 0) { data += "," + "Please type the name."; } //salary validation result = decimal.TryParse(Salary, out salary); if (!result) { data += "," + "Please type the valid salary."; } #endregion //Add new employee if (string.IsNullOrEmpty(data)) { EmployeeModel empobj = empList.OrderByDescending(emp => emp.ID).First(); EmployeeModel obj = new EmployeeModel() { ID = (empobj.ID + 1), Name = Name, Age = age, Salary = salary }; empList.Add(obj); JqgridResult addResult = new JqgridResult(); addResult.EmpList = empList; addResult.Result = "Employee added successfully"; return(addResult); } return(null); }
public JqgridResult DeleteEmployee(List <EmployeeModel> empList, int Id) { var obj = empList.Single(emp => emp.ID == Id); empList.Remove(obj); JqgridResult result = new JqgridResult(); result.EmpList = empList; result.Result = "Employee deleted successfully"; return(result); }
public ActionResult UpdateEmployee(int Id, string Name, string Age, string Salary) { try { List <EmployeeModel> lst = Session["webgridbs"] as List <EmployeeModel>; JqgridResult result = dalobj.UpdateEmployee(lst, Id, Name, Age, Salary); if (result != null) { Session["webgridbs"] = result.EmpList; return(Json(new { result = "true" })); } } catch (Exception exc) { ExceptionLogger.LogException(exc, "Method:Webgridbs Controller:UpdateEmployee"); } return(Json(new { result = "false" })); }
public ActionResult DeleteEmployee(int Id) { try { List <EmployeeModel> lst = Session["webgridbs"] as List <EmployeeModel>; JqgridResult result = dalobj.DeleteEmployee(lst, Id); if (result != null) { Session["webgridbs"] = result.EmpList; return(Json(new { result = "true" })); } } catch (Exception exc) { ExceptionLogger.LogException(exc, "Method:DeleteEmployee Controller:Webgrid"); } return(Json(new { result = "false" })); }
public string Delete(int ID, int id, string oper) { try { if (oper == "del") { List <EmployeeModel> empList = (List <EmployeeModel>)Session["empList"]; JqgridResult result = dalobj.DeleteEmployee(empList, ID, id, oper); if (result != null) { Session["empList"] = result.EmpList; return(result.Result); } } return("Delete operation failed"); } catch (Exception exc) { ExceptionLogger.LogException(exc, "Method: Delete Controller: Jqgrid"); } return("Delete operation failed."); }
public string Add(int Age, string Name, string Salary, string id, string oper) { try { if (oper == "add") { List <EmployeeModel> empList = (List <EmployeeModel>)Session["empList"]; JqgridResult result = dalobj.AddEmployee(empList, Age, Name, Salary, id, oper); if (result != null) { Session["empList"] = result.EmpList; return(result.Result); } } return("Add operation failed"); } catch (Exception exc) { ExceptionLogger.LogException(exc, "Method: Add Controller: Jqgrid"); } return("Add operation failed."); }
public string Update(string Age, int EmpId, string Name, string Salary, int id, string oper) { try { if (oper == "edit") { List <EmployeeModel> empList = (List <EmployeeModel>)Session["empList"]; JqgridResult result = dalobj.UpdateEmployee(empList, Age, EmpId, Name, Salary, id, oper); if (result != null) { Session["empList"] = result.EmpList; return(result.Result); } } return("Update failed"); } catch (Exception exc) { ExceptionLogger.LogException(exc, "Method: Update Controller: Jqgrid"); } return("Update failed."); }