示例#1
0
        public bool CreateGoalItem(GoalItemCreate model)
        {
            var entity =
                new GoalItem()
            {
                UserID           = _userID,
                GoalItemName     = model.GoalItemName,
                GoalItemPrice    = model.GoalItemPrice,
                GoalItemLocation = model.GoalItemLocation,
                CreatedUTC       = DateTimeOffset.Now
            };

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

            var service = CreateGoalItemService();

            if (service.CreateGoalItem(model))
            {
                TempData["SaveResult"] = "Your goal  purchase was saved.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Goal purchase could not be saved.");

            return(View(model));
        }