예제 #1
0
        /// <summary>
        /// A function that deletes a specific assignment
        /// </summary>
        public ActionResult Delete(int id)
        {
            Assignment assignment = (from a in db.Assignments where a.ID == id select a).FirstOrDefault();
            int        courseID   = assignment.CourseID;

            #region Security
            SecurityRedirect redirect = accountService.VerifySecurityLevel
                                        (
                auth: User.Identity.IsAuthenticated,
                secLevel: SecurityState.TEACHER,
                userID: User.Identity.GetUserId(),
                courseID: courseID
                                        );
            if (redirect.Redirect)
            {
                return(RedirectToAction(redirect.ActionName, redirect.ControllerName));
            }
            #endregion
            assignmentService.deleteAssignment(assignment);
            //if (assignment != null)
            //{
            //    List<Milestone> milestones = (from m in db.Milestones where m.AssignmentID == id select m).ToList();
            //    if(milestones.Count != 0)
            //    {
            //        IEnumerable<Milestone> milestonesToDelete = milestones;
            //        db.Milestones.RemoveRange(milestonesToDelete);
            //        db.SaveChanges();
            //    }
            //    db.Assignments.Remove(assignment);
            //    db.SaveChanges();
            //}
            return(RedirectToAction("TeacherOverview", new { id = courseID }));
        }