示例#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); }
 }