public ActionResult ActiveWeekPlanExists() { if (User == null) { return(Content("0")); } int id = 0; //Get week int week = WeekOfYearISO8601(DateTime.Now); RecipeRepository repo = new RecipeRepository(ConnectionString); WeekPlan weekPlan = repo.GetActiveWeekPlan(User.Id); if (weekPlan == null) { //create a new one weekPlan = new WeekPlan { Name = week + "", UserId = User.Id, Week = week, CreatedAt = DateTime.Now.ToShortDateString(), Active = true }; repo.InsertWeekPlan(weekPlan); weekPlan = repo.GetActiveWeekPlan(User.Id); } return(Content(weekPlan.Id + "")); }