예제 #1
0
        public int AddCourse(CourseViewModel model)
        {
            var cmd       = $"INSERT INTO Courses (Author, CourseName, Duration) VALUES('{model.Author}', '{model.Name}', {model.Duration});";
            var insResult = _courseRepo.AddCourse(cmd);

            return(insResult);
        }
예제 #2
0
        public IActionResult AddCourse(Course course)
        {
            if (course == null)
            {
                return(BadRequest());
            }

            Db.AddCourse(course);
            return(Created("course has been added", course));
        }
        public IHttpActionResult PostCourse(Course course)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _repo.AddCourse(course);
            _repo.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = course.Id }, course));
        }
예제 #4
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (Course.CourseId > 0)
            {
                _courseRepo.Update(Course);
                _courseRepo.Commit();
                TempData["message"] = "Course updated successfully";
            }
            else
            {
                _courseRepo.AddCourse(Course);
                _courseRepo.Commit();
                TempData["message"] = "Course Added successfully";
            }

            return(RedirectToPage("./AllCourses"));
        }