protected void btnAddToPlan_Click(object sender, EventArgs e) { DateTime date = DateTime.Now; try { date = DateTime.Parse(datepicker.Value); } catch (Exception ex) { if (Session["error"] != null) { Session.Remove("error"); } Session.Add("error", "Invalid Date."); return; } MealPlan meal = new MealPlan(); meal.UserID = mUser.ID; meal.PlanDate = date.ToString("MM/dd/yyyy"); meal.RecipeID = mRecipe.ID; meal.Save(); lblAlert.Visible = true; lblAlert.Text = $"Recipe added successfully for {date.ToString("MM/dd/yyyy")}"; }
private void MealPlanCreateTest() { MealPlan meal = new MealPlan(); meal.UserID = -1; meal.RecipeID = -1; meal.PlanDate = "01/01/2016"; meal.Save(); MealPlan savedmeal = MealPlan.Get(-1, -1, meal.PlanDate); if (savedmeal == null) { testFailed("MealPlanCreateTest"); return; } else if (savedmeal.UserID.Equals(meal.UserID) && savedmeal.RecipeID.Equals(meal.RecipeID) && savedmeal.PlanDate.Equals(meal.PlanDate)) { testPassed("MealPlanCreateTest"); } else { testFailed("MealPlanCreateTest"); } savedmeal.Delete(); }