Example #1
0
        protected void AddBtn_Click(object sender, EventArgs e)
        {
            var usr = (User)Session["LoggedInUser"];

            if (TypeDropDn.SelectedIndex == 0)
            {
                TypeDropDn.Focus();
                return;
            }
            using (var ctx = new BudgetContext())
            {
                ctx.Users.Attach(usr);
                Alarm neo = new Alarm
                {
                    Active    = true,
                    AlarmType = (AlarmType)Enum.Parse(typeof(AlarmType), TypeDropDn.Text),
                    Amount    = float.Parse(AmntTxt.Text),
                    Message   = MsgTxt.Text,
                    Tag       = ctx.ExpenseTags.Find(TagDropDn.Text)
                };
                usr.Alarms.Add(neo);
                ctx.SaveChanges();
                ctx.Entry(usr).State = System.Data.Entity.EntityState.Detached;
            }
            AmntTxt.Text            = MsgTxt.Text = "";
            TagDropDn.SelectedIndex = 0;
            GridView1.DataBind();
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var usr = (User)Session["LoggedInUser"];

            if (usr == null)
            {
                Response.Redirect("~/Login.aspx");
            }
            else if (!IsPostBack)
            {
                TypeDropDn.DataBind();
                TagDropDn.DataBind();
                TypeDropDn_SelectedIndexChanged(TypeDropDn, e);
                GridView1.DataBind();
            }
        }