public void GetMainImgByGoodId() { try { var options = CreateNewContextOptions(); using (var db = new StoreContext(options)) { var repository = new GoodRepository(db); StoreTestHelper.PopulateDefaultStoreDataCtx(db); var item = GenerateModel(); GoodImage result = null; Assert.DoesNotThrow(() => result = repository.GetMainImg(item.Id)); Assert.True(result == null); item = db.Set <Good>().First(it => it.Code == "TestGoodPopulated"); Assert.DoesNotThrow(() => result = repository.GetMainImg(item.Id)); Assert.True(result != null); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public void AddImage(Good good, GoodImage image, bool isSaveNow = false) { try { if (good == null || good.Id == 0) { throw new ArgumentException("No good provided."); } if (image.Image == null) { throw new ArgumentException("No image provided."); } if (image.Image.Id == 0) { Add(image.Image); } image.ImageId = image.Image.Id; image.Image = null; image.GoodId = good.Id; Db.Set <GoodImage>().Add(image); if (isSaveNow) { Db.SaveChanges(); } } catch (Exception ex) { LogEventManager.Logger.Error(ex.Message, ex); throw; } }
public void RemoveImage(Good good, GoodImage image, bool isSaveNow = false) { try { if (good == null || good.Id == 0) { return; } if (image.Image == null || image.Image.Id == 0) { return; } var dbImage = Db.Set <GoodImage>().Single(it => it.ImageId == image.Image.Id && it.GoodId == good.Id); if (dbImage.IsMain) { var newMain = Db.Set <GoodImage>().FirstOrDefault(it => it.GoodId == good.Id); if (newMain != null) { newMain.IsMain = true; } } Db.Set <GoodImage>().Remove(dbImage); //todo: think about save delete of image entity. if (isSaveNow) { Db.SaveChanges(); } } catch (Exception ex) { LogEventManager.Logger.Error(ex.Message, ex); throw; } }
public void RemoveImage(Good good, GoodImage image, bool isSaveNow = false) { throw new NotImplementedException(); }