예제 #1
0
 public StudentCertificateDTO GetStudentCertificate(Guid studentCertId)
 {
     try
     {
         return(StudentCertificatesViewRepository.Get(x => x.StudentCertificateId == studentCertId).Entity2StudentCertificateDto());
     }
     catch (Exception ex)
     {
         Logger.Error("GetStudentCertificate by id " + studentCertId, studentCertId, ex, CommonEnums.LoggerObjectTypes.Certificate);
         return(new StudentCertificateDTO {
             IsValid = false, Message = FormatError(ex)
         });
     }
 }
예제 #2
0
        public StudentCertificateDTO GetStudentCertificate(string key)
        {
            try
            {
                var decrypted = _encryptionServices.DecryptText(key);

                var keys = decrypted.Split(Convert.ToChar(KEY_SEPARATOR));

                if (keys.Count() != 3)
                {
                    Logger.Warn("GetStudentCertificate by key " + key + ":: keys missing with count " + keys.Count(), CommonEnums.LoggerObjectTypes.Certificate);
                    return(new StudentCertificateDTO {
                        IsValid = false, Message = "Certificate not found"
                    });
                }

                Guid sid;
                int  userId;
                int  certid;

                if (!Guid.TryParse(keys[0], out sid) || !int.TryParse(keys[1], out userId) || !int.TryParse(keys[2], out certid))
                {
                    Logger.Warn("GetStudentCertificate by key " + key + ":: key not parsed", CommonEnums.LoggerObjectTypes.Certificate);
                    return(new StudentCertificateDTO {
                        IsValid = false, Message = "Certificate not found"
                    });
                }

                var certificate = StudentCertificatesViewRepository.Get(x => x.StudentCertificateId == sid && x.StudentUserId == userId && x.CertificateId == certid);

                if (certificate == null)
                {
                    Logger.Warn("GetStudentCertificate by key " + key + ":: student certificate not found", CommonEnums.LoggerObjectTypes.Certificate);
                    return(new StudentCertificateDTO {
                        IsValid = false, Message = "Certificate not found"
                    });
                }

                return(certificate.Entity2StudentCertificateDto());
            }
            catch (Exception ex)
            {
                Logger.Error("GetStudentCertificate by key " + key, null, ex, CommonEnums.LoggerObjectTypes.Certificate);
                return(new StudentCertificateDTO {
                    IsValid = false, Message = "Certificate not found"
                });
            }
        }
예제 #3
0
        public StudentCertificateDTO GetStudentCertificate(int courseId, int userId)
        {
            try
            {
                var studentCertificate = StudentCertificatesViewRepository.Get(x => x.CourseId == courseId && x.StudentUserId == userId);

                if (studentCertificate != null)
                {
                    return(studentCertificate.Entity2StudentCertificateDto());
                }

                var certificateEntity = CertificateRepository.GetMany(x => x.CourseId == courseId).First();

                if (certificateEntity == null)
                {
                    Logger.Warn("GetStudentCertificate for course " + courseId + ":: certificate entity not found", CommonEnums.LoggerObjectTypes.Quiz);
                    return(new StudentCertificateDTO {
                        IsValid = false, Message = "certificate entity not found"
                    });
                }

                var studentCertificateEntity = certificateEntity.CertificateEntity2StudentCertificateEntity(userId);

                StudentCertificatesRepository.Add(studentCertificateEntity);

                string error;

                return(StudentCertificatesRepository.UnitOfWork.CommitAndRefreshChanges(out error) ?
                       StudentCertificatesViewRepository.Get(x => x.CourseId == courseId && x.StudentUserId == userId).Entity2StudentCertificateDto() :
                       new StudentCertificateDTO {
                    IsValid = false, Message = error
                });
            }
            catch (Exception ex)
            {
                Logger.Error("GetStudentCertificate for course " + courseId, userId, ex, CommonEnums.LoggerObjectTypes.Certificate);
                return(new StudentCertificateDTO {
                    IsValid = false, Message = FormatError(ex)
                });
            }
        }