public async Task <IActionResult> Create(Pagesa pagesa) { try { if (ModelState.IsValid) { pagesa.Active = true; pagesa.DataEPageses = DateTime.Now; switch (pagesa.Shuma) { case 5: pagesa.DataESkadimit = DateTime.Now.AddMonths(1); break; case 10: pagesa.DataESkadimit = DateTime.Now.AddMonths(3); break; case 15: pagesa.DataESkadimit = DateTime.Now.AddMonths(6); break; } _context.Add(pagesa); Klienti klienti = _context.Klienti.Where(k => k.id == pagesa.Klienti_id).First(); klienti.Aktiv = true; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } }catch (DbUpdateException ex) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(pagesa)); }
public async Task <IActionResult> Create( [Bind("Emri,Email,NumriTel,Aktiv")] Klienti k) { try { if (ModelState.IsValid) { k.created_at = DateTime.Now; _context.Add(k); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(k)); }
public async Task <IActionResult> Create( [Bind("Titulli,Autori")] Libra libra) { try { if (ModelState.IsValid) { libra.E_Lire = true; _context.Add(libra); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(libra)); }