public IHttpActionResult DeleteLesson(int id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var service = new LessonService();

                bool isSuccess = service.Delete(id);
                if (!isSuccess)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResponseType.Error, Description = "Entity was not deleted."
                    }));
                }

                return(Ok(new ResponseModel()
                {
                    Result = ResponseType.Success
                }));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);

                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 2
0
        public async Task Delete_All_Versions(IAuthorizationService authorizationService, IStateService stateService, List <Lesson> entities, Lesson target)
        {
            var context = TestSetup.SetupContext();
            var service = new LessonService(context, TestSetup.SetupHttpContext(), authorizationService, stateService);

            await context.Lessons.AddRangeAsync(entities);

            var version = 0;

            for (var i = 0; i < 5; i++)
            {
                var newLesson = new Lesson();
                newLesson.CloneFrom(target);
                newLesson.Version = version;
                await context.Lessons.AddAsync(target);

                version += 1;
            }

            await context.SaveChangesAsync();

            var result = await service.Delete(target.Id);

            result.Should().BeTrue();
            context.Lessons.Any(x => x.Id == target.Id).Should().BeFalse();
            context.Lessons.Count().Should().Be(entities.Count);
        }
Ejemplo n.º 3
0
 public ActionResult Delete(int id)
 {
     try
     {
         service.Delete(id);
         return(NoContent());
     }
     catch (Exception e)
     {
         return(Content(e.Message));
     }
 }
Ejemplo n.º 4
0
        public async Task Update_Subject_State_On_Delete(Mock <IAuthorizationService> authorizationService, Mock <IStateService> stateService, Lesson lesson)
        {
            stateService.Setup(x => x.UpdateSubjectState(It.IsAny <Guid>(), It.IsAny <CancellationToken>()));

            var context     = TestSetup.SetupContext();
            var httpContext = TestSetup.SetupHttpContext();

            await context.Lessons.AddAsync(lesson);

            await context.SaveChangesAsync();

            var service = new LessonService(context, httpContext, authorizationService.Object, stateService.Object);
            await service.Delete(lesson.Id);

            stateService.VerifyAll();
        }
Ejemplo n.º 5
0
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <ILessonRepository>();
            var model = new ApiLessonRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new LessonService(mock.LoggerMock.Object,
                                            mock.RepositoryMock.Object,
                                            mock.ModelValidatorMockFactory.LessonModelValidatorMock.Object,
                                            mock.BOLMapperMockFactory.BOLLessonMapperMock,
                                            mock.DALMapperMockFactory.DALLessonMapperMock,
                                            mock.BOLMapperMockFactory.BOLLessonXStudentMapperMock,
                                            mock.DALMapperMockFactory.DALLessonXStudentMapperMock,
                                            mock.BOLMapperMockFactory.BOLLessonXTeacherMapperMock,
                                            mock.DALMapperMockFactory.DALLessonXTeacherMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.LessonModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
Ejemplo n.º 6
0
        public async Task <Lesson> Delete(string id)
        {
            var lesson = await _lessonService.Delete(id);

            return(lesson);
        }