コード例 #1
0
        public bool CreateSection(SectionCreate model)
        {
            var entity =
                new Section()
            {
                CreatorID = _userId,
                Title     = model.Title,
            };

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

            var service = CreateSectionService();

            if (service.CreateSection(model))
            {
                TempData["ResultSaved"] = "Your section was created.";
                return(RedirectToAction("Index"));
            }
            ;

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

            return(View(model));
        }