public async Task <IActionResult> Delete(CourseDeleteViewModel courseDeleteViewModel)
        {
            if (await this.courseService.ExistsAsync(courseDeleteViewModel.Id) == false)
            {
                return(this.RedirectToAction("Error", "Home"));
            }

            await this.courseService.DeleteByIdAsync(courseDeleteViewModel.Id);

            return(this.Redirect($"/Courses/All"));
        }
Exemplo n.º 2
0
        public IActionResult Delete(int id)
        {
            Course course = _courserepository.GetCourse(id);
            CourseDeleteViewModel courseDeleteViewModel = new CourseDeleteViewModel
            {
                Id          = course.Id,
                Title       = course.Title,
                Description = course.Description,
            };

            return(View(courseDeleteViewModel));
        }
        public IActionResult Delete(int id)
        {
            var course = _repositoryCourse.GetCourseById(id);

            if (course == null)
            {
                return(RedirectToAction(nameof(Index)));
            }
            var courseViewModel = new CourseDeleteViewModel()
            {
                idCourse   = course.id,
                NomeCourse = course.Name
            };

            return(View(courseViewModel));
        }
        public async Task <ActionResult> Delete(CourseDeleteViewModel model)
        {
            if (ModelState.IsValid)
            {
                var course = await db.Courses.FindAsync(model.Id);

                if (course == null)
                {
                    return(View("Error"));
                }
                var catid = course.Category.Id;
                db.Courses.Remove(course);
                await db.SaveChangesAsync();

                return(RedirectToAction("View", "Category", new { id = catid }));
            }
            return(View(model));
        }
Exemplo n.º 5
0
        public IActionResult Delete(Guid id)
        {
            try
            {
                CourseDeleteViewModel courseDeleteViewModel = new CourseDeleteViewModel();
                courseDeleteViewModel.CourseView = _courseService.GetById(new GetCourseByIdRequest {
                    ID = id
                }).CourseView;
                _courseService.Delete(new DeleteCourseRequest {
                    ID = id
                });
            }
            catch (Exception)
            {
                return(RedirectToAction("Delete", new { id = id, saveChangesError = true }));
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 6
0
        public ActionResult DeleteConfirmed(CourseDeleteViewModel cdvm)
        {
            int?id = (int?)Session["courseid"];

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            try
            {
                Course course             = db.Courses.Find(id);
                List <FileDocument> docs  = new List <FileDocument>();
                ApplicationUser[]   users = course.Members.ToArray();
                foreach (var user in users)
                {
                    docs.AddRange(user.Files);
                }
                docs.AddRange(course.Files);
                foreach (var module in course.Modules)
                {
                    docs.AddRange(module.Files);
                    foreach (var activity in module.Activities)
                    {
                        docs.AddRange(activity.Files);
                    }
                }
                DeleteDocs(docs.ToArray());
                foreach (var user in users)
                {
                    db.Users.Remove(user);
                }
                db.Courses.Remove(course);
                db.SaveChanges();
                TempData["alert"] = "success|Kursen togs bort!";
            }
            catch (Exception)
            {
                // Log errors here
                TempData["alert"] = "danger|Det gick inte att ta bort kursen!";
            }
            return(PartialView("_Delete", cdvm));
        }
Exemplo n.º 7
0
        public IActionResult Delete(CourseDeleteViewModel model)
        {
            _courserepository.Delete(model.Id);

            return(RedirectToAction("Index"));
        }