Beispiel #1
0
    public bool CreateGhost(GhostCreate model)
    {
        var entity =
            new Ghostt()
        {
            OwnerId    = _userId,
            Title      = model.Title,
            Content    = model.Content,
            CreatedUtc = DateTimeOffset.Now
        };

        using (var ctx = new ApplicationDbContext())
        {
            ctx.Ghosts.Add(entity);
            return(ctx.SaveChanges() == 1);
        }
    }
        public ActionResult Create(GhostCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateGhostService();

            if (service.CreateGhost(model))
            {
                TempData["SaveResult"] = "Your ghost encounter was created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Ghost encounter could not be created.");

            return(View(model));
        }