示例#1
0
        //CREATE A MEALPLAN
        public bool CreateMealPlan(MealPlanCreate model)
        {
            var entity =
                new MealPlan()
            {
                Title          = model.Title,
                DateCreatedUtc = DateTimeOffset.Now,
                Length         = model.Length,
                OwnerId        = _userId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.MealPlans.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#2
0
        public ActionResult Create(MealPlanCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            MealPlanService service = CreateMealPlanService();

            if (service.CreateMealPlan(model))
            {
                TempData["SaveResult"] = "Your Meal Plan was created.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Meal Plan unable to be created.");
            return(View(model));
        }