public void Save(Course aCourse)
        {
            string query = "INSERT INTO Courses (CourseCode, CourseName, CourseCredit, CourseDescription, DepartmentId, SemesterId) VALUES (@code, @name, @credit, @description, @deptId, @semesterId)";
            using (connection = new SqlConnection(connectionString))
            using (SqlCommand command = new SqlCommand(query, connection))
            {
                command.Parameters.Clear();
                command.Parameters.Add("code", sqlDbType: SqlDbType.NVarChar);
                command.Parameters["code"].Value = aCourse.CourseCode;

                command.Parameters.Add("name", sqlDbType: SqlDbType.NVarChar);
                command.Parameters["name"].Value = aCourse.CourseName;

                command.Parameters.Add("credit", sqlDbType: SqlDbType.Decimal);
                command.Parameters["credit"].Value = aCourse.CourseCredit;

                command.Parameters.Add("description", sqlDbType: SqlDbType.NVarChar);
                command.Parameters["description"].Value = aCourse.CourseDescription;

                command.Parameters.Add("deptId", sqlDbType: SqlDbType.Int);
                command.Parameters["deptId"].Value = aCourse.DepartmentId;

                command.Parameters.Add("semesterId", sqlDbType: SqlDbType.Int);
                command.Parameters["semesterId"].Value = aCourse.SemesterId;

                connection.Open();
                command.ExecuteNonQuery();
            }
        }
 public ActionResult Save(Course aCourse)
 {
     ViewBag.response = aCourseManager.Save(aCourse);
     ViewBag.Departments = aDepartmentManager.GetAllDepartments();
     ViewBag.Semesters = aSemesterManager.GetAllSemesters();
     return View();
 }
        public ActionResponse Save(Course aCourse)
        {
            ActionResponse response = new ActionResponse();
            try
            {
                bool isCourseCodeExists = aCourseGateway.IsCourseCodeExists(aCourse.CourseCode);
                if (isCourseCodeExists)
                {
                    response.Class = "danger";
                    response.Message = "Course Code [" + aCourse.CourseCode + "] is already exists.";
                    return response;
                }

                bool isCourseNameExists = aCourseGateway.IsCourseNameExists(aCourse.CourseName);
                if (isCourseNameExists)
                {
                    response.Class = "danger";
                    response.Message = "Course Name [" + aCourse.CourseName + "] is already exists.";
                    return response;
                }

                aCourseGateway.Save(aCourse);
                response.Class = "success";
                response.Message = "Course Saved Successfully";
            }
            catch (SqlException ex)
            {
                response.Class = "warning";
                response.Message = ex.Message;
            }
            return response;
        }