Exemple #1
0
        public IActionResult Add(CatCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            this.catService.Create(model);

            return(this.RedirectToAction("Index"));
        }
        public IActionResult Create(CatCreateInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            Cat cat = new Cat(model.Name, model.Age, model.Breed, model.ImageUrl);

            service.Add(cat);
            return(this.RedirectToAction("Index", "Home"));
        }
Exemple #3
0
        public void Create(CatCreateInputModel cat)
        {
            var dbCat = new Cat
            {
                Name     = cat.Name,
                Age      = cat.Age,
                Breed    = cat.Breed,
                ImageUrl = cat.ImageUrl
            };

            this.dbContext.Cats.Add(dbCat);
            this.dbContext.SaveChanges();
        }