コード例 #1
0
        public ActionResult Create(CigarCreate model)
        {
            var service = CreateCigarService();

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


            ModelState.AddModelError("", "Cigar could not be created");
            return(View(model));
        }
コード例 #2
0
        public bool CreateCigar(CigarCreate model)
        {
            var entity =
                new Cigar
            {
                CigarName   = model.CigarName,
                MakerId     = model.MakerId,
                CigarTypeId = model.CigarTypeId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Cigars.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }