Exemplo n.º 1
0
 public ViewBasic(Data.Entities.Teacher teacher)
 {
     Id    = teacher.Id;
     Name  = teacher.Name;
     Email = teacher.Email;
     Image = teacher.Image;
 }
Exemplo n.º 2
0
 public static TeacherDto  FromEntity(Data.Entities.Teacher entity)
 {
     return(new TeacherDto()
     {
         Id = entity.Id,
         Name = entity.Name,
         Surname = entity.Surname,
         Email = entity.Email
     });
 }
Exemplo n.º 3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Teacher = await _context.Teachers.FirstOrDefaultAsync(m => m.Id == id);

            if (Teacher == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Exemplo n.º 4
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage));
                await initializeDropDowns();

                return(Page());
            }
            var user = new ApplicationUser {
                Name     = Input.Name,
                Email    = Input.Email,
                UserName = Input.Email
            };

            var cathedra = await _context.Cathedras.FindAsync(Input.CathedraId);

            if (Input.Role == Role.Teacher)
            {
                var teacher = new Data.Entities.Teacher
                {
                    User     = user,
                    Cathedra = cathedra
                };
                await _context.Teachers.AddAsync(teacher);
            }
            else if ((Input.Role == Role.Student))
            {
                var student = new Student
                {
                    User     = user,
                    Cathedra = cathedra
                };
                await _context.Students.AddAsync(student);
            }

            var result = await _userManager.CreateAsync(user, Input.Password);

            if (result.Succeeded)
            {
                await _userManager.AddToRoleAsync(user, Input.Role.ToString());
            }
            return(RedirectToPage("./Index"));
        }
        protected override OperationResult DoExecute(LoadExaminationSheetRequest request)
        {
            Data.Entities.Exam exam = _dbContext.Exams.Include(e => e.ExamTakers).FirstOrDefault(e => e.Id == request.ExamId);
            if (exam == null)
            {
                throw new ValidationFailedException()
                      {
                          ValidationResult = new ValidationResult($"Nieprawidłowe Id egzaminu: {request.ExamId}")
                      };
            }

            Data.Entities.Teacher teacher = _dbContext.Teachers.FirstOrDefault(t => t.Id == request.TeacherId);
            if (teacher == null)
            {
                throw new ValidationFailedException()
                      {
                          ValidationResult = new ValidationResult($"Nieprawidłowe Id nauczyciela: {request.TeacherId}")
                      };
            }

            List <int> points = null;

            try
            {
                points = GetPoints(request.FileStream);

                if (!points.Any())
                {
                    throw new Exception("Brak sczytanych punktów. - upewnij się że dokument jest poprawny");
                }
            }
            catch (Exception e)
            {
                throw new ValidationFailedException()
                      {
                          ValidationResult = new ValidationResult($"Sczytywanie punktów z karty nie powiodło się: {e.Message}")
                      };
            }
            request.FileStream.Seek(0, SeekOrigin.Begin);
            List <int> userIds = null;

            try
            {
                userIds = Decode(request.FileStream);
            }
            catch (Exception e)
            {
                throw new ValidationFailedException()
                      {
                          ValidationResult = new ValidationResult($"Sczytywanie kodu QR z karty nie powiodło się: {e.Message}")
                      };
            }

            if (userIds.GroupBy(x => x).Any(g => g.Count() > 1))
            {
                throw new ValidationFailedException()
                      {
                          ValidationResult = new ValidationResult("One user cannot take the same exam twice at the same moment")
                      };
            }

            if (points.Count != userIds.Count)
            {
                throw new ValidationFailedException()
                      {
                          ValidationResult = new ValidationResult("User count and points count dont match up")
                      };
            }

            var examTakers = exam.ExamTakers.ToDictionary(et => et.UserId);

            foreach (var item in points.Zip(userIds, (p, i) => (userId: i, points: p)))
            {
                var examTaker = examTakers[item.userId];
                examTaker.Score     = item.points;
                examTaker.TeacherId = request.TeacherId;
            }

            _dbContext.SaveChanges();
            return(new OperationSucceded());
        }