public IActionResult Logout() { WisClient.Logout(); HttpContext.Session.Clear(); ViewBag.isLogged = false; return(RedirectToAction("Index", "Students")); }
public async Task <IActionResult> RegisterConfirmed(int?variantId, IList <int> sIds) { if (variantId == null || !sIds.Any()) { return(BadRequest()); } if (ModelState.IsValid) { var variant = (await _variantRepository.GetVariantById(variantId.Value)); if (variant == null) { return(NotFound()); } var students = await Task.WhenAll(sIds.Select(id => _studentRepository.GetStudentById(id) )); if (students != null) { var studentsPostDto = students.Select(StudentViewModel.CreateStudentPostDto).ToList(); var registrationDto = VariantViewModel.CreateRegistrationDto(variant); var registeredIds = await WisClient.RegisterStudents(studentsPostDto, registrationDto); foreach (var registeredId in registeredIds) { await _studentRepository.RegisterStudent(registeredId); await _studentRepository.SaveChanges(); } } } return(RedirectToAction(nameof(Index))); }
public async Task <bool> IsUserLogged() { var username = HttpContext.Session.GetString("_Username"); var auth = HttpContext.Session.GetString("_Auth"); if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(auth)) { return(false); } return(await WisClient.IsUserLogged(username, auth)); }
public async Task <IActionResult> Index(string username, string password) { string authBase64 = WisClient.GenerateBase64(username, password); bool isLoginCorrect = await WisClient.Login(username, authBase64); if (isLoginCorrect) { HttpContext.Session.Clear(); HttpContext.Session.SetString("_Username", username); HttpContext.Session.SetString("_Auth", authBase64); return(RedirectToAction("Index", "Students")); } ViewBag.LoginFailed = true; return(View()); }
// GET: Variants/Create public async Task <IActionResult> Create(CourseViewModel courseVm, int?itemId, int?points) { if (!ModelState.IsValid || courseVm == null || itemId == null || points == null) { return(BadRequest()); } var variantsDto = await WisClient.GetVariantsAsync(courseVm.WisId, itemId.Value); if (variantsDto == null) { return(NotFound()); } var variantsVm = variantsDto.Select(v => VariantViewModel.CreateVariantVm(v, itemId.Value, points.Value, courseVm)); return(View(variantsVm)); }
// GET: Variants/FindCourse public async Task <IActionResult> FindCourse(string searchString) { if (!string.IsNullOrEmpty(searchString)) { var courseDto = (await WisClient.GetCoursesAsync(searchString))?.FirstOrDefault(); if (courseDto != null) { var items = (await WisClient.GetItemsAsync(courseDto.Id)); if (items != null) { var courseVm = CourseViewModel.CreateCourseVm(courseDto); courseVm.Items = items.Select(ItemViewModel.CreateItemVm); return(View(courseVm)); } } } return(View()); }
public async Task <ActionResult <string> > CreateStudent([FromForm] string uid) { if (uid != null) { var auth = WisClient.AuthBase64; if (string.IsNullOrEmpty(auth)) { return(NotFound()); } Debug.WriteLine("Incoming ID: " + uid); var studentRfidDto = await WisClient.GetStudentByRfidUid(uid); int?activeVariantId = VariantViewModel.ActiveVariantId; if (activeVariantId == null) { return("Variant!"); } int variantId = activeVariantId.Value; var variant = await _variantRepository.GetVariantById(variantId); var studentsDto = await WisClient.GetStudents(variant.WisCourseId); var studentDto = studentsDto?.Single(s => s.Login == studentRfidDto.Login); if (studentDto == null) { return("Not found"); } if (_studentRepository.StudentExists(studentDto.Id)) { return("Registered"); } try { var student = StudentViewModel.CreateStudent(studentDto); var studentPostDto = StudentViewModel.CreateStudentPostDto(student); await _studentRepository.InsertStudent(student); await _studentRepository.AddStudentToVariant(student.Id, variantId); await _studentRepository.SaveChanges(); if (WisClient.AutoRegister) { var registerStudentsDto = new List <StudentPostDto> { studentPostDto }; var registrationDto = VariantViewModel.CreateRegistrationDto(variant); var registeredIds = await WisClient.RegisterStudents(registerStudentsDto, registrationDto); foreach (var registeredId in registeredIds) { await _studentRepository.RegisterStudent(registeredId); await _studentRepository.SaveChanges(); } } } catch (DbUpdateConcurrencyException) { } return(studentRfidDto.Login); } return(NotFound()); }