Esempio n. 1
0
 public int AddOrUpdateCourse(Course course)
 {
     using (TransactionScope tran = new TransactionScope()) {
         Courses.AddOrUpdate(course);
         //   Complete();
         tran.Complete();
         return(course.Id);
     }
 }
Esempio n. 2
0
        public static void AddCourses(this ICourseRepository repository, int count)
        {
            for (var i = 0; i < count; i++)
            {
                var faker = new Faker <Course>()
                            .RuleFor(c => c.Name, f => f.Random.String2(25))
                            .RuleFor(c => c.Description, f => f.Random.String2(50));

                faker.Generate(count).ForEach(async(c) => await repository.AddOrUpdate(c));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> AddCourse(Course course)
        {
            if (course == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid == false)
            {
                ViewBag.Title = "Data is not valid";
                return(View("AddPage", course));
            }

            await _courseRepository.AddOrUpdate(course);

            return(Redirect("~/Course/All"));
        }