public bool CreateGift(GiftCreate model) { var entity = new Gift() { GiftName = model.GiftName, GiftDescription = model.GiftDescription, RegistryEventId = model.RegistryEventId, //RegistryEvent = model.RegistryEvent }; using (var ctx = new ApplicationDbContext()) { ctx.Gifts.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateGift(GiftCreate model) { var entity = new Gift() { OwnerID = _userID, Description = model.Description, BoughtGift = model.BoughtGift, Person = model.Person, PersonID = model.PersonID, }; using (var ctx = new ApplicationDbContext()) { ctx.Gifts.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(GiftCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateGiftService(); if (service.CreateGift(model)) { // Use TempData rather than ViewBag. TempData removes information after it's accessed TempData["SaveResult"] = "Your Event was created."; return(RedirectToAction("Index", new { id = model.RegistryEventId })); } ModelState.AddModelError("", "Your Event could not be created."); return(View(model)); }
public ActionResult Create(GiftCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateGiftService(); if (service.CreateGift(model)) { TempData["SaveResult"] = "Gift was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "New Gift could not be created."); return(View(model)); }