Exemple #1
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"
                });
            }
        }