예제 #1
0
 public void DeleteImageOfProduct(int id)
 {
     if (AppCache.FindPhoto(id) != null)
     {
         AppCache.DeletePhoto(id);
     }
     using (var dataContext = new DataContext(_connectionString))
     {
         dataContext.ExecuteCommand("DELETE FROM BigPhoto WHERE product_id={0}", id);
     }
 }
예제 #2
0
 public bool IsImageExist(int id)
 {
     if (AppCache.FindPhoto(id) != null)
     {
         return(true);
     }
     else
     {
         using (var dataContext = new DataContext(_connectionString))
         {
             return(dataContext.GetTable <BigPhoto>().Any(c => c.ProductId == id && c.Picture != null));
         }
     }
 }
예제 #3
0
        public void UpdateImageOfProduct(BigPhoto bigPhoto)
        {
            if (AppCache.FindPhoto(bigPhoto.Id) != null)
            {
                AppCache.DeletePhoto(bigPhoto.Id);
                AppCache.Add(bigPhoto.Id, bigPhoto.Picture);
            }
            using (var dataContext = new DataContext(_connectionString))
            {
                BigPhoto dbPhoto = dataContext.GetTable <BigPhoto>().Single(p => p.ProductId == bigPhoto.ProductId);

                dbPhoto.Picture = bigPhoto.Picture;

                dataContext.SubmitChanges();
            }
        }
예제 #4
0
        public void UpdateImageOfUser(UserPhoto userPhoto)
        {
            if (AppCache.FindPhoto(userPhoto.Id) != null)
            {
                AppCache.DeletePhoto(userPhoto.Id);
                AppCache.Add(userPhoto.Id, userPhoto.Picture);
            }
            using (var dataContext = new DataContext(_connectionString))
            {
                UserPhoto dbPhoto = dataContext.GetTable <UserPhoto>().Single(p => p.UserId == userPhoto.UserId);

                dbPhoto.Picture = userPhoto.Picture;

                dataContext.SubmitChanges();
            }
        }
예제 #5
0
 public byte[] GetImageBytesById(int Id)
 {
     if (!IsImageExist(Id))
     {
         throw new Exception("This photo does not exist");
     }
     else
     {
         if (AppCache.FindPhoto(Id) != null)
         {
             return(AppCache.FindPhoto(Id));
         }
         else
         {
             using (var dataContext = new DataContext(_connectionString))
             {
                 byte[] rez = dataContext.GetTable <BigPhoto>().Single(c => c.ProductId == Id).Picture;
                 AppCache.Add(Id, rez);
                 return(rez);
             }
         }
     }
 }