Example #1
0
        public async void Delete_RemovesACourseFromDatabase_ThrowsForNonNullObject()
        {
            //Arrange
            var connectionBuilder = new SqliteConnectionStringBuilder {
                DataSource = ":memory:"
            };
            var connection = new SqliteConnection(connectionBuilder.ToString());
            var options    = new DbContextOptionsBuilder <ApplicationDbContext>()
                             .UseSqlite(connection)
                             .Options;

            using var context = new ApplicationDbContext(options);
            context.Database.OpenConnection();
            context.Database.EnsureCreated();
            var courseRepository = new CourseRepository(context);
            var course           = CourseHelpers.GetCourse();
            await courseRepository.Insert(course);

            //Act
            await courseRepository.Delete(course);

            var returnedCourses = await courseRepository.GetAll();

            //Assert
            Assert.Empty(returnedCourses);
            await Assert.ThrowsAsync <ArgumentNullException>(
                () => courseRepository.Delete(null));
        }
Example #2
0
        public void Delete_Should_Do_Nothing_When_Record_Not_Exist()
        {
            var course = new Course()
            {
                Id = "Math", LengthInWeeks = 10
            };

            courseRepository.Save(course);
            courseRepository.Delete("English");
            var result = courseRepository.Get("Math");

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Id, "Math");
            Assert.AreEqual(result.LengthInWeeks, 10);
        }
Example #3
0
        public void DeleteCourses(int id)
        {
            CourseRepository coursesRepository = new CourseRepository();
            Courses          obj = coursesRepository.GetByID(id);

            coursesRepository.Delete(obj);
        }
 public void Delete(int Id)
 {
     if (Id != null)
     {
         _courseRepository.Delete(x => x.Id == Id);
     }
 }
        public IActionResult RemoveCourse(int id)
        {
            Course course = courseRepository.Read(id);

            courseRepository.Delete(course);
            return(RedirectToAction("Courses", "Course"));
        }
Example #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            var course = repos.GetCourse(id);

            repos.Delete(course);
            return(RedirectToAction("Index"));
        }
Example #7
0
        public ActionResult DeleteConfirmed(int id)
        {
            Course course = repo.Find(id);

            repo.Delete(course);
            repo.UnitOfWork.Commit();
            return(RedirectToAction("Index"));
        }
        public IActionResult Delete(int id)
        {
            Course course = new Course {
                Id = id
            };

            _courseRepository.Delete(course);
            return(Ok());
        }
        public async Task <ActionResult> Delete(int id)
        {
            if (id > 0)
            {
                await _courseRepo.Delete(id);

                return(RedirectToAction("Index"));
            }
            return(HttpNotFound());
        }
Example #10
0
        public static bool Remove(int id)
        {
            IList <Course> cs = CourseRepository.FindByTeacherId(id);

            foreach (Course c in cs)
            {
                CourseRepository.Delete(c.id);
            }
            return(UsersRepository.Delete(id) > 0);
        }
Example #11
0
        public static bool Remove(int id)
        {
            Course course = CourseRepository.GetById(id);

            foreach (var item in course.items)
            {
                CourseItemRepository.Delete(item.id);
            }

            return(CourseRepository.Delete(id) > 0);
        }
Example #12
0
        public IActionResult Delete(int id)
        {
            var course = courseRepository.GetById(id);

            if (course == null)
            {
                return(NotFound("Course does not exist."));
            }
            courseRepository.Delete(id);
            courseRepository.Save();

            return(new NoContentResult());
        }
Example #13
0
        public ActionResult DeleteConfirmed(int id)
        {
            Course course = courseRepository.GetById(id);

            if (course.Assignments.Count > 0)
            {
                return(View("Error"));
            }
            else
            {
                courseRepository.Delete(course);
                return(RedirectToAction("CourseInfo"));
            }
        }
        public void Should_DeleteCourseFromStore()
        {
            //arrange
            const int id     = 5;
            var       course = _courseBuilder.WithId(id).Build();

            _courseRepository.Create(course);

            //act
            _courseRepository.Delete(id);


            //assert
            _courseRepository.Courses.Should().NotContain(course);
        }
 public ActionResult Delete(int id, CourseViewModel collection)
 {
     try
     {
         var repository = new CourseRepository(context);
         var entity     = repository.Find(id);
         repository.Delete(entity);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
        public void delete_applies_soft_delete()
        {
            //var repo = new CourseRepository(new MOOCollab2UOW());
            var repo = new CourseRepository(new TestDb());

            var testCourse = new Course { Id = 1, Status = true };

            //act
            repo.Delete(testCourse);

            var changedCourse = repo.CourseAndInstructorByCourseId(1);//get changed course
            //assert
            Assert.IsFalse(changedCourse.Status);
            Assert.IsNull(changedCourse.Groups.FirstOrDefault(g => g.Status == true));
        }
Example #17
0
        public ActionResult Delete(int id, CourseViewModel model)
        {
            try
            {
                var repository = new CourseRepository(context);
                var course     = MapperHelper.Map <Course>(model);
                repository.Delete(course);
                context.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #18
0
        public void CourseRepository_Delete()
        {
            var sut    = new CourseRepository(fixture.GetNewDbContext());
            var course = new Course {
                Id = 1, Name = "Test course"
            };

            sut.Add(course);

            var toDelete = sut.GetById(course.Id);

            sut.Delete(toDelete);

            var afterDelete = sut.GetById(course.Id);

            afterDelete.Should().BeNull();
        }
Example #19
0
        public ActionResult Delete(string id)
        {
            var courseRepository = new CourseRepository(_context);
            var uploader         = new ImageUploader();
            var course           = courseRepository.GetById(new Guid(id));

            using (var tx = new TransactionScope())
            {
                if (course.Image != null)
                {
                    uploader.DeleteFile(course.Image);
                }
                courseRepository.Delete(course.Id);
                _context.Save(_loggedUser);
                tx.Complete();
            }

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Example #20
0
 public IHttpActionResult Delete(int id, [FromBody] Course course)
 {
     course = courseRepo.GetById(id);
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (id != course.Id)
     {
         return(BadRequest("Ids did not matched"));
     }
     else
     {
         course = courseRepo.GetById(id);
         courseRepo.Delete(course);
         courseRepo.Save();
         return(Ok(course));
     }
 }
Example #21
0
        public JsonResult DeleteCourses(int id)
        {
            bool              courseInUse       = false;
            List <Student>    studentList       = new List <Student>();
            StudentRepository studentRepository = new StudentRepository();

            studentList = studentRepository.GetAll(filter: s => s.Course.Id == id);
            if (studentList.Count > 0)
            {
                courseInUse = true;
            }
            else
            {
                Course           course           = new Course();
                CourseRepository courseRepository = new CourseRepository();
                course = courseRepository.GetById(id);
                courseRepository.Delete(course);
            }
            return(Json(courseInUse, JsonRequestBehavior.AllowGet));
        }
 public ActionResult Delete(int id, CourseViewModel model)
 {
     try
     {
         if (id != model.Id)
         {
             return(new HttpNotFoundResult());
         }
         // TODO: Add delete logic here
         var repository = new CourseRepository(context);
         var course     = repository.Find(model.Id);
         repository.Delete(course);
         context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ViewBag.ErrorMessage = ex.Message;
         return(View(model));
     }
 }
Example #23
0
 protected void RadGrid_DeleteCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
 {
     courseRepository.Delete(int.Parse(RadGrid.SelectedValue.ToString()));
     FormatHelper.MessageInformation(msg, "Success");
 }
 public ActionResult DeleteCourse(DeleteCourseVM viewModel)
 {
     CourseRepository.Delete(viewModel.currentCourse.CourseId);
     return(RedirectToAction("Courses"));
 }
Example #25
0
 public ActionResult DeleteCourse(Course course)
 {
     CourseRepository.Delete(course.CourseId);
     return(RedirectToAction("Courses"));
 }
 public JsonResult DeleteCourses(int id)
 {
     bool courseInUse = false;
     List<Student> studentList = new List<Student>();
     StudentRepository studentRepository = new StudentRepository();
     studentList = studentRepository.GetAll(filter: s => s.Course.Id == id);
     if (studentList.Count > 0)
     {
         courseInUse = true;
     }
     else
     {
         Course course = new Course();
         CourseRepository courseRepository = new CourseRepository();
         course = courseRepository.GetById(id);
         courseRepository.Delete(course);
     }
     return Json(courseInUse, JsonRequestBehavior.AllowGet);
 }
Example #27
0
 public void RemoveCourse(Course course)
 {
     _CourseRepository.Delete(course);
 }
 public void Delete(int id)
 {
     _courseRepository.Delete(id);
 }
Example #29
0
 public void DeleteById(int id)
 {
     repository.Delete(id);
 }
Example #30
0
 public void Delete(Course course)
 {
     _courseRepository.Delete(course);
 }
        public static void DeleteCourse(Course c)
        {
            CourseRepository courseRepository = new CourseRepository();

            courseRepository.Delete(c);
        }
        /// <summary>
        /// 删除课程
        /// </summary>
        /// <param name="courseId">课程Id</param>
        /// <returns>是否成功</returns>
        public OutputBase Delete(long courseId)
        {
            _repository.Delete(courseId);

            return(_unitWork.Commit() ? OutputBase.Success("删除课程成功") : OutputBase.Fail("删除课程失败"));
        }