Пример #1
0
 private StudentExam?DataTableToStudentExam(DataTable dt)
 {
     if (dt != null && dt.Rows.Count > 0)
     {
         StudentExam info = new StudentExam();
         info.IsFirstLogin  = dt.Rows[0]["IsFirstLogin"] == DBNull.Value ? 2 : Convert.ToInt32(dt.Rows[0]["IsFirstLogin"]);
         info.StudentName   = dt.Rows[0]["StudentName"] == DBNull.Value ? "" : dt.Rows[0]["StudentName"].ToString();
         info.StudentExamId = dt.Rows[0]["StudentExamId"] == DBNull.Value ? -100 : Convert.ToInt32(dt.Rows[0]["StudentExamId"]);
         info.StudentNumber = dt.Rows[0]["StudentNumber"] == DBNull.Value ? "" : dt.Rows[0]["StudentNumber"].ToString();
         info.StudentSex    = dt.Rows[0]["StudentSex"] == DBNull.Value ? -100 : Convert.ToInt32(dt.Rows[0]["StudentSex"]);
         info.StudentPhone  = dt.Rows[0]["StudentPhone"] == DBNull.Value ? "" : dt.Rows[0]["StudentPhone"].ToString();
         info.Password      = dt.Rows[0]["Password"] == DBNull.Value ? "" : dt.Rows[0]["Password"].ToString();
         info.Type          = dt.Rows[0]["Type"] == DBNull.Value ? -100 : Convert.ToInt32(dt.Rows[0]["Type"]);
         if (dt.Rows[0]["LoginDateTime"] != DBNull.Value)
         {
             DateTime datetime;
             if (DateTime.TryParse(dt.Rows[0]["LoginDateTime"].ToString(), out datetime))
             {
                 info.LoginDateTime = datetime.ToString("yyyy-MM-dd HH:mm:ss");
             }
         }
         return(info);
     }
     else
     {
         return(null);
     }
 }
Пример #2
0
        private List <StudentExam> DataTableToStudentExams(DataTable dt)
        {
            List <StudentExam> listInfo = new List <StudentExam>();

            if (dt != null)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    StudentExam info = new StudentExam();
                    info.IsFirstLogin  = dr["IsFirstLogin"] == DBNull.Value ? 2 : Convert.ToInt32(dr["IsFirstLogin"]);
                    info.StudentName   = dr["StudentName"] == DBNull.Value ? "" : dr["StudentName"].ToString();
                    info.StudentExamId = dr["StudentExamId"] == DBNull.Value ? -100 : Convert.ToInt32(dr["StudentExamId"]);
                    info.StudentNumber = dr["StudentNumber"] == DBNull.Value ? "" : dr["StudentNumber"].ToString();
                    info.StudentSex    = dr["StudentSex"] == DBNull.Value ? -100 : Convert.ToInt32(dr["StudentSex"]);
                    info.StudentPhone  = dr["StudentPhone"] == DBNull.Value ? "" : dr["StudentPhone"].ToString();
                    info.Type          = dr["Type"] == DBNull.Value ? -100 : Convert.ToInt32(dr["Type"]);
                    if (dr["LoginDateTime"] != DBNull.Value)
                    {
                        DateTime datetime;
                        if (DateTime.TryParse(dr["LoginDateTime"].ToString(), out datetime))
                        {
                            info.LoginDateTime = datetime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                    }

                    listInfo.Add(info);
                }
            }
            return(listInfo);
        }
Пример #3
0
 public StudentExam?OptStudentNumber(StudentExam info)
 {
     if (!IsExistStudentNumber(info.StudentNumber))
     {
         string strSql = "insert into StudentExam(StudentNumber,StudentName) values(@StudentNumber,@StudentName)";
         int    obj    = DBFactory.GetDB(DBType.SQLITE, m_strConn).ExecuteNonQuery(strSql, new DbParameter[] {
             new SQLiteParameter()
             {
                 Value = info.StudentNumber, ParameterName = "@StudentNumber"
             },
             new SQLiteParameter()
             {
                 Value = info.StudentName == null?"":info.StudentName, ParameterName = "@StudentName"
             }
         });
         if (obj > 0)
         {
             return(GetStudentExamNumber(info.StudentNumber));
         }
         else
         {
             return(null);
         }
     }
     else
     {
         return(GetStudentExamNumber(info.StudentNumber));
     }
 }
Пример #4
0
        public int AddUserInfo(StudentExam info)
        {
            string strSql = @"insert into StudentExam(StudentName,StudentNumber,Password,Type,IsFirstLogin) 
                            values(@StudentName,@StudentNumber,@Password,@Type,@IsFirstLogin)";

            return(DBFactory.GetDB(DBType.SQLITE, m_strConn).ExecuteNonQuery(strSql, new DbParameter[] {
                new SQLiteParameter()
                {
                    Value = info.Password, ParameterName = "@Password"
                },
                new SQLiteParameter()
                {
                    Value = info.StudentName, ParameterName = "@StudentName"
                },
                new SQLiteParameter()
                {
                    Value = info.StudentNumber, ParameterName = "@StudentNumber"
                },
                new SQLiteParameter()
                {
                    Value = info.Type, ParameterName = "@Type"
                },
                //new SQLiteParameter(){  Value=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), ParameterName="@LoginDateTime"},
                new SQLiteParameter()
                {
                    Value = 1, ParameterName = "@IsFirstLogin"
                }
            }));
        }
Пример #5
0
 private static void ValidateStorageStudentExam(StudentExam storageStudentExam, Guid studentExamId)
 {
     if (storageStudentExam == null)
     {
         throw new NotFoundStudentExamException(studentExamId);
     }
 }
Пример #6
0
        public async Task ShouldRetrieveStudentExamByIdAsync()
        {
            // given
            Guid           randomStudentExamId = Guid.NewGuid();
            Guid           inputStudentExamId  = randomStudentExamId;
            DateTimeOffset randomDateTime      = GetRandomDateTime();
            StudentExam    randomStudentExam   = CreateRandomStudentExam(randomDateTime);
            StudentExam    storageStudentExam  = randomStudentExam;
            StudentExam    expectedStudentExam = storageStudentExam;

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectStudentExamByIdAsync(inputStudentExamId))
            .ReturnsAsync(storageStudentExam);

            // when
            StudentExam actualStudentExam =
                await this.studentExamService.RetrieveStudentExamByIdAsync(inputStudentExamId);

            // then
            actualStudentExam.Should().BeEquivalentTo(expectedStudentExam);

            this.dateTimeBrokerMock.Verify(broker =>
                                           broker.GetCurrentDateTime(),
                                           Times.Never);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentExamByIdAsync(inputStudentExamId),
                                          Times.Once);

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
Пример #7
0
        private static void ValidateInvalidAuditFields(StudentExam studentExam)
        {
            switch (studentExam)
            {
            case { } when IsInvalid(studentExam.CreatedBy):
                throw new InvalidStudentExamInputException(
                          parameterName: nameof(StudentExam.CreatedBy),
                          parameterValue: studentExam.CreatedBy);

            case { } when IsInvalid(studentExam.UpdatedBy):
                throw new InvalidStudentExamInputException(
                          parameterName: nameof(StudentExam.UpdatedBy),
                          parameterValue: studentExam.UpdatedBy);

            case { } when IsInvalid(studentExam.CreatedDate):
                throw new InvalidStudentExamInputException(
                          parameterName: nameof(StudentExam.CreatedDate),
                          parameterValue: studentExam.CreatedDate);

            case { } when IsInvalid(studentExam.UpdatedDate):
                throw new InvalidStudentExamInputException(
                          parameterName: nameof(StudentExam.UpdatedDate),
                          parameterValue: studentExam.UpdatedDate);
            }
        }
Пример #8
0
        public async Task <ActionResult <StudentExam> > PostStudentExam(StudentExam studentExam)
        {
            _context.StudentExams.Add(studentExam);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetStudentExam", new { id = studentExam.Id }, studentExam));
        }
Пример #9
0
 private static void ValidateStudentExam(StudentExam StudentExam)
 {
     if (StudentExam is null)
     {
         throw new NullStudentExamException();
     }
 }
Пример #10
0
 private static void ValidateStudentExamIsNotNull(StudentExam studentExam)
 {
     if (studentExam is null)
     {
         throw new NullStudentExamException();
     }
 }
Пример #11
0
        private static void ValidateStudentExamIds(StudentExam studentExam)
        {
            switch (studentExam)
            {
            case { } when IsInvalid(studentExam.CreatedBy):
                throw new InvalidStudentExamInputException(
                          parameterName: nameof(studentExam.CreatedBy),
                          parameterValue: studentExam.CreatedBy);

            case { } when IsInvalid(studentExam.UpdatedBy):
                throw new InvalidStudentExamInputException(
                          parameterName: nameof(studentExam.UpdatedBy),
                          parameterValue: studentExam.UpdatedBy);

            case { } when IsInvalid(studentExam.Id):
                throw new InvalidStudentExamInputException(
                          parameterName: nameof(studentExam.Id),
                          parameterValue: studentExam.Id);

            case { } when IsInvalid(studentExam.StudentId):
                throw new InvalidStudentExamInputException(
                          parameterName: nameof(studentExam.Student),
                          parameterValue: studentExam.Student);

            case { } when IsInvalid(studentExam.ExamId):
                throw new InvalidStudentExamInputException(
                          parameterName: nameof(studentExam.Exam),
                          parameterValue: studentExam.ExamId);

            case { } when IsInvalid(studentExam.TeacherId):
                throw new InvalidStudentExamInputException(
                          parameterName: nameof(studentExam.ReviewingTeacher),
                          parameterValue: studentExam.TeacherId);
            }
        }
        public void GetStudentExamsSVM()
        {
            ErrorsSVM = "";

            Student     student     = new Student();
            Exam        exam        = new Exam();
            StudentExam studentExam = new StudentExam();

            if (CurrentStudentSVM != null)
            {
                student = CurrentStudentSVM;
                studentExam.StudentId = student.Id;

                StudentExamsListSVM = studentExam.StudentByExams(studentExam.StudentId);
                if (CurrentSubjectNameSVM != null)
                {
                    StudentExamsBySubjectListSVM = StudentExamsListSVM.FindAll(x => x.Exam.Subject.Name == CurrentSubjectNameSVM).ToList();
                    exams = true;
                }
                else
                {
                    StudentExamsBySubjectListSVM = StudentExamsListSVM;
                    exams = true;
                }

                if (StudentExamsBySubjectListSVM.Count == 0)
                {
                    ErrorsSVM = "El alumno no ha realizado exámenes de " + CurrentSubjectNameSVM;
                    exams     = false;
                }
            }
        }
Пример #13
0
        public void ShouldThrowDependencyExceptionOnAddWhenSqlExceptionOccursAndLogIt()
        {
            // given
            DateTimeOffset dateTime          = GetRandomDateTime();
            StudentExam    randomStudentExam = CreateRandomStudentExam(dateTime);
            StudentExam    inputStudentExam  = randomStudentExam;

            inputStudentExam.UpdatedBy = inputStudentExam.CreatedBy;


            this.dateTimeBrokerMock.Setup(broker =>
                                          broker.GetCurrentDateTime())
            .Returns(dateTime);


            // when
            ValueTask <StudentExam> addStudentExamTask =
                this.studentExamService.AddStudentExamAsync(inputStudentExam);

            // then

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertStudentExamAsync(inputStudentExam),
                                          Times.Once);

            this.dateTimeBrokerMock.Verify(broker =>
                                           broker.GetCurrentDateTime(),
                                           Times.Once);

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
Пример #14
0
        /// <summary>
        /// Student exam notice
        /// </summary>
        /// <param name="studentExam"></param>
        /// <returns></returns>
        public List <Exam> StudentExamNotice(StudentExam studentExam)
        {
            SqlConnection connection = new SqlConnection(CONNECTION_STRING);

            connection.Open();
            SqlCommand command = new SqlCommand("spStudentExamNotice", connection);

            command.CommandType = CommandType.StoredProcedure;

            command.Parameters.Add(new SqlParameter("@UserId", studentExam.UserId));
            command.Parameters.Add(new SqlParameter("@Operation", studentExam.Operation));
            List <Exam> exams = new List <Exam>();

            using (SqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    Exam exam = new Exam();
                    exam.Id            = reader.GetInt32(0);
                    exam.ExamName      = reader.GetString(1);
                    exam.EffectiveTime = reader.GetDateTime(2);
                    exams.Add(exam);
                }
            }

            return(exams);
        }
Пример #15
0
        public void TotalPoints(int id)
        {
            StudentExam studentExam = _studentExamManager.Get(id);

            studentExam.OnPoints = studentExam.Exam.ExamQuestions.Count;
            _studentExamManager.Update(studentExam);
        }
        public void EditStudentExam(int examId, StudentExam newExam)
        {
            StudentExam model = studentExamRepository.GetById(examId);

            model = newExam;
            EditStudentExam(model);
        }
Пример #17
0
        public void DelStudentExamsSEVM()
        {
            StudentExam studentExam = new StudentExam();

            if (CurrentStudentExamSEVM == null)
            {
                studentExam.Delete();
                ErrorsList = studentExam.CurrentValidation.Errors.Select(x => new ErrorMessage()
                {
                    Message = x
                }).ToList();
            }

            else
            {
                ErrorsList = new List <ErrorMessage>();

                studentExam = CurrentStudentExamSEVM;
                studentExam.Delete();
                ErrorsList = studentExam.CurrentValidation.Errors.Select(x => new ErrorMessage()
                {
                    Message = x
                }).ToList();

                GetStudentExamsSEVM();
            }
        }
Пример #18
0
        public async Task <IActionResult> PutStudentExam(int id, StudentExam studentExam)
        {
            if (id != studentExam.StudentID)
            {
                return(BadRequest());
            }

            _context.Entry(studentExam).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StudentExamExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #19
0
        private async ValueTask <StudentExam> UpdateStudentExamRandomAsync(StudentExam studentExam)
        {
            studentExam.Score       = GetRandomNumber();
            studentExam.UpdatedDate = DateTimeOffset.UtcNow;

            return(studentExam);
        }
        public async Task ShouldThrowValidationExceptionOnModifyWhenStudentIdIsInvalidAndLogItAsync()
        {
            //given
            Guid           invalidStudentId   = Guid.Empty;
            DateTimeOffset dateTime           = GetRandomDateTime();
            StudentExam    randomStudentExam  = CreateRandomStudentExam(dateTime);
            StudentExam    invalidStudentExam = randomStudentExam;

            invalidStudentExam.StudentId = invalidStudentId;

            var invalidStudentExamException = new InvalidStudentExamException(
                parameterName: nameof(StudentExam.StudentId),
                parameterValue: invalidStudentExam.StudentId);

            var expectedStudentExamValidationException =
                new StudentExamValidationException(invalidStudentExamException);

            //when
            ValueTask <StudentExam> modifyStudentExamTask =
                this.studentExamService.ModifyStudentExamAsync(invalidStudentExam);

            //then
            await Assert.ThrowsAsync <StudentExamValidationException>(() =>
                                                                      modifyStudentExamTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedStudentExamValidationException))),
                                          Times.Once);

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnModifyWhenStudentExamIsNullAndLogItAsync()
        {
            //given
            StudentExam invalidStudentExam       = null;
            var         nullStudentExamException = new NullStudentExamException();

            var expectedStudentExamValidationException =
                new StudentExamValidationException(nullStudentExamException);

            //when
            ValueTask <StudentExam> modifyStudentExamTask =
                this.studentExamService.ModifyStudentExamAsync(invalidStudentExam);

            //then
            await Assert.ThrowsAsync <StudentExamValidationException>(() =>
                                                                      modifyStudentExamTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedStudentExamValidationException))),
                                          Times.Once);

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnModifyWhenUpdatedDateIsSameAsCreatedDateAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime          = GetRandomDateTime();
            StudentExam    randomStudentExam = CreateRandomStudentExam(dateTime);
            StudentExam    inputStudentExam  = randomStudentExam;

            var invalidStudentExamException = new InvalidStudentExamException(
                parameterName: nameof(StudentExam.UpdatedDate),
                parameterValue: inputStudentExam.UpdatedDate);

            var expectedStudentExamValidationException =
                new StudentExamValidationException(invalidStudentExamException);

            // when
            ValueTask <StudentExam> modifyStudentExamTask =
                this.studentExamService.ModifyStudentExamAsync(inputStudentExam);

            // then
            await Assert.ThrowsAsync <StudentExamValidationException>(() =>
                                                                      modifyStudentExamTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedStudentExamValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectStudentExamByIdAsync(It.IsAny <Guid>()),
                                          Times.Never);

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
Пример #23
0
        public ValueTask <StudentExam> AddStudentExamAsync(StudentExam studentExam) =>
        TryCatch(async() =>
        {
            ValidateStudentExamOnCreate(studentExam);

            return(await this.storageBroker.InsertStudentExamAsync(studentExam));
        });
Пример #24
0
        public async void ShouldThrowValidationExceptionOnAddWhenStudentExamIsNullAndLogItAsync()
        {
            // given
            StudentExam randomStudentExam        = default;
            StudentExam nullStudentExam          = randomStudentExam;
            var         nullStudentExamException = new NullStudentExamException();

            var expectedStudentExamValidationException =
                new StudentExamValidationException(nullStudentExamException);

            // when
            ValueTask <StudentExam> addStudentExamTask =
                this.studentExamService.AddStudentExamAsync(nullStudentExam);

            // then
            await Assert.ThrowsAsync <StudentExamValidationException>(() =>
                                                                      addStudentExamTask.AsTask());

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(expectedStudentExamValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertStudentExamAsync(It.IsAny <StudentExam>()),
                                          Times.Never);

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
Пример #25
0
        public async Task ShouldGetAllStudentExamsAsync()
        {
            // given
            int randomNumber       = GetRandomNumber();
            var randomStudentExams = new List <StudentExam>();

            for (int i = 0; i < randomNumber; i++)
            {
                randomStudentExams.Add(await PostRandomStudentExamAsync());
            }

            List <StudentExam> inputStudentExams    = randomStudentExams;
            List <StudentExam> expectedStudentExams = inputStudentExams.ToList();

            // when
            List <StudentExam> actualStudentExams = await this.otripleSApiBroker.GetAllStudentExamsAsync();

            // then
            foreach (StudentExam expectedStudentExam in expectedStudentExams)
            {
                StudentExam actualStudentExam = actualStudentExams.Single(student => student.Id == expectedStudentExam.Id);
                actualStudentExam.Should().BeEquivalentTo(expectedStudentExam);
                await DeleteStudentExam(actualStudentExam);
            }
        }
Пример #26
0
        public static StudentExam ProjectTo(this StudentExamRequest request, IMapper mapper)
        {
            StudentExam entity = mapper.Map <StudentExam>(request);

            entity.DateCreated = DateTime.Now;
            return(entity);
        }
Пример #27
0
        public void SaveStudentExamsSEVM()
        {
            MarkStringToDouble();
            StudentExam studentExamsSEVM = new StudentExam();

            if (MarkSEVM != 0)
            {
                Exam    exam    = new Exam();
                Student student = new Student();
                ErrorsList = new List <ErrorMessage>();


                exam    = CurrentExamSEVM;
                student = CurrentStudentSEVM;
                if (CurrentStudentExamSEVM != null)
                {
                    studentExamsSEVM = CurrentStudentExamSEVM;
                }

                studentExamsSEVM.Mark       = MarkSEVM;
                studentExamsSEVM.HasCheated = HasCheatedSEVM;
                if (CurrentStudentSEVM != null)
                {
                    studentExamsSEVM.StudentId = student.Id;

                    if (CurrentExamSEVM != null)
                    {
                        studentExamsSEVM.ExamId = exam.Id;
                    }
                }

                studentExamsSEVM.Save();

                ErrorsList = studentExamsSEVM.CurrentValidation.Errors.Select(x => new ErrorMessage()
                {
                    Message = x
                }).ToList();                                                                                                      //Nou

                if (CurrentStudentSEVM != null || CurrentStudentExamSEVM != null)
                {
                    GetStudentExamsSEVM();
                    MarkTextSEVM = "";
                }
            }


            CurrentStudentSEVM     = null;
            _currentExamSEVM       = null;
            CurrentStudentExamSEVM = null;
            DniSEVM         = "";
            NameSEVM        = "";
            TitleSEVM       = "";
            SubjectNameSEVM = "";
            DateSEVM        = default;
            MarkSEVM        = 0;
            HasCheatedSEVM  = false;

            isEdit = false;
        }
Пример #28
0
        public async ValueTask <StudentExam> DeleteStudentExamAsync(StudentExam studentExam)
        {
            EntityEntry <StudentExam> studentExamEntityEntry = this.StudentExams.Remove(studentExam);

            await this.SaveChangesAsync();

            return(studentExamEntityEntry.Entity);
        }
Пример #29
0
        public async ValueTask <StudentExam> InsertStudentExamAsync(StudentExam studentExam)
        {
            EntityEntry <StudentExam> studentExamEntityEntry = await this.StudentExams.AddAsync(studentExam);

            await this.SaveChangesAsync();

            return(studentExamEntityEntry.Entity);
        }
Пример #30
0
 public static void ProjectTo(this StudentExamRequest request, StudentExam entity)
 {
     entity.IsAbsent   = request.IsAbsent;
     entity.IsClosed   = request.IsClosed;
     entity.Note       = request.Note;
     entity.BehaviorId = request.BehaviorId;
     entity.ExamId     = request.ExamId;
 }