Esempio n. 1
0
 public ActionResult Create(GunCreate model)
 {
     if (ModelState.IsValid)
     {
     }
     return(View(model));
 }
        public bool CreateGun(GunCreate model)
        {
            var entity =
                new Gun()
            {
                OwnerId     = _userId,
                Name        = model.Name,
                Description = model.Description,
                IsPrimary   = model.IsPrimary,
                CreatedUtc  = DateTimeOffset.Now
            };

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

            var service = CreateGunService();

            if (service.CreateGun(model))
            {
                return(RedirectToAction("Index"));
            }
            ;

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

            return(View(model));
        }