Ejemplo n.º 1
0
        public string SaveDepartment(Department departmentObj)
        {
            bool checkName = IsDepartmentNameExist(departmentObj.DepartmentName);
            bool checkCode = IsDepartmentCodeExist(departmentObj.DepartmentCode);

            if (checkName && checkCode)
                return "Department Name and Code Already Exists";

            else if (checkName)
                return "Department Name Already Exists";

            else if (checkCode)
                return "Department Code Already Exists";

            else
            {
                string message = gateWay.SaveDepartment(departmentObj);
                return message;
            }
        }
Ejemplo n.º 2
0
        public string SaveDepartment(Department departmentObj)
        {
            string query = "INSERT INTO Department VALUES(@departmentCode, @departmentName)";
            SqlCommand insertCommand = new SqlCommand(query, connection);

            insertCommand.Parameters.Clear();

            insertCommand.Parameters.Add("departmentCode", SqlDbType.VarChar);
            insertCommand.Parameters["departmentCode"].Value = departmentObj.DepartmentCode;

            insertCommand.Parameters.Add("departmentName", SqlDbType.VarChar);
            insertCommand.Parameters["departmentName"].Value = departmentObj.DepartmentName;

            connection.Open();
            try
            {
                int rowAffected = insertCommand.ExecuteNonQuery();
                connection.Close();
                if (rowAffected > 0)
                    return "Saved Successfully";
                return "Saved Failed";
            }
            catch (Exception e)
            {

                throw e;
            }
        }
Ejemplo n.º 3
0
        public List<Department> GetAllDepartmentInfo()
        {
            string query = "SELECT * FROM Department";
            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();

            List<Department> departmetList = new List<Department>();

            try
            {
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Department departmentObj = new Department();
                    departmentObj.DepartmentCode = reader["DepartmentCode"].ToString();
                    departmentObj.DepartmentName = reader["DepartmentName"].ToString();

                    departmetList.Add(departmentObj);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                connection.Close();
                throw e;
            }

            connection.Close();
            return departmetList;
        }
Ejemplo n.º 4
0
 public ActionResult SaveDepartment(Department departmentObj)
 {
     ViewBag.SaveDepartment = manage.SaveDepartment(departmentObj);
     return View();
 }