public ActionResult Watch(Guid id) { var classRepository = new ClassRepository(_context); var classAccessRepository = new ClassAccessRepository(_context); var classInfo = classRepository.GetClass(id, _loggedUser.Id, GetUserRole(_loggedUser)); if (classInfo.Available && classInfo.Class.Active) { if (GetUserRole(_loggedUser) == Role.Student) { classAccessRepository.CreateAccess(new ClassAccess { Class = classInfo.Class, User = _loggedUser, AccessDateTime = DateTime.Now, Percentual = classInfo.Percentual, WatchedSeconds = classInfo.WatchedSeconds }); } return(View(ClassViewModel.FromEntityWithFiles(classInfo))); } TempData["MessageType"] = "warning"; TempData["MessageTitle"] = Resource.WarningToastrTitle; TempData["Message"] = Resource.NotAllowedWatchClassToastrMessage; return(RedirectToAction("Index", "Home")); }
public async Task <IActionResult> ClassInfo(int id) { var user = await userManager.GetUserAsync(User); ClassRepository repo = new ClassRepository(configModel.ConnectionString); ClassModel classModel; // Ensure that ONLY staff accounts have access to this API endpoint if (user == null || !await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString())) { return(Utilities.ErrorJson("Not authorized")); } if (id == 0) { return(Utilities.ErrorJson("Must include a class id")); } classModel = repo.GetClass(id); if (classModel == null) { return(Utilities.ErrorJson("That class does not exist")); } return(new JsonResult(new { Class = classModel, Error = "" })); }
public async Task <IActionResult> ClassTeacherAssignment(ClassModel model) { var user = await userManager.GetUserAsync(User); ClassRepository repo = new ClassRepository(configModel.ConnectionString); VolunteerRepository vRepo = new VolunteerRepository(configModel.ConnectionString); // Ensure that ONLY staff accounts have access to this API endpoint if (user == null || !await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString())) { return(Utilities.ErrorJson("Not authorized")); } // Make sure the provided class and volunteer ids are valid if (model.Id == 0 || repo.GetClass(model.Id) == null) { return(Utilities.ErrorJson("Must include a valid class ID")); } if (model.TeacherId == 0 || vRepo.GetVolunteer(model.TeacherId) == null) { return(Utilities.ErrorJson("Must include a valid volunteer id as TeacherId")); } // Update in the database try { repo.AssignTeacher(model.Id, model.TeacherId); } catch (Exception e) { return(Utilities.ErrorJson(e.Message)); } return(Utilities.NoErrorJson()); }
public async Task <IActionResult> ClassDelete(ClassModel model) { var user = await userManager.GetUserAsync(User); ClassRepository repo = new ClassRepository(configModel.ConnectionString); ClassModel dbClass; // Ensure that ONLY staff accounts have access to this API endpoint if (user == null || !await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString())) { return(Utilities.ErrorJson("Not authorized")); } // Verify that a valid class id was provided dbClass = repo.GetClass(model.Id); if (dbClass == null) { return(Utilities.ErrorJson("Invalid class id")); } try { repo.DeleteClass(model.Id); } catch (Exception e) { return(Utilities.ErrorJson(e.Message)); } return(Utilities.NoErrorJson()); }
public async Task <ActionResult <Class> > GetClass(string classid) { return(await cr.GetClass(HttpContext.Items["UserID"].ToString(), classid)); var classItem = collection.Find(item => item.ID == classid).FirstOrDefault(); return(classItem); }
public ActionResult UpdateProgress(ClassAccessViewModel viewModel) { var classAccessRepository = new ClassAccessRepository(_context); var classRepository = new ClassRepository(_context); var classInfo = classRepository.GetClass(viewModel.ClassId, _loggedUser.Id, GetUserRole(_loggedUser)); classAccessRepository.UpdateProgress(viewModel.ToEntity(_loggedUser, classInfo.Class)); return(new HttpStatusCodeResult(HttpStatusCode.OK, "Updated")); }
public ActionResult ListComments(Guid classId, int page = 1) { var classRepository = new ClassRepository(_context); var classInfo = classRepository.GetClass(classId, _loggedUser.Id, GetUserRole(_loggedUser)); var humanizer = new DefaultDateTimeHumanizeStrategy(); var comments = classInfo.Class.Comments .OrderByDescending(x => x.DateTime) .Skip((page - 1) * 10) .Take(10) .ToList(); return(Json(CommentViewModel.FromEntityList(comments, humanizer, _loggedUser.Id), JsonRequestBehavior.AllowGet)); }
/// <summary> /// This adds a Class to a User's Collection of Classes. /// </summary> /// <param name="userName"></param> /// <param name="selectedClass"></param> /// <returns name="isClassAdded"></returns> public bool AddNewClass(string userName, ListClassesViewModel selectedClass) { bool isClassAdded = false; UserModel currentUser = _userRepository.GetUser(userName); ClassModel classToAdd = _classRepository.GetClass(selectedClass.ClassName); if (currentUser.UserId != null && classToAdd.ClassId != null) { List <ClassModel> currentUsersClasses = _classRepository.ListUserClasses((int)currentUser.UserId); if (!currentUsersClasses.Contains(classToAdd)) { isClassAdded = _userRepository.AddUserClass((int)currentUser.UserId, (int)classToAdd.ClassId); } } return(isClassAdded); }
public async Task <IActionResult> ClassEdit(ClassModel model) { var user = await userManager.GetUserAsync(User); ClassRepository repo = new ClassRepository(configModel.ConnectionString); ClassModel dbClass; // Ensure that ONLY staff accounts have access to this API endpoint if (user == null || !await userManager.IsInRoleAsync(user, UserHelpers.UserRoles.Staff.ToString())) { return(Utilities.ErrorJson("Not authorized")); } // Validate that a name was provided if (String.IsNullOrEmpty(model.Name)) { return(Utilities.ErrorJson("Name is required")); } // Verify that a valid class id was provided dbClass = repo.GetClass(model.Id); if (dbClass == null) { return(Utilities.ErrorJson("Invalid class id")); } // Send to the database try { repo.UpdateClass(model.Id, model.Name, model.Location == null ? "" : model.Location); } catch (Exception e) { return(Utilities.ErrorJson(e.Message)); } return(Utilities.NoErrorJson()); }
public ActionResult Comment(FormCollection formData) { if (string.IsNullOrEmpty(formData["CommentText"])) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var comment = new CommentViewModel { ClassId = new Guid(formData["ClassId"]), CommentText = formData["CommentText"] }; var classRepository = new ClassRepository(_context); var classInfo = classRepository.GetClass(comment.ClassId, _loggedUser.Id, GetUserRole(_loggedUser)); comment.DateTime = DateTime.Now; classRepository.SendComment(comment.ToEntity(_loggedUser, classInfo.Class)); _context.Save(_loggedUser); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }