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");
            }
            
        }
        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 GetDaylist()
        {
            try
            {
                //connect to db via EF
                using (DefaultConnectionEF db = new DefaultConnectionEF())
                {

                    //get day name in daylist
                    var Daylist = from d in db.Daylists
                              orderby d.Dayname
                              select d;

                    //bind the dropdown list
                    ddlDays.DataSource = Daylist.ToList();
                    ddlDays.DataBind();

                    //add a default option to the dropdown after we fill it
                    ListItem DefaultTime = new ListItem("-Select-", "0");
                    ddlDays.Items.Insert(0, DefaultTime);
                }
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine("Cannot load data. " + e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error passing data. " + e.InnerException.Message);
            }
            
        }
        protected void GetFood()
        {
            try
            {
                using (DefaultConnectionEF db = new DefaultConnectionEF())
                {
                    Int32 FoodID = Convert.ToInt32(Request.QueryString["FoodID"]);

                    //look up foodlist
                    Foodlist food = (from f in db.Foodlists
                                 where f.FoodID == FoodID
                                 select f).FirstOrDefault();

                    //pre-populate the form fields
                    txtFood.Text = food.FoodType;
                    txtBrand.Text = food.FoodBrand;
                    txtNotes.Text = food.Notes;
                
                }
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine("Cannot load data. " + e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error passing data. " + e.InnerException.Message);
            }
            
        }
Esempio n. 5
0
        protected void GetFoodlog()
        {
            try
            {
                using (DefaultConnectionEF db = new DefaultConnectionEF())
                {
                    var Foodlog = (from f in db.Foodlogs
                                   select new { f.LogID, f.FoodName, f.Daylist.Dayname, f.Calories, f.Foodlist.FoodType });

                    //append the current direction to the Sort Column
                    String Sort = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                    grdFoodlog.DataSource = Foodlog.AsQueryable().OrderBy(Sort).ToList();
                    grdFoodlog.DataBind();
                }
            }
            catch (NullReferenceException e)
            {
                Trace.Write("An error occured during update operation with Message: ", e.Message);
                Trace.Write("Stack Trace: ", e.StackTrace);
            }
            catch (Exception e)
            {
                Trace.Write("Database unavailable with Message: ", e.Message);
                Trace.Write("Stack Trace: ", e.StackTrace);

            }
        }
Esempio n. 6
0
        protected void GetExercise()
        {
            
            try
            {
                using (DefaultConnectionEF db = new DefaultConnectionEF())
                {
                    var Exercise = (from r in db.Exerciselogs
                                    select new { r.ExerciseID, r.ExerciseType, r.Duration, r.CaloriesBurn, r.Daylist.Dayname });

                    //append the current direction to the Sort Column
                    String Sort = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                    grdExerciselog.DataSource = Exercise.AsQueryable().OrderBy(Sort).ToList();
                    grdExerciselog.DataBind();
                }
            }
            catch (NullReferenceException e)
            {
                Trace.Write("An error occured during update operation with Message: ", e.Message);
                Trace.Write("Stack Trace: ", e.StackTrace);

            }
            catch (Exception e)
            {
                Trace.Write("Database unavailable with Message: ", e.Message);
                Trace.Write("Stack Trace: ", e.StackTrace);

            }
        }
        protected void GetFoodtype()
        {
            try
            {
                using (DefaultConnectionEF db = new DefaultConnectionEF())
                {
                    //Get selected day list
                    var Foodlist = from d in db.Foodlists
                                   orderby d.FoodID
                                   select d;

                    //bind to the dropdown list
                    ddlFoodtype.DataSource = Foodlist.ToList();
                    ddlFoodtype.DataBind();

                    //add default option to the dropdown after we fill it
                    ListItem DefaultItem = new ListItem("-Select-", "0");
                    ddlFoodtype.Items.Insert(0, DefaultItem);

                }
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine("Cannot load data. " + e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error passing data. " + e.InnerException.Message);
            }
        }
Esempio n. 8
0
        protected void GetGoals()
        {
            try
            {
                using (DefaultConnectionEF db = new DefaultConnectionEF())
                {
                    var Goals = (from g in db.Goallogs
                                 select new { g.GoalID, g.GoalName, g.Description, g.GoalTime });

                    //append the current direction to the Sort Column
                    String Sort = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                    grdGoals.DataSource = Goals.AsQueryable().OrderBy(Sort).ToList();
                    grdGoals.DataBind();

                }
            }
            catch (NullReferenceException e)
            {
                Trace.Write("An error occured during update operation with Message: ", e.Message);
                Trace.Write("Stack Trace: ", e.StackTrace);

            }
            catch (Exception e)
            {
                Trace.Write("Database unavailable with Message: ", e.Message);
                Trace.Write("Stack Trace: ", e.StackTrace);

            }
        }
Esempio n. 9
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();
        }
Esempio n. 10
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();
        }
Esempio n. 11
0
        protected void GetGoals()
        {
            using (DefaultConnectionEF db = new DefaultConnectionEF())
            {
                Int32 GoalID = Convert.ToInt32(Request.QueryString["GoalID"]);

                //look up foodlist
                Goallog goal = (from g in db.Goallogs
                                 where g.GoalID == GoalID
                                 select g).FirstOrDefault();

                //pre-populate the form fields
                txtGoals.Text = goal.GoalName;
                txtDescription.Text = goal.Description;
                txtGoaltime.Text = goal.GoalTime.ToString();

            }
        }
        protected void GetExercise()
        {
            using (DefaultConnectionEF db = new DefaultConnectionEF())
            {
                Int32 ExerciseID = Convert.ToInt32(Request.QueryString["ExerciseID"]);

                //look up foodlist
                Exerciselog exercise = (from r in db.Exerciselogs
                                        where r.ExerciseID == ExerciseID
                                        select r).FirstOrDefault();

                //pre-populate the form fields
                txtExercise.Text = exercise.ExerciseType;
                txtDuration.Text = exercise.Duration.ToString();
                txtCaloriesburn.Text = exercise.CaloriesBurn.ToString();
                ddlDays.SelectedValue = exercise.DayID.ToString();
            }
        }
Esempio n. 13
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 GetLog()
        {
            using (DefaultConnectionEF db = new DefaultConnectionEF())
            {
                Int32 LogID = Convert.ToInt32(Request.QueryString["LogID"]);

                //look up foodlist
                Foodlog log = (from l in db.Foodlogs 
                                where l.LogID == LogID
                                select l).FirstOrDefault();

                //pre-populate the form fields
                txtFoodname.Text = log.FoodName;
                ddlDay.SelectedValue = log.DayID.ToString();
                txtCalCount.Text = log.Calories.ToString();
                ddlFoodtype.SelectedValue = log.FoodID.ToString();
            }
        }
        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");
            }
        }