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); } }
/// <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! ฅ^•ﻌ•^ฅ")); }
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)); }
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); } }
//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); } }