예제 #1
0
        private POPhoto getPOPhotoByID(int poPhotoID, CFIEntities db)
        {
            var query =
                from p in db.POPhotos
                where p.ID == poPhotoID
                select p;

            POPhoto[] poPhotos = query.ToArray <POPhoto>();
            if (poPhotos.Length == 0)
            {
                return(null);
            }
            else
            {
                POPhoto poPhoto = poPhotos[0];
                if (poPhoto.Deleted == false)
                {
                    return(poPhoto);
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #2
0
 public PhotoInfo GetPhoto(string accessToken, int photoID)
 {
     logMethodInvocation();
     checkAccessToken(accessToken);
     try
     {
         using (CFIEntities db = new CFIEntities())
         {
             POPhoto poPhoto = getPOPhotoByID(photoID, db);
             if (poPhoto == null)
             {
                 return(null);
             }
             else
             {
                 return(ConversionUtils.ToPhotoInfo(poPhoto, db));
             }
         }
     }
     catch (Exception ex)
     {
         logException(ex);
         return(null);
     }
 }
예제 #3
0
        public bool AddPhoto(string accessToken, int orderID, PhotoInfo photo, string fileExtension, string uploadedFileClaimToken)
        {
            logMethodInvocation();
            checkAccessToken(accessToken);
            try
            {
                using (CFIEntities db = new CFIEntities())
                {
                    Order order = getOrderByID(orderID, db);

                    // the file name will depend on the po number and how many other photos may have already been added
                    string fileName = getPhotoFileName(order.OrderID, fileExtension);
                    photo.FilePath = fileName;

                    // claim the uploaded file and name it and store it in the proper location
                    byte[] photoBytes = Globals.FileTransferManager.Uploader.ClaimFile(uploadedFileClaimToken);
                    savePhoto(order.OrderID, fileName, photoBytes);

                    POPhoto poPhoto = ConversionUtils.ToPOPhoto(photo, orderID);
                    order.POPhotos.Add(poPhoto);
                    db.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                logException(ex);
                return(false);
            }
        }
예제 #4
0
        public static POPhoto ToPOPhoto(PhotoInfo photo, int orderID)
        {
            POPhoto poPhoto = new POPhoto();

            poPhoto.OrderID         = orderID;
            poPhoto.Title           = photo.Title;
            poPhoto.FilePath        = photo.FilePath;
            poPhoto.DateTimeEntered = photo.DateTimeEntered;
            poPhoto.EnteredByUserID = photo.EnteredByUserID;
            return(poPhoto);
        }
예제 #5
0
        private string queuePhotoDownloadInternal(int photoID, CFIEntities db)
        {
            var query =
                from p in db.POPhotos
                where p.ID == photoID
                select p;

            POPhoto poPhoto   = query.Single <POPhoto>();
            string  targetDir = getTargetPhotoDirectory(poPhoto.Order.OrderID);
            string  fullPath  = Path.Combine(targetDir, poPhoto.FilePath);

            if (File.Exists(fullPath) == false)
            {
                return(null);
            }
            byte[] bytes = File.ReadAllBytes(fullPath);

            // queue file into downloader
            return(Globals.FileTransferManager.Downloader.QueueFile(bytes));
        }
예제 #6
0
        public static PhotoInfo ToPhotoInfo(POPhoto poPhoto, CFIEntities db)
        {
            PhotoInfo photo = new PhotoInfo();

            photo.ID              = poPhoto.ID;
            photo.FilePath        = poPhoto.FilePath;
            photo.DateTimeEntered = poPhoto.DateTimeEntered;
            photo.Title           = poPhoto.Title;

            if (poPhoto.EnteredByUserID != null)
            {
                photo.EnteredByUserID = poPhoto.EnteredByUserID.Value;
                photo.EnteredByUser   = getUserName(poPhoto.EnteredByUserID.Value, db);
            }
            else
            {
                photo.EnteredByUserID = -1;
                photo.EnteredByUser   = null;
            }

            return(photo);
        }
예제 #7
0
 public bool DeletePhoto(string accessToken, int photoID)
 {
     logMethodInvocation();
     checkAccessToken(accessToken);
     try
     {
         using (CFIEntities db = new CFIEntities())
         {
             POPhoto poPhoto = getPOPhotoByID(photoID, db);
             if (poPhoto != null)
             {
                 poPhoto.Deleted = true;
                 db.SaveChanges();
                 deletePhoto(poPhoto.Order.OrderID, poPhoto.FilePath);
             }
         }
         return(true);
     }
     catch (Exception ex)
     {
         logException(ex);
         return(false);
     }
 }