//add admin authentication here? //private readonly Guid _userId; //public PromptServices(Guid userId) //{ // _userId = userId; //} public bool CreatePrompt(PromptCreate model) { var entity = new PromptItem() { Category = model.Category, Prompt = model.Prompt }; using (var ctx = new ApplicationDbContext()) { ctx.PromptItems.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(PromptCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = new PromptServices(); if (service.CreatePrompt(model)) { TempData["SaveResult"] = "Your entry was created."; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Prompt could not be created."); return(View(model)); }