Exemplo n.º 1
0
        public IActionResult NewAssignment(ClassroomHomeViewModel model)
        {
            string Id = null;

            if (_signInManager.IsSignedIn(HttpContext.User))
            {
                Id = _userManager.GetUserId(HttpContext.User);
            }
            if (ModelState.IsValid)
            {
                string        filename = null;
                List <string> files    = new List <string>();
                if (model.AssignmentViewModel.Files != null)
                {
                    foreach (IFormFile file in model.AssignmentViewModel.Files)
                    {
                        string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "posted_assignments");
                        filename = Guid.NewGuid().ToString() + "_" + file.FileName;
                        files.Add(filename);
                        string filePath = Path.Combine(uploadsFolder, filename);
                        file.CopyTo(new FileStream(filePath, FileMode.Create));
                    }
                }
                Assignment newAssignment = new Assignment
                {
                    ClassroomID = Convert.ToInt32(model.AssignmentViewModel.ClassId),
                    AppUserID   = Id,
                    Title       = model.AssignmentViewModel.Title,
                    Description = model.AssignmentViewModel.Description,
                    Files       = string.Join(",", files)
                };
                _assignmentRepo.Add(newAssignment);
            }
            return(RedirectToAction("Home", new { id = model.AssignmentViewModel.ClassId, loadPartial = "Assignments" }));
        }
Exemplo n.º 2
0
        public IActionResult BlackBoard(ClassroomHomeViewModel model)
        {
            string Id = null;

            if (_signInManager.IsSignedIn(HttpContext.User))
            {
                Id = _userManager.GetUserId(HttpContext.User);
            }
            if (ModelState.IsValid)
            {
                string        filename = null;
                List <string> files    = new List <string>();
                if (model.BlackBoardViewModel.Files != null)
                {
                    foreach (IFormFile file in model.BlackBoardViewModel.Files)
                    {
                        string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "blackboard");
                        filename = Guid.NewGuid().ToString() + "_" + file.FileName;
                        files.Add(filename);
                        string filePath = Path.Combine(uploadsFolder, filename);
                        file.CopyTo(new FileStream(filePath, FileMode.Create));
                    }
                }
                BlackBoard newBoard = new BlackBoard
                {
                    ClassroomId = Convert.ToInt32(model.BlackBoardViewModel.ClassId),
                    AppUserId   = Id,
                    content     = model.BlackBoardViewModel.content,
                    FilesPaths  = string.Join(",", files)
                };
                _boardRepo.Add(newBoard);
            }
            return(RedirectToAction("Home", new { id = model.BlackBoardViewModel.ClassId, loadPartial = "BlackBoard" }));
        }
Exemplo n.º 3
0
        public IActionResult Home(int id, string loadPartial)
        {
            Classroom Classroom = _classRepo.GetClassroom(id);
            string    userId    = null;

            if (_signInManager.IsSignedIn(HttpContext.User))
            {
                userId = _userManager.GetUserId(HttpContext.User);
            }
            ClassroomUser classUser = _classUserRepo.GetClassroomUser(id, userId);

            if (Classroom == null || classUser == null)
            {
                Response.StatusCode = 404;
                return(View("NotFound"));
            }
            ClassroomHomeViewModel chvm = new ClassroomHomeViewModel();

            chvm.Classroom   = Classroom;
            chvm.BlackBoards = _boardRepo.GetClassBlackBoards(id);
            List <List <Comment> > Comments = new List <List <Comment> >();

            foreach (BlackBoard bb in chvm.BlackBoards)
            {
                Comments.Add(_commentRepo.GetBlackBoardComments(bb.Id).ToList());
            }
            chvm.Comments           = Comments;
            chvm.ClassroomUserRole  = classUser.Role;
            chvm.ClassroomMentors   = _classUserRepo.GetClassroomMentors(id);
            chvm.ClassroomStudents  = _classUserRepo.GetClassroomStudents(id);
            chvm.StudentInvites     = _inviteRepo.GetAllInvites(id);
            chvm.Assignments        = _assignmentRepo.GetClassAssignments(id);
            ViewData["loadPartial"] = loadPartial;
            return(View(chvm));
        }
Exemplo n.º 4
0
        public IActionResult DeleteConfirmed(ClassroomHomeViewModel chvm)
        {
            var Class = _classRepo.GetClassroom(chvm.Classroom.ID);

            _classRepo.Delete(Class.ID);
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 5
0
        public IActionResult LeaveClassroomConfirmed(ClassroomHomeViewModel chvm)
        {
            string userId = null;

            if (_signInManager.IsSignedIn(HttpContext.User))
            {
                userId = _userManager.GetUserId(HttpContext.User);
                _classUserRepo.Delete(chvm.Classroom.ID, userId);
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 6
0
        public IActionResult AddComment(ClassroomHomeViewModel model)
        {
            string Id      = null;
            int    classId = 0;

            if (_signInManager.IsSignedIn(HttpContext.User))
            {
                Id = _userManager.GetUserId(HttpContext.User);
                Comment newComment = new Comment
                {
                    AppUserId    = Id,
                    BlackBoardId = model.Comment.BlackBoardId,
                    TimeCreated  = DateTime.Now,
                    Content      = model.Comment.Content,
                };
                classId = _boardRepo.GetBlackBoard(model.Comment.BlackBoardId).ClassroomId;
                _commentRepo.Add(newComment);
            }
            return(RedirectToAction("Home", new { id = classId, loadPartial = "BlackBoard" }));
        }