public List <Departmrnt> GetAllDepartment()
        {
            string query = "SELECT *FROM Departmrnts";

            SqlCommand command = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader     reader         = command.ExecuteReader();
            List <Departmrnt> departmentList = new List <Departmrnt>();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    Departmrnt department = new Departmrnt();
                    department.Id       = int.Parse(reader["Id"].ToString());
                    department.DeptCode = reader["DeptCode"].ToString();
                    department.DeptName = reader["DeptName"].ToString();
                    departmentList.Add(department);
                }
                reader.Close();
            }
            connection.Close();
            return(departmentList);
        }
        private string GetStudentRegNo(Student aStudent)
        {
            Departmrnt aDepartment             = db.Departments.FirstOrDefault(aDept => aDept.Id == aStudent.DepartmentId);
            int        countDepartmentStudentd = db.Students.Count(aStd => (aStd.DepartmentId == aStudent.DepartmentId) && (aStd.RegistrationDate.Year == aStudent.RegistrationDate.Year)) + 1;
            int        noOfZeroAdded           = 3 - countDepartmentStudentd.ToString().Length;
            string     noOfZero = "";

            for (int i = 0; i < noOfZeroAdded; i++)
            {
                noOfZero += "0";
            }

            return(aDepartment.DeptCode + "-" + aStudent.RegistrationDate.Year + "-" + noOfZero + countDepartmentStudentd);
        }
        public ActionResult SaveDepartment([Bind(Include = "Id,DeptCode,DeptName")] Departmrnt departmrnt)
        {
            if (ModelState.IsValid)
            {
                ViewBag.message = "Saved success";
                db.Departments.Add(departmrnt);
                db.SaveChanges();
                ModelState.Clear();
                return(View());
                //return RedirectToAction("Index");
            }

            return(View(departmrnt));
        }