public IHttpActionResult UpdateLesson(LessonModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var service = new LessonService();

                bool isSuccess = service.Update(BindingManager.ToLessonEntity(model));
                if (!isSuccess)
                {
                    return(Ok(new ResponseModel()
                    {
                        Result = ResponseType.Error, Description = "Entity was not created."
                    }));
                }

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

                return(InternalServerError(ex));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Update(LessonEditViewModel Lesson)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            LessonService.Update(Lesson);
            return(RedirectToAction("Lesson"));
        }
Ejemplo n.º 3
0
        // PUT: api/lesson/5
        public HttpResponseMessage Put(int id, [FromBody] Lesson value)
        {
            HttpResponseMessage msg = new HttpResponseMessage(HttpStatusCode.Conflict);

            using (ILessonService ts = new LessonService(WebApiApplication.connection))
            {
                ts.Update(id, Mapper.Map <BLL.Objects.Lesson>(value));
                msg.StatusCode = HttpStatusCode.OK;
            }
            return(msg);
        }
Ejemplo n.º 4
0
        public async Task Update_Subject_State_On_Update(Mock <IAuthorizationService> authorizationService, Mock <IStateService> stateService, Lesson lesson, LessonRequest request)
        {
            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.Update(lesson.Id, request);

            stateService.VerifyAll();
        }
Ejemplo n.º 5
0
        public async Task Update_Lesson_Version(IAuthorizationService authorizationService, IStateService stateService, Lesson entity, LessonRequest request)
        {
            var context = TestSetup.SetupContext();
            var service = new LessonService(context, TestSetup.SetupHttpContext(), authorizationService, stateService);

            await context.Lessons.AddAsync(entity);

            await context.SaveChangesAsync();

            var expected = new Lesson();

            expected.CloneFrom(entity);
            expected.CloneFrom(request);
            expected.Version += 1;

            var result = await service.Update(entity.Id, request);

            result.Should().NotBeNull().And.BeEquivalentTo(expected, config => TestSetup.IgnoreTimestamps <Lesson>()(config.Excluding(lesson => lesson.Exercises)));
            context.Lessons.Count().Should().Be(2);
        }
Ejemplo n.º 6
0
        public async Task Get_Latest_Version(IAuthorizationService authorizationService, IStateService stateService, List <Lesson> entities, Lesson target)
        {
            var request = new LessonRequest();

            request.CloneFrom(target);

            var context = TestSetup.SetupContext();
            var service = new LessonService(context, TestSetup.SetupHttpContext(), authorizationService, stateService);

            await context.Lessons.AddRangeAsync(entities);

            await context.Lessons.AddAsync(target);

            await context.SaveChangesAsync();

            var newLesson = await service.Update(target.Id, request);

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

            result.Should().NotBeNull().And.BeEquivalentTo(newLesson);
        }
Ejemplo n.º 7
0
        public async void Update()
        {
            var mock  = new ServiceMockFacade <ILessonRepository>();
            var model = new ApiLessonRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <Lesson>())).Returns(Task.FromResult(new Lesson()));
            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Lesson()));
            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);

            UpdateResponse <ApiLessonResponseModel> response = await service.Update(default(int), model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.LessonModelValidatorMock.Verify(x => x.ValidateUpdateAsync(It.IsAny <int>(), It.IsAny <ApiLessonRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Update(It.IsAny <Lesson>()));
        }
Ejemplo n.º 8
0
        public async Task <LessonUpdateModel> Update(string id, LessonUpdateModel lessonUpdate)
        {
            var lesson = await _lessonService.Update(id, lessonUpdate);

            return(lesson);
        }