static void Main(string[] args) { ICourseDataAccess da = new CourseRepository(); IAppError apperror = new AppError(); ICourseService serv = new CourseService(apperror, da); Course c = new Course(); c.CourseName = ""; serv.AddNewCourse(c); if (apperror.IsValid) { Console.WriteLine("Course Added"); } else { foreach (Error e in apperror.GetErrors()) { Console.WriteLine(e.ErrorDescription); } } Console.ReadLine(); }
public async Task <IActionResult> AddCourse([FromBody] Course newCourse) { int userId; int.TryParse(HttpContext.User.Claims.FirstOrDefault(m => m.Type == ClaimTypes.NameIdentifier).Value, out userId); newCourse.TeacherID = userId; try { return(Ok(await _courseService.AddNewCourse(newCourse))); } catch (Exception e) { return(BadRequest("Error inserting Course")); } }
public ActionResult AddNewCourse(CourseName course) { try { var msg = courseService.AddNewCourse(course); if (msg.status) { return(Ok()); } else { return(BadRequest(msg.message)); } } catch (Exception e) { return(StatusCode(500, e)); } }