示例#1
0
        // CreateThing
        public bool CreateThing(ThingCreate model)
        {
            var entity = new Thing()
            {
                OwnerId      = _userId,
                Heading      = model.Heading,
                TimeAllotted = model.TimeAllotted,
                CatagoryId   = model.CatagoryId,
                CreatedUtc   = DateTime.UtcNow,
            };

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

            if (service.CreateThing(model))
            {
                TempData["SaveResult"] = " You added a Thing.";
                return(RedirectToAction("Index"));
            }
            ;
            ModelState.AddModelError("", "Thing could not be added.");
            return(View(model));
        }