示例#1
0
        protected void DelBtn_Command(object sender, CommandEventArgs e)
        {
            string lessonId = e.CommandArgument as string;

            LessonService.DeleteLesson(SessionVariable.Current.Company.Id, SessionVariable.Current.User.Id, course.Id, lessonId);

            Response.Redirect(Request.RawUrl);
        }
        public async Task <ActionResponse> DeleteLesson(int lessonId, int courseId)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var access = await _userService.AuthorizeCourse(userId, courseId);

            if (access)
            {
                return(await _lessonService.DeleteLesson(lessonId, courseId));
            }
            else
            {
                return(new ActionResponse(false, "Invalid Lesson Information"));
            }
        }
示例#3
0
        public IActionResult Delete(int id)
        {
            var lesson = _lessonService.GetLesson(id);

            if (lesson == null)
            {
                return(View("Error", new ErrorViewModel
                {
                    Message = "This lesson does not exist."
                }));
            }

            _lessonService.DeleteLesson(lesson);
            _lessonService.SaveChanges();

            _logger.LogInformation("{user} deleted lesson {lesson}", User.Identity.Name, id);

            return(RedirectToAction("Index"));
        }
示例#4
0
        public async Task <IActionResult> DeleteLesson(
            [HttpTrigger(AuthorizationLevel.Function, "delete", Route = "Lesson/Delete/{id}/{pk}")] HttpRequest req,
            string id,
            string pk,
            ILogger log)
        {
            try
            {
                var data = await _lessonService.DeleteLesson
                               (id, new Dictionary <string, string> {
                    { "LessonCode", pk }
                });

                return(new OkObjectResult(data));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(ex.Message));
            }
        }
            public async Task DeleteLesson_Deleted(string id)
            {
                var repo = new Mock<IDocumentDBRepository<Lesson>>();

                var lessonExisting = lessonList.FirstOrDefault(L => L.Id == id).Id;
                repo.Setup(c => c.GetByIdAsync(
                    It.IsAny<string>(),
                    It.IsAny<Dictionary<string, string>>()
                )).ReturnsAsync(
                    (string id, Dictionary<string, string> pk) => lessonList.FirstOrDefault());

                repo.Setup(c => c.DeleteAsync(
                    It.IsAny<string>(),
                    It.IsAny<Dictionary<string, string>>(),
                    It.IsAny<EventGridOptions>()
                    )).Returns(Task.FromResult(new PageResult<Lesson>(lessonList, "")));

                var svc = new LessonService(repo.Object);

                var act = await svc.DeleteLesson(id, null);
                Assert.Equal($"{lessonExisting}-Deleted", act);

            }