public string Save(Student student) { int? departmentId = student.DepartmentId; Department department = studentGateway.GetDepartmentInfoByDepartmentId(departmentId); string departmentCode = department.Code; string year = student.Date.Substring(6, 4); string key = departmentCode + "-" + year + "-"; int totalStudent = studentGateway.CountTotalStudent(key); string registrationNumber; if (totalStudent >= 0 && totalStudent <= 9) { registrationNumber = departmentCode + "-" + year + "-00" + (totalStudent + 1); } else if (totalStudent <= 99 && totalStudent > 9) { registrationNumber = departmentCode + "-" + year + "-0" + (totalStudent + 1); } else { registrationNumber = departmentCode + "-" + year + "-" + (totalStudent + 1); } student.RegistrationNumber = registrationNumber; int rowAffected = studentGateway.Save(student); if (rowAffected > 0) { return("Student registered successfully"); } return("Failed to register student!"); }