コード例 #1
0
        public bool CreateSighting(SightingCreate model)
        {
            var entity =
                new Sighting()
            {
                TimeSeen = model.TimeSeen
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Sightings.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #2
0
        public ActionResult Create(SightingCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateSightingService();

            if (service.CreateSighting(model))
            {
                TempData["SaveResult"] = "The sighting was added!";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "The sighting could not be added.");

            return(View(model));
        }