public async Task <IActionResult> Create([Bind("Id,Title,Description,PostedOn")] NewsModel newsModel) { if (ModelState.IsValid) { _context.Add(newsModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(newsModel)); }
public async Task <IActionResult> Create([Bind("ID,Name,Price")] ProductModel productModel) { if (ModelState.IsValid) { _context.Add(productModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(productModel)); }
public async Task <IActionResult> Create([Bind("Id,Category,Name,Description,Price")] MenuModel menuModel) { if (ModelState.IsValid) { _context.Add(menuModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(menuModel)); }
public IActionResult Add(int id, [FromForm] ConsultationModel consult) { consult.CustomerID = id; if (ModelState.IsValid) { Context.Add <ConsultationModel>(consult); Context.SaveChanges(); return(RedirectToAction("Index", new { id })); } return(View(consult)); }
public void AddPost(PostModel postModel) { _context.Add(postModel); try { _context.SaveChanges(); } catch (DbUpdateException) { if (postModel.Id != default(int)) { postModel.Id = default(int); _context.SaveChanges(); } } }