public static void DeleteClientAsset(ClientAsset clientAsset)
 {
     var ctx = new RepGenDataContext();
     ctx.ClientAssets.Attach(clientAsset);
     ctx.ClientAssets.DeleteOnSubmit(clientAsset);
     ctx.SubmitChanges();
 }
        public static Guid InsertClientAsset(ClientAsset clientAsset)
        {
            var ctx = new RepGenDataContext();
            ctx.ClientAssets.InsertOnSubmit(clientAsset);
            ctx.SubmitChanges();

            return clientAsset.GUID;
        }
    protected void gridAsset_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Insert") {
            TextBox textName = null;
            TextBox textAmount = null;

            string guidString = Request.QueryString["guid"].ToString();
            Guid clientGuid = new Guid(guidString);
            var source = e.CommandSource;

            if ((string)e.CommandArgument == "AllNew") {
                Table tbl = (Table)gridAsset.Controls[0];
                GridViewRow gvr = (GridViewRow)tbl.Controls[0];
                textName = (TextBox)gvr.FindControl("textAssetNameAddAllNew");
                textAmount = (TextBox)gvr.FindControl("textAmountAddAllNew");
            } else {
                textName = (TextBox)gridAsset.FooterRow.FindControl("textAssetNameAdd");
                textAmount = (TextBox)gridAsset.FooterRow.FindControl("textAmountAdd");
            }

            string name = textName.Text;
            decimal amount = 0;
            if (textAmount.Text != String.Empty)
                amount = Convert.ToDecimal(textAmount.Text);

            ClientAsset asset = new ClientAsset()
            {
                ClientGUID = clientGuid,
                AssetName = name,
                Amount = amount
            };

            var guid = ClientAsset.InsertClientAsset(asset);
            gridAsset.DataBind();
            int nrows = gridAsset.Rows.Count;

            if (nrows >= 1)
                gridAsset.SelectedIndex = nrows - 1;

        } else if (e.CommandName == "Delete") {
            gridAsset.DataBind();
            int nrows = gridAsset.Rows.Count;
            if (nrows > 1)
                gridAsset.SelectedIndex = 0;
            else
                gridAsset.SelectedIndex = -1;
        }
    }
 public static void UpdateClientAsset(ClientAsset clientAsset, ClientAsset original_clientAsset)
 {
     var ctx = new RepGenDataContext();
     ctx.ClientAssets.Attach(clientAsset, original_clientAsset);
     ctx.SubmitChanges();
 }