// GET: Create public ActionResult Create() { var model = new WrestlerCreate(); var promotionList = new PromotionRepo(); model.Promotions = promotionList.GetPromotions(); return(View(model)); }
public bool CreateWrestler(WrestlerCreate model) { var entity = new Wrestler() { OwnerId = _userId, RingName = model.RingName, Gender = model.Gender, DateOfBirth = model.DateOfBirth, Nationality = model.Nationality, PromotionId = model.PromotionId, Wins = model.Wins, Losses = model.Losses, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Wrestlers.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(WrestlerCreate model) { if (!ModelState.IsValid) { var promotionList = new PromotionRepo(); model.Promotions = promotionList.GetPromotions(); return(View(model)); } var service = CreateWrestlerService(); if (service.CreateWrestler(model)) { TempData["SaveResult"] = "Your wrestler has been created!"; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Wrestler could not be created."); return(View(model)); }