protected void Save(object sender, EventArgs e) { try { memberId = Convert.ToInt32(Session["MID"]); } catch { return; } MemberExercisePlan myPlan; if (Session["MPID"] != null) { int mPlanId = Convert.ToInt32(Session["MPID"]); myPlan = dbAccess.GetMemberExercisePlan(mPlanId); } else { myPlan = dbAccess.GetCurrentMemberPlanOrStartingPlan(memberId); } int weekNum = int.Parse(ddlWeek.SelectedValue); int myPlanId = myPlan.Id; using (DIYPTEntities db = new DIYPTEntities()) { db.Database.Connection.Open(); { int id = Convert.ToInt32(Session["MID"]); var foodplanweek = dbAccess.GetMemberFoodPlanWeek(memberId, myPlanId, weekNum, false); if (foodplanweek == null) { MemberFoodPlanWeek MemFoodPW = new MemberFoodPlanWeek(); MemFoodPW.MemberId = id; MemFoodPW.MemberExercisePlanId = myPlanId; MemFoodPW.Food1 = tbFood1.Text; MemFoodPW.Food2 = tbFood2.Text; MemFoodPW.Food3 = tbFood3.Text; MemFoodPW.Food4 = tbFood4.Text; MemFoodPW.Food5 = tbFood5.Text + ";" + tbFood6.Text + ";" + tbFood7.Text; MemFoodPW.StartWeek = weekNum; MemFoodPW.EndWeek = MemFoodPW.StartWeek; db.MemberFoodPlanWeeks.Add(MemFoodPW); } else { var updatePlan = (from c in db.MemberFoodPlanWeeks where c.Id == foodplanweek.Id select c).FirstOrDefault(); updatePlan.Food1 = tbFood1.Text; updatePlan.Food2 = tbFood2.Text; updatePlan.Food3 = tbFood3.Text; updatePlan.Food4 = tbFood4.Text; updatePlan.Food5 = tbFood5.Text + ";" + tbFood6.Text + ";" + tbFood7.Text; } db.SaveChanges(); } } }
public MemberFoodPlanWeek GetMemberFoodPlanWeek(int iMemberId, int iMemberPlanId, int iWeek, bool subWithAll = true) { MemberFoodPlanWeek myFoodPlanWeek = (from c in db.MemberFoodPlanWeeks where c.MemberExercisePlanId == iMemberPlanId && c.StartWeek <= iWeek && c.EndWeek >= iWeek select c).FirstOrDefault(); if (myFoodPlanWeek == null && subWithAll) { myFoodPlanWeek = (from c in db.MemberFoodPlanWeeks where c.MemberId == iMemberId && c.StartWeek == -1 && c.MemberExercisePlanId == iMemberPlanId select c).FirstOrDefault(); } return(myFoodPlanWeek); }
protected void Page_Load(object sender, EventArgs e) { int memberId = PrizeMemberAuthUtils.GetMemberID(); var exercisePlan = dbAccess.GetCurrentMemberPlanOrStartingPlan(memberId); if (exercisePlan == null) { PrizeMember member = PrizeMemberAuthUtils.GetMemberData(memberId); PrizeMemberPlanManager planMan = new PrizeMemberPlanManager(); Response.Redirect(planMan.GetEmptyPlanJumpURL(member)); } MemberExercisePlanWeek memberPlanWeek; if (Request["MemberPlanWeekID"] != null) { int memberPlanWeekId; int.TryParse(Request["MemberPlanWeekID"], out memberPlanWeekId); memberPlanWeek = dbAccess.GetMemberPlanWeekById(memberPlanWeekId); } else { memberPlanWeek = dbAccess.GetCurrentMemberPlanWeek(memberId); } if (memberPlanWeek == null) { divMealPlanContent.Visible = false; divNotStarted.Visible = true; return; } int iWeekNum = memberPlanWeek.Week; lblWeekNum.Text = "Week " + iWeekNum; divMainMealPlan.Attributes.Add("class", "tab-inner-content nodisplay wk" + iWeekNum); lblDateDuration.Text = PrizeCommonUtils.ParseDateToEnglish(memberPlanWeek.StartDate) + " - " + PrizeCommonUtils.ParseDateToEnglish(memberPlanWeek.EndDate); MemberExercisePlan memberPlan = dbAccess.GetCurrentMemberPlan(memberId); if (memberPlan == null) { return; } PrizeExercisePlan plan = dbAccess.GetExercisePlan(memberPlan.ExercisePlanId); if (plan == null) { return; } lblPlanProgram.Text = plan.PrizePlanProgram.Name; MemberExercisePlanWeek prevWeek = dbAccess.GetMemberPlanWeekByMemberPlanAndWeek(memberPlan.Id, memberPlanWeek.Week - 1); if (prevWeek != null) { int prevWeekNum = iWeekNum - 1; weekPre.NavigateUrl = "/my-account/meal-plan?MemberPlanWeekID=" + prevWeek.Id; weekPre.Text = "Week " + (memberPlanWeek.Week - 1); } else { weekPre.Attributes.Add("class", "no-arrow"); } MemberExercisePlanWeek nextWeek = dbAccess.GetMemberPlanWeekByMemberPlanAndWeek(memberPlan.Id, memberPlanWeek.Week + 1); if (nextWeek != null) { weekNext.NavigateUrl = "/my-account/meal-plan?MemberPlanWeekID=" + nextWeek.Id; weekNext.Text = "Week " + (memberPlanWeek.Week + 1); } else { weekNext.Attributes.Add("class", "no-arrow"); } MemberFoodPlanWeek foodWeek = dbAccess.GetMemberFoodPlanWeek(memberId, memberPlanWeek.MemberExercisePlanId, memberPlanWeek.Week); if (foodWeek == null) { return; } if (foodWeek.Food1 == null || foodWeek.Food1.Equals("")) { this.colories.Visible = false; } else { lblFood1.Text = foodWeek.Food1; } if (foodWeek.Food2 == null || foodWeek.Food2.Equals("")) { this.protein.Visible = false; } else { lblFood2.Text = foodWeek.Food2; } if (foodWeek.Food3 == null || foodWeek.Food3.Equals("")) { this.carbo.Visible = false; } else { lblFood3.Text = foodWeek.Food3; } if (foodWeek.Food4 == null || foodWeek.Food4.Equals("")) { this.fats.Visible = false; } else { lblFood4.Text = foodWeek.Food4; } if (foodWeek.Food5 != null) { string[] sPersentage = foodWeek.Food5.Split(';'); if (sPersentage.Length > 0) { lblFood5.Text = sPersentage[0]; if (sPersentage.Length > 1) { lblFood6.Text = sPersentage[1]; if (sPersentage.Length > 2) { lblFood7.Text = sPersentage[2]; } } } } }