protected void btnSave_Click(object sender, EventArgs e)
        {
            using (DefaultConnectionEF db = new DefaultConnectionEF())
            {
                //create new foodlist in memory
                Foodlist food = new Foodlist();

                //check url
                if(!String.IsNullOrEmpty(Request.QueryString["FoodID"]))
                {
                    Int32 FoodID = Convert.ToInt32(Request.QueryString["FoodID"]);

                    food = (from f in db.Foodlists
                            where f.FoodID == FoodID
                            select f).FirstOrDefault();
                }
                //fill new properties of the new foodlist
                food.FoodType = txtFood.Text;
                food.FoodBrand = txtBrand.Text;
                food.Notes = txtNotes.Text;
                //save the new foodlist
                if (String.IsNullOrEmpty(Request.QueryString["FoodID"]))
                {
                    db.Foodlists.Add(food);
                }
                db.Foodlists.Add(food);
                db.SaveChanges();

                //redirect to foodlist page
                Response.Redirect("foodlist.aspx");
            }
            
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (DefaultConnectionEF db = new DefaultConnectionEF())
            {
                //create new goals log in memory
                Goallog goal = new Goallog();

                //check url
                if (!String.IsNullOrEmpty(Request.QueryString["GoalID"]))
                {
                    Int32 GoalID = Convert.ToInt32(Request.QueryString["GoalID"]);

                    goal = (from g in db.Goallogs
                            where g.GoalID == GoalID
                            select g).FirstOrDefault();
                }
                //fill new properties of the new goals log
                goal.GoalName = txtGoals.Text;
                goal.Description = txtDescription.Text;
                goal.GoalTime = Convert.ToInt32(txtGoaltime.Text);

                //save the new goals log
                if (String.IsNullOrEmpty(Request.QueryString["GoalID"]))
                {
                    db.Goallogs.Add(goal);
                }
                db.Goallogs.Add(goal);
                db.SaveChanges();

                //redirect to foodlist page
                Response.Redirect("goals.aspx");
            }
            
        }
示例#3
0
        protected void grdExerciselog_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Int32 ExerciseID = Convert.ToInt32(grdExerciselog.DataKeys[e.RowIndex].Values["ExerciseID"].ToString());

            using (DefaultConnectionEF db = new DefaultConnectionEF())
            {
                Exerciselog objR = (from r in db.Exerciselogs
                                    where r.ExerciseID == ExerciseID
                                    select r).FirstOrDefault();

                db.Exerciselogs.Remove(objR);
                db.SaveChanges();
            }

            //reload exercise table
            GetExercise();
        }
示例#4
0
        protected void grdGoals_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            Int32 GoalID = Convert.ToInt32(grdGoals.DataKeys[e.RowIndex].Values["GoalID"].ToString());

            using (DefaultConnectionEF db = new DefaultConnectionEF())
            {
                Goallog objG = (from g in db.Goallogs
                                where g.GoalID == GoalID
                                select g).FirstOrDefault();

                db.Goallogs.Remove(objG);
                db.SaveChanges();
            }

            //reload exercise table
            GetGoals();
        }
示例#5
0
        protected void grdFoodlog_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //get the ID that will be deletin
            Int32 LogID = Convert.ToInt32(grdFoodlog.DataKeys[e.RowIndex].Values["LogID"].ToString());

            //look into db the same ID to be deleted
            using (DefaultConnectionEF db = new DefaultConnectionEF())
            {
                Foodlog objF = (from f in db.Foodlogs
                                 where f.LogID == LogID
                                 select f).FirstOrDefault();

                db.Foodlogs.Remove(objF);
                db.SaveChanges();
            }

            //Reload the new foodlist table
            GetFoodlog();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect to SQL Server
            using (DefaultConnectionEF db = new DefaultConnectionEF())
            {
                //create a new exercise and fill properties
                Exerciselog objE = new Exerciselog();

                objE.ExerciseType = txtExercise.Text;
                objE.Duration = Convert.ToInt32(txtDuration.Text);
                objE.CaloriesBurn = Convert.ToInt32(txtCaloriesburn.Text);
                objE.DayID = Convert.ToInt32(ddlDays.SelectedValue);

                //save
                db.Exerciselogs.Add(objE);
                db.SaveChanges();

                //redirect
                Response.Redirect("exercise.aspx");

            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //connect
            using (DefaultConnectionEF db = new DefaultConnectionEF())
            {
                //create a new food log and fill the properties
                Foodlog objC = new Foodlog();

                objC.FoodName = txtFoodname.Text;
                objC.Calories = Convert.ToInt32(txtCalCount.Text);
                objC.FoodID = Convert.ToInt32(ddlFoodtype.SelectedValue);
                objC.DayID = Convert.ToInt32(ddlDay.SelectedValue);

                //save
                db.Foodlogs.Add(objC);
                db.SaveChanges();

                //redirect
                Response.Redirect("/foodlog.aspx");
            }
        }