예제 #1
0
 public JsonResult Users()
 {
     User currentUser = GlobalVariables.CurrentUser;
     DatabaseRepository db = new DatabaseRepository();
     List<User> users = db.GetMinions(currentUser.user_id, currentUser.user_is_teacher);
     return Json(users, JsonRequestBehavior.AllowGet);
 }
예제 #2
0
        public ActionResult Index()
        {
            User user = GlobalVariables.CurrentUser;
            DatabaseRepository db = new DatabaseRepository();
            List<Comment> comments = db.GetComments(user.user_id);

            // Group comments and comma separate the recipients
            var groupedComments = comments.GroupBy(c => c.id).Select(c => new Comment
            {
                recipients = string.Join(", ", c.Select(comment => comment.recipient_first_name + ' ' + comment.recipient_last_name)),
                commenter = c.Select(comment => comment.commenter_first_name + ' ' + comment.commenter_last_name).First(),
                comment_text = c.Select(comment => comment.comment_text).First(),
                user_is_commenter = c.Select(comment => comment.user_is_commenter).First(),
                created_at = c.Select(comment => comment.created_at).First(),
                hidden = c.Select(comment => comment.hidden).First(),
                id = c.Select(comment => comment.id).First()
            }).ToList();

            var commentViewModel = new Comments
            {
                comments = groupedComments,
                commenter_id = user.user_id
            };

            return View(commentViewModel);
        }
예제 #3
0
 public ActionResult Index()
 {
     DatabaseRepository db = new DatabaseRepository();
     User user = GlobalVariables.CurrentUser;
     List<Course> courses = db.GetCourses(user.user_id);
     List<Module> viewModel = Mapper.Map<List<Course>, List<Module>>(courses);
     return View(viewModel);
 }
예제 #4
0
        public ActionResult Delete(int commentId)
        {
            // This will delete the comment from the DB and redirect back to the comment page
            DatabaseRepository db = new DatabaseRepository();

            db.DeleteComment(commentId);

            return RedirectToAction("Index");
        }
예제 #5
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            DatabaseRepository db = new DatabaseRepository();
            int teamId = (int) filterContext.ActionParameters["teamId"];
            User currentUser = GlobalVariables.CurrentUser;
            List<Project> teams = db.GetLeaderProjects(currentUser.user_id);

            if (!teams.Any(t => t.project_id == teamId) && !currentUser.user_is_teacher)
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(
                            new { action = "Index", controller = "Error" }));
        }
예제 #6
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            DatabaseRepository db = new DatabaseRepository();
            int commentId = (int) filterContext.ActionParameters["commentId"];
            Comment comment = db.GetComment(commentId);

            // If the user is not the commenter, redirect
            if (comment.commenter_id != GlobalVariables.CurrentUser.user_id)
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(
                            new { action = "Index", controller = "Error" }));
        }
예제 #7
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            DatabaseRepository db = new DatabaseRepository();
            string userId = filterContext.ActionParameters["userId"].ToString();
            User currentUser = GlobalVariables.CurrentUser;
            List<User> users = db.GetMinions(currentUser.user_id, currentUser.user_is_teacher);

            // If the user is not the commenter, redirect
            if (!users.Any( u => u.user_id == userId))
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(
                            new { action = "Index", controller = "Error" }));
        }
예제 #8
0
        public ActionResult Create(Comments newComment)
        {
            // This will add the comment to the DB and redirect back to the comment page
            DatabaseRepository db = new DatabaseRepository();

            if(!string.IsNullOrEmpty(newComment.comment) && !string.IsNullOrEmpty(newComment.recipients))
            {
                int commentId = db.CreateComment(newComment.commenter_id, newComment.comment, newComment.hidden);
                db.LinkComment(commentId, newComment.recipients.Split(','));
            }

            return RedirectToAction("Index");
        }
예제 #9
0
        public ActionResult Teams(int courseId)
        {
            DatabaseRepository db = new DatabaseRepository();
            List<Project> projects = db.GetProjects(courseId);
            List<User> users = db.GetUsersWithoutTeams(courseId);
            List<User> members = db.GetUsersWithTeams(courseId);

            var viewModel = new TeamsProjectsAndUsers()
            {
                projects = projects,
                users = users,
                members = members
            };
            return View(viewModel);
        }
예제 #10
0
        public ActionResult Create(TeamsProjectsAndUsers course)
        {
            DatabaseRepository db = new DatabaseRepository();
            int[] allProjectIds = course.teams.Where(t => t.projectId != 0).Select(t => t.projectId).ToArray();
            int[] populatedProjectIds = course.teams.Where(t => t.userIds != null && t.projectId != 0).Select(t => t.projectId).ToArray();

            if (allProjectIds.Any())
            {
                db.DeleteAllMembers(allProjectIds);

                if (!string.IsNullOrEmpty(course.projectManager))
                {
                    string projectManagerId = course.projectManager.Split(',').First();
                    db.InsertProjectManager(projectManagerId, populatedProjectIds);
                }

                db.InsertTeamMembers(course.teams.ToList());
            }
            return RedirectToAction("Index");
        }