예제 #1
0
        public async Task <ActionResult> AssignCourses(string RegNo, string[] selectedCourses)
        {
            if (!string.IsNullOrEmpty(RegNo))
            {
                Lecturer lecturer = await _lecturerService.GetByRegNoAsync(RegNo);

                if (lecturer != null)
                {
                    try
                    {
                        await _lecturerService.AssignCoursesAsync(RegNo, selectedCourses);

                        TempData["success"] = "Operation was successful";
                        return(RedirectToAction("lecturer-courses", new { RegNo = lecturer.RegNo }));
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
                else
                {
                    TempData["error"] = "Lecturer Not found";
                    return(RedirectToAction("lecturers"));
                }
            }
            else
            {
                TempData["error"] = "Must select a lecturer";
                return(RedirectToAction("lecturers"));
            }
        }