コード例 #1
0
ファイル: AddingBuying.aspx.cs プロジェクト: DarkGraf/Buying
    protected void btnOk_Click(object sender, EventArgs e)
    {
        using (BuyingClient client = BuyingClient.Create(Global.Address))
        {
          BuyingAddDto buyingInfo = new BuyingAddDto
          {
              Goods = Guid.Parse(lstGood.SelectedValue),
              Priority = int.Parse(txtPriority.Text),
              Comment = txtComment.Text
          };
            client.AddBuying(buyingInfo);
        }

        Response.Redirect("Default.aspx");
    }
コード例 #2
0
ファイル: BuyingService.cs プロジェクト: DarkGraf/Buying
        public void AddBuying(BuyingAddDto buyingInfo)
        {
            #region Sql-Запрос.
            /*declare @CommentId uniqueidentifier
            if @Comment is not null and rtrim(@Comment) <> ''
            begin
              set @CommentId = newid()
            end

            insert into Buying (Id, Goods, Priority, InputDate, Comment)
            values (newid(), @Goods, @Priority, getdate(), @CommentId)

            if @CommentId is not null
            begin
              insert into Comments(Id, Description)
              values (@CommentId, @Comment)
            end*/
            #endregion

            using (EFUnitOfWork uow = new EFUnitOfWork("GoodsBuyingConnectionString"))
            using (var transaction = uow.BeginTransaction())
            {
                // Если комментарий есть, добавим его сначала.
                Comments comment = null;
                if (!string.IsNullOrWhiteSpace(buyingInfo.Comment))
                {
                    comment = new Comments { Description = buyingInfo.Comment };
                    uow.Comments.Create(comment);
                    uow.Save();
                }

                Dal.Entities.Buying buying = new Dal.Entities.Buying
                {
                    Goods = buyingInfo.Goods,
                    Priority = buyingInfo.Priority,
                    Comment = comment != null ? comment.Id : (Guid?)null
                };
                uow.Buyings.Create(buying);
                // Обновим дату синхронизации.
                UpdateSyncDate(uow);
                uow.Save();
                transaction.Commit();
            }
        }