static int Set(UserLicenseCertification item, bool internalUpdate = false)
 {
     if (item.userLicenseCertificationID > 0)
     {
         Update(item, internalUpdate);
         return(item.userLicenseCertificationID);
     }
     else
     {
         return(Insert(item, internalUpdate));
     }
 }
Exemple #2
0
        public static int SubmitPhoto(UserLicenseCertification item, string originalFileName, Stream photo)
        {
            // For updates, needs to remove previous file
            if (item.userLicenseCertificationID > 0)
            {
                var oldItem = Get(item.userID, item.jobTitleID, item.languageID, item.userLicenseCertificationID);
                if (oldItem == null)
                {
                    // Not found:
                    return(0);
                }
                if (!String.IsNullOrEmpty(oldItem.submittedImageLocalURL))
                {
                    var localPath = oldItem.submittedImageLocalURL.Replace(LcUrl.AppUrl, "");
                    localPath = HttpContext.Current.Server.MapPath(LcUrl.RenderAppPath + localPath);
                    File.Delete(localPath);
                }
            }

            // File name with special prefix
            var    autofn      = Guid.NewGuid().ToString().Replace("-", "");
            string fileName    = photoPrefix + autofn + (System.IO.Path.GetExtension(originalFileName) ?? ".jpg");
            string virtualPath = LcUrl.RenderAppPath + LcData.Photo.GetUserPhotoFolder(item.userID);
            var    path        = HttpContext.Current.Server.MapPath(virtualPath);

            item.submittedImageLocalURL = LcUrl.AppUrl + LcData.Photo.GetUserPhotoFolder(item.userID) + fileName;
            // Check folder or create
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            using (var file = File.Create(path + fileName))
            {
                photo.CopyTo(file);
            }
            // TODO: i18n
            var msg = "UserID: " + item.userID + " submitted a photo of their License/Certification to being verified and added. It can be found in the FTP an folder: " + virtualPath;
            // TODO create config value
            var email = "*****@*****.**";

            LcMessaging.SendMail(email, "License/Certification Verification Request", msg);

            return(Set(item));
        }
 private static void Update(UserLicenseCertification item, bool internalUpdate = false)
 {
     // TODO, for an admin dashboard, we may need to implement internalUpdate allowing for update of all non-ID fields.
     if (internalUpdate)
     {
         throw new NotImplementedException("Internal update not implemented");
     }
     using (var db = new LcDatabase())
     {
         db.Execute(@"
             UPDATE userlicensecertifications SET
                  submittedImageLocalURL = @3
             WHERE
                 ProviderUserID = @0
                 AND PositionID = @1
                 AND userLicenseCertificationID = @2
         ", item.userID, item.jobTitleID, item.userLicenseCertificationID, item.submittedImageLocalURL);
     }
 }
        private static int Insert(UserLicenseCertification item, bool internalUpdate = false)
        {
            // TODO, for an admin dashboard, we may need to implement internalUpdate allowing for update of all non-ID fields.
            if (internalUpdate)
            {
                throw new NotImplementedException("Internal update not implemented");
            }
            var user = UserProfile.Get(item.userID);

            using (var db = new LcDatabase())
            {
                // Constraint: licenses cannot be duplicated for an existant licenseID (>0), but they can for the special wildcard IDs (-1, 0)
                if (item.licenseCertificationID > 0)
                {
                    var many = (int)db.QueryValue("SELECT count(*) FROM UserLicenseCertifications WHERE ProviderUserID = @0 AND PositionID = @1 AND LicenseCertificationID = @2",
                                                  item.userID, item.jobTitleID, item.licenseCertificationID);
                    if (many > 0)
                    {
                        throw new ConstraintException("You have already registered that license, please try to update it if you want to submit a new file.");
                    }
                }

                return((int)db.QueryValue(sqlInsertNew,
                                          item.userID,
                                          item.jobTitleID,
                                          item.licenseCertificationID,
                                          2,
                                          "",
                                          "",
                                          null,
                                          "",
                                          user.firstName,
                                          user.lastName,
                                          "",
                                          "",
                                          "",
                                          "",
                                          "",
                                          item.userID,
                                          item.submittedImageLocalURL
                                          ));
            }
        }
        public static UserLicenseCertification FromDB(dynamic record)
        {
            if (record == null)
            {
                return(null);
            }
            var item = new UserLicenseCertification
            {
                userLicenseCertificationID = record.userLicenseCertificationID,
                userID                     = record.userID,
                jobTitleID                 = record.jobTitleID,
                licenseCertificationID     = record.licenseCertificationID,
                statusID                   = record.statusID,
                licenseCertificationNumber = record.licenseCertificationNumber,
                licenseCertificationUrl    = record.licenseCertificationUrl,
                expirationDate             = record.expirationDate,
                issueDate                  = record.issueDate,
                firstName                  = record.firstName,
                lastName                   = record.lastName,
                middleInitial              = record.middleInitial,
                secondLastName             = record.secondLastName,
                businessName               = record.businessName,
                comments                   = record.comments,
                verifiedBy                 = record.verifiedBy,
                lastVerifiedDate           = record.lastVerifiedDate,
                submitDate                 = record.submitDate,
                submittedBy                = record.submittedBy,
                submittedImageLocalURL     = record.submittedImageLocalURL,
                status                     = record.status,
                statusDescription          = record.statusDescription,
                languageID                 = record.languageID,
            };

            item.FillLicenseCertification();
            return(item);
        }