コード例 #1
0
ファイル: CatService.cs プロジェクト: jonphilk/PeaceOfMind
        public bool CreateCat(CatCreate model)
        {
            var entity =
                new Cat()
            {
                Name     = model.Name,
                ClientId = model.ClientId,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Cats.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cat"></param>
        /// <returns></returns>
        public IHttpActionResult Post(CatCreate cat)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateCatServices();

            if (!service.CreateCat(cat))
            {
                return(InternalServerError());
            }

            return(Ok($"{cat.Name} has been posted to Bootz & Catz! ฅ^•ﻌ•^ฅ"));
        }
コード例 #3
0
        public ActionResult Create(CatCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = new CatService();

            if (service.CreateCat(model))
            {
                TempData["SaveResult"] = "Your cat was added.";
                return(RedirectToAction("Index"));
            }
            ;
            ModelState.AddModelError("", "Cat could not be added.");
            return(View(model));
        }
コード例 #4
0
ファイル: CatService.cs プロジェクト: mckinneydmatt/PetPickr
        public bool CreateCat(CatCreate model)
        {
            var entity = new Cat()
            {
                CatName   = model.CatName,
                CatSex    = model.CatSex,
                CatWeight = model.CatWeight,
                CatAge    = model.CatAge,
                CatPrice  = model.CatPrice,
                ShelterId = model.ShelterId,
                CatImage  = model.CatImage,
            };


            using (var ctx = new ApplicationDbContext())
            {
                ctx.Cats.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #5
0
        //create cat
        public bool CreateCat(CatCreate model)
        {
            var entity =
                new Cat()
            {
                ShelterId  = model.ShelterId,
                IsDeclawed = model.IsDeclawed,
                IsFat      = model.IsFat,
                Name       = model.Name,
                Breed      = model.Breed,
                Age        = model.Age,
                AboutMe    = model.AboutMe
            };

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