public static ReturnObject EditDepartment(string current, string previous) { masters_department page_object = new masters_department(); ReturnObject return_object = new ReturnObject(); string original_department_name = string.Empty; string company_code = string.Empty; string department_code = string.Empty; string department_name = string.Empty; int count = 0; if (HttpContext.Current.Session["username"] == null) // checking session expired or not { return_object = page_object.DoLogout(); } else { try { JObject current_data = JObject.Parse(current); company_code = current_data["company_code"].ToString(); department_code = current_data["department_code"].ToString(); department_name = current_data["department_name"].ToString(); JObject previous_data = JObject.Parse(previous); original_department_name = previous_data["department_name"].ToString(); if (original_department_name != department_name) { count = page_object.CheckDepartmentName(department_name, company_code); if (count > 0) { return_object.status = "error"; return_object.return_data = "Department Name has been taken. Please try again with a different Name"; return(return_object); } } page_object.UpdateDatabase("U", department_code, department_name, company_code); return_object.status = "success"; return_object.return_data = "Department edited successfully!"; } catch (Exception ex) { Logger.LogException(ex, page, "EDIT_DEPARTMENT"); return_object.status = "error"; return_object.return_data = "An error occurred while saving the Department. Please try again. If the error persists, please contact Support."; throw; } finally { page_object.Dispose(); } } return(return_object); }
public static ReturnObject DeleteDepartment(string current) { masters_department page_object = new masters_department(); DBConnection db_connection = new DBConnection(); ReturnObject return_object = new ReturnObject(); string query = string.Empty; string company_code = string.Empty; string department_code = string.Empty; string department_name = string.Empty; int count = 0; if (HttpContext.Current.Session["username"] == null) // checking session expired or not { return_object = page_object.DoLogout(); } else { try { JObject current_data = JObject.Parse(current); department_code = current_data["department_code"].ToString(); department_name = current_data["department_name"].ToString(); company_code = current_data["company_code"].ToString(); query = "select count(*) from EmployeeMaster where Emp_Department = '" + department_code + "' and Emp_Status = 1"; count = db_connection.GetRecordCount(query); if (count > 0) { return_object.status = "error"; return_object.return_data = "Please unassign or delete the employees mapped to this Department and try again."; } else { page_object.UpdateDatabase("D", department_code, department_name, company_code); return_object.status = "success"; return_object.return_data = "Department deleted successfully!"; } } catch (Exception Ex) { Logger.LogException(Ex, page, "DELETE_DEPARTMENT"); return_object.status = "error"; return_object.return_data = "An error occurred while deleteing the Department. Please try again. If the error persists, please contact Support."; throw; } finally { page_object.Dispose(); } } return(return_object); }