예제 #1
0
        public void AddImageDrugs(int id, HttpPostedFileBase file)
        {
            try
            {
                //  string path =
                // Path.Combine(HttpContext.Current.Server.MapPath("~/GoogleDriveFiles"),
                // Path.GetFileName(file.FileName));
                // file.SaveAs(path);
                using (var ctx = new mediDB())
                {
                    Medicine tmp = ctx.Drugs.First(m => m.Id == id);
                    if (tmp.ImageUrl == null)
                    {
                        tmp.ImageUrl = @"/images/" + file.FileName;
                        ctx.SaveChanges();

                        //Google Drive API
                        GoogleDriveAPIHelper gd = new GoogleDriveAPIHelper();
                        gd.UplaodFileOnDriveInFolder(file, file.FileName, "MedicinesImages");
                    }
                    else
                    {
                        GoogleDriveAPIHelper gd = new GoogleDriveAPIHelper();
                        gd.deleteFile(tmp.ImageUrl);
                        tmp.ImageUrl = @"/images/" + file.FileName;
                        ctx.SaveChanges();

                        //Google Drive API
                        gd.UplaodFileOnDriveInFolder(file, file.FileName, "MedicinesImages");
                    }
                }
            }
            catch (Exception e) { throw new Exception(e.Message); }
        }
예제 #2
0
 public void RemoveDrugs(int id)
 {
     try
     {
         using (var ctx = new mediDB())
         {
             //Google Drive API
             GoogleDriveAPIHelper gd       = new GoogleDriveAPIHelper();
             Medicine             medicine = ctx.Drugs.Find(id);
             gd.deleteFile(medicine.ImageUrl);
             ctx.Drugs.Remove(medicine);
             ctx.SaveChanges();
         }
     }
     catch (Exception e) { throw new Exception(e.Message); }
 }
예제 #3
0
        public void UpdateDrugs(Medicine medicine, int id)
        {
            try
            {
                using (var ctx = new mediDB())
                {
                    Medicine tmp = ctx.Drugs.First(m => m.Id == id);
                    tmp.CommercialName     = medicine.CommercialName;
                    tmp.GenericName        = medicine.GenericName;
                    tmp.Producer           = medicine.Producer;
                    tmp.ActiveIngredients  = medicine.ActiveIngredients;
                    tmp.DoseCharacteristic = medicine.DoseCharacteristic;
                    tmp.ImageUrl           = medicine.ImageUrl;
                    ctx.SaveChanges();

                    //Google Drive API
                    GoogleDriveAPIHelper gd = new GoogleDriveAPIHelper();
                    //gd.deleteAllFiles(medicineId.ToString());
                    //gd.UplaodFileOnDriveInFolder(file, medicineId.ToString(), "cloudComputing");
                }
            }
            catch (Exception e) { throw new Exception(e.Message); }
        }