protected void btnOk_Click(object sender, EventArgs e) { using (BuyingClient client = BuyingClient.Create(Global.Address)) { GoodsAddDto goods = new GoodsAddDto { Name = txtGood.Text }; client.AddGoods(goods); } Response.Redirect("GoodsDirectory.aspx"); }
public void AddGoods(GoodsAddDto goodsInfo) { #region Sql-запрос. /*if not exists(select 1 from Goods where Name = @Name) begin insert into Goods (Id, Name) values (newid(), @Name) end*/ #endregion using (EFUnitOfWork uow = new EFUnitOfWork("GoodsBuyingConnectionString")) using (var transaction = uow.BeginTransaction()) { if (uow.Goods.GetAll().Where(v => v.Name == goodsInfo.Name).Count() == 0) { Goods goods = new Goods { Name = goodsInfo.Name }; uow.Goods.Create(goods); uow.Save(); } transaction.Commit(); } }