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); } }
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)); } } }
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(); } }
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(); } }
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); } } } }