using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
using System.Collections;

public partial class _Default : System.Web.UI.Page
{
    public DataTable MyTable
    {
        get
        {
            if (Session["table"] == null)
            {
                Session["table"] = new DataTable();
            }

            return Session["table"] as DataTable;
        }
        set
        {
            Session["table"] = value;
        }
    }

    protected void grdNotes_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        if (MyTable.Rows.Count == 0)
        {
            MyTable.Columns.Add("UserCreated");
            MyTable.Columns.Add("Notes");
            MyTable.Columns.Add("DateCreated", typeof(DateTime));
            for (int i = 1; i < 8; i++)
            {
                MyTable.Rows.Add(i, "Notes" + i.ToString(), DateTime.Now.AddDays(i));
            }
        }
        grdNotes.DataSource = MyTable;
    }

    protected void grdNotes_InsertCommand(object sender, GridCommandEventArgs e)
    {
        GridEditableItem dataItem = e.Item as GridEditableItem;
        Hashtable values = new Hashtable();
        dataItem.ExtractValues(values);
        //ClaimUserNotes un = new ClaimUserNotes();
        //un.Claim_IDX = claimId;
        //un.Notes = values["Notes"].ToString();
        //un.UserCreated = user.UserName;

        //un.DateCreated = DateTime.Now;
        //entities.AddToClaimUserNotes(un);

        //entities.SaveChanges();

        //lstUserNotes = entities.ClaimUserNotes.Where(obj => obj.Claim_IDX == claimId).ToList();
        int user = Convert.ToInt32(MyTable.Rows[MyTable.Rows.Count - 1]["UserCreated"].ToString()) + 1;
        MyTable.Rows.Add(user, values["Notes"].ToString(), DateTime.Now);
        grdNotes.Rebind();
    }
}
