Ejemplo n.º 1
0
        protected void grdActivities_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                using (DefaultConnectionAL conn = new DefaultConnectionAL())
                {
                    var user = HttpContext.Current.GetOwinContext().Authentication.User.Identity.GetUserId();

                    Int32 ActivityID = Convert.ToInt32(grdActivities.DataKeys[e.RowIndex].Values["id"]);

                    var activityItem = (from a in conn.activities
                             where a.id == ActivityID
                             select a).FirstOrDefault();
                    //save
                    conn.activities.Remove(activityItem);
                    conn.SaveChanges();

                    //redirect to updated departments page
                    GetActivities();
                }
            }
            catch (Exception e2)
            {
                Response.Redirect("~/error.aspx");
            }
        }
Ejemplo n.º 2
0
        protected void GetActivities()
        {
            try
            {
                using (DefaultConnectionAL conn = new DefaultConnectionAL())
                {
                    var user = HttpContext.Current.GetOwinContext().Authentication.User.Identity.GetUserId();
                    //use link to query the Departments model
                    var activityItems = (from a in conn.activities
                            where a.account_id == user
                            select new { a.id, a.activity_name, a.duration }
                    );

                    //bind the query result to the gridview
                    //String sort = Session["SortColumn"] + " " + Session["SortDirection"].ToString();
                    //grdActivities.DataSource = activity.AsQueryable().OrderBy(sort).ToList();
                    grdActivities.DataSource = activityItems.ToList();
                    grdActivities.DataBind();
                }
            }
            catch (Exception e1)
            {
                Response.Redirect("/error.aspx");
            }
        }
        protected void btnLog_Click(object sender, EventArgs e)
        {
            try
            {
                //connect
                using (DefaultConnectionAL conn = new DefaultConnectionAL())
                {
                    activity objA = new activity();

                    if (!String.IsNullOrEmpty(Request.QueryString["ActivityID"]))
                    {
                        int ActivityID = Convert.ToInt32(Request.QueryString["ActivityID"]);
                        objA = (from a in conn.activities
                                where a.id == ActivityID
                                select a).FirstOrDefault();

                        //Populate the activity from the input form
                        objA.activity_name = txtActivityName.Text;
                    }
                    else
                    {
                        //Populate the activity from the input form
                        objA.account_id = HttpContext.Current.GetOwinContext().Authentication.User.Identity.GetUserId();
                        objA.activity_name = txtActivityName.Text;
                        objA.duration = lblTimeHidden.Text;
                    }

                    if (String.IsNullOrEmpty(Request.QueryString["ActivityID"]))
                    {
                        //add
                        conn.activities.Add(objA);
                    }

                    conn.SaveChanges();
                    Response.Redirect("activitylog.aspx");
                }
            }
            catch (System.IO.IOException e3)
            {
                Server.Transfer("/error.aspx", true);
            }
        }
Ejemplo n.º 4
0
        protected void GetName()
        {
            try
            {
                using (DefaultConnectionAL conn = new DefaultConnectionAL())
                {
                    var user = HttpContext.Current.GetOwinContext().Authentication.User.Identity.GetUserId();

                    var name = (from n in conn.AspNetUsers
                                    where n.Id == user
                                    select n).FirstOrDefault();

                    lblName.Visible = true;
                    lblName.Text = "Hey " + name.UserName + "! Thanks for using Activity Logger! Start your active lifestyle by recording an activity now!";
                }
            }
            catch (Exception e)
            {
                Response.Redirect("~/error.aspx");
            }
        }
        protected void GetActivity()
        {
            activity objA = new activity();

            try
            {
                using (DefaultConnectionAL conn = new DefaultConnectionAL())
                {
                    Int32 ActivityID = Convert.ToInt32(Request.QueryString["ActivityID"]);
                    objA = (from a in conn.activities
                            where a.id == ActivityID
                            select a).FirstOrDefault();

                    txtActivityName.Text = objA.activity_name;
                    pnlTiming.Visible = false;
                    btnLog.Text = "Update";
                }
            }
            catch (Exception e2)
            {
                Response.Redirect("~/error.aspx");
            }
        }