Ejemplo n.º 1
0
        private void GetImagesFromDrive(string FolderName)
        {
            GoogleDriveAPITool     googleDrive = new GoogleDriveAPITool();
            List <GoogleDriveFile> collection  = googleDrive.GetDriveFiles();
            GoogleDriveFile        folder      = googleDrive.GetDriveFolder(FolderName);

            if (folder != null)
            {
                string folderId = folder.Id;
                List <GoogleDriveFile> images = new List <GoogleDriveFile>();
                foreach (GoogleDriveFile item in collection)
                {
                    if (item.Parents != null && item.Parents.Contains(folderId))
                    {
                        images.Add(item);
                    }
                }
                foreach (GoogleDriveFile item in images)
                {
                    string fileId   = item.Id;
                    string FilePath = googleDrive.DownloadGoogleFile(fileId);
                    googleDrive.DeleteGoogleFile(fileId);
                }
            }
        }
Ejemplo n.º 2
0
        public bool DeleteMedicine(int?id)
        {
            bool Result = true;

            try
            {
                Medicine medicine = GetMedicine(id);
                if (medicine == null)
                {
                    return(false);
                }
                using (var ctx = new DrugsContext())
                {
                    ctx.Configuration.ValidateOnSaveEnabled = false;
                    ctx.Medicines.Attach(medicine);
                    ctx.Entry(medicine).State = EntityState.Deleted;
                    ctx.SaveChanges();
                }
                GoogleDriveAPITool.DeleteGoogleFileByName(medicine.imagePath);
            }
            catch (Exception)
            {
                Result = false;
            }

            return(Result);
        }
Ejemplo n.º 3
0
 public void AddMedicine(Medicine medicine, HttpPostedFileBase httpPostedFile)
 {
     try
     {
         using (var ctx = new DrugsContext())
         {
             ctx.Medicines.Add(medicine);
             ctx.SaveChanges();
         }
         GoogleDriveAPITool.FileUpload(httpPostedFile);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 4
0
 public void UpdateMedicine(Medicine medicine, HttpPostedFileBase httpPostedFile)
 {
     try
     {
         Medicine med = GetMedicine(medicine.Id);
         GoogleDriveAPITool.DeleteGoogleFileByName(med.imagePath);
         using (var ctx = new DrugsContext())
         {
             ctx.Entry(medicine).State = EntityState.Modified;
             ctx.SaveChanges();
         }
         GoogleDriveAPITool.FileUpload(httpPostedFile);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }