예제 #1
0
        public ActionResult db_Create([DataSourceRequest] DataSourceRequest request, CoursesViewModel db)
        {
            if (db != null && ModelState.IsValid)
            {
                CoursesService.Create(db);
            }

            return(Json(new[] { db }.ToDataSourceResult(request, ModelState)));
        }
예제 #2
0
        public void OnPost()
        {
            var courseCode = Request.Form["courseCode"];
            var difficulty = Request.Form["difficulty"];
            var grade      = Request.Form["grade"];
            var department = Request.Form["department"];
            var comments   = Request.Form["comments"];

            var data = new Courses(courseCode, Int32.Parse(difficulty), Int32.Parse(grade), department, comments);

            MyCoursesService.Create(data);
        }
        public async Task CreateCourseTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var repository     = new EfDeletableEntityRepository <Course>(new ApplicationDbContext(options.Options));
            var userRepository =
                new EfDeletableEntityRepository <ApplicationUser>(new ApplicationDbContext(options.Options));
            var categoryRepository = new EfDeletableEntityRepository <Category>(new ApplicationDbContext(options.Options));
            var category           = new Category
            {
                Name = "test",
            };

            var user = new ApplicationUser
            {
                FullName = "Test",
            };

            var course = new Course
            {
                Id    = 6,
                Title = "test",
            };
            await categoryRepository.AddAsync(category);

            await categoryRepository.SaveChangesAsync();

            await userRepository.AddAsync(user);

            await userRepository.SaveChangesAsync();

            await repository.AddAsync(course);

            await repository.SaveChangesAsync();

            var coursesService = new CoursesService(repository, userRepository);

            Assert.Throws <ArgumentException>(() =>
                                              coursesService.Create(user.Id, "title", "des", category.Id, "image", "Finished").GetAwaiter()
                                              .GetResult());
        }
예제 #4
0
 public ActionResult Create(Courses course)
 {
     coursesService.Create(course);
     return(RedirectToAction("Index"));
 }
예제 #5
0
 public ActionResult Create(Course course)
 {
     course = coursesService.Create(course);
     return(new JsonResult(course));
 }
 public ActionResult <Courses> Create(Courses course)
 {
     _coursesService.Create(course);
     return(Ok());
 }