public ActionResult Index(int page = 0) { int start = (page > 0) ? (page - 1) * perpage : 0; using (var ctx = new Context()) { var query = ctx.Record // .Where(x => Npgsql.NpgsqlTypeFunctions.Cast(x.Title, "text").ToLower().Contains("jinja".ToLower())) .OrderBy(x => x.Title) // klo mau limit, dahulukan orderby -> offset -> limit .Skip(start) // offset .Take(perpage) // limit .ToList(); var total = ctx.Record.Count(); var data = new ArtikelViewModel(); // Untuk menampung data yg akan di parsing ke view data.Record.AddRange(query); data.page = page; data.totalPage = total / perpage; data.totalRow = total; data.title = "Daftar Artikel"; return(View(data)); } }
public ActionResult Cari(string filter = "wahyuni", int page = 0) { int start = (page > 0) ? (page - 1) * perpage : 0; using (var ctx = new Context()) { var query = ctx.Record .Where(x => Npgsql.NpgsqlTypeFunctions.Cast(x.Author, "text").ToLower().Contains(filter.ToLower())) .OrderBy(x => x.Title) // klo mau limit, dahulukan orderby -> offset -> limit .Skip(start) // offset .Take(perpage) // limit .ToList(); var total = ctx.Record.Where(x => Npgsql.NpgsqlTypeFunctions.Cast(x.Author, "text").ToLower().Contains(filter.ToLower())).Count(); var data = new ArtikelViewModel(); // Untuk menampung data yg akan di parsing ke view data.Record.AddRange(query); data.page = page; data.totalPage = total / perpage; data.totalRow = total; data.title = "Hasil Pencarian Artikel dengan keyword : " + filter + "."; data.message = "Keyword masih diketik lewat URL (method GET belum POST) contoh localhos:port/tArtikel/Cari/nama. Hehe jek belajaran"; data.keyword = filter; return(View(data)); } }
public IActionResult AddNew([FromBody] ArtikelViewModel newArticle) { var command = new ArtikelNeuanlageCommand() { Artikelnummer = newArticle.ArtikelNummer, Artikelbezeichnung = newArticle.Bezeichnung, }; if (newArticle.Kategorien != null) { command.Kategorien = newArticle.Kategorien.Select(k => k.Name).ToArray(); } try { _handler.Handle(command); } catch (ArtikelException ex) { return(BadRequest(ex.Message)); } catch (Exception) { return(new StatusCodeResult(500)); } return(Ok()); }
public IActionResult Edit(int id, [Bind("ArtikelID,CategorieID,Naam")] Artikel artikel) { if (id != artikel.ArtikelID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(artikel); _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ArtikelExists(artikel.ArtikelID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ArtikelViewModel avm = new ArtikelViewModel(); avm.artikel = artikel; avm.categorie = _context.Categorie.ToList <Categorie>(); return(View(avm)); }
// GET: Artikels/Create public IActionResult Create() { ArtikelViewModel avm = new ArtikelViewModel(); avm.categorie = _context.Categorie.ToList <Categorie>(); //ViewData["CategorieID"] = new SelectList(_context.Categorie, "CategorieID", "CategorieID"); return(View(avm)); }
public IActionResult Create(ArtikelViewModel avm) { if (ModelState.IsValid) { _context.Artikel.Add(avm.artikel); _context.SaveChanges(); return(RedirectToAction("Index")); } //ArtikelViewModel avm = new ArtikelViewModel(); avm.categorie = _context.Categorie.ToList <Categorie>(); return(View(avm)); }
// GET: Artikels/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var artikel = await _context.Artikel.SingleOrDefaultAsync(m => m.ArtikelID == id); if (artikel == null) { return(NotFound()); } ArtikelViewModel avm = new ArtikelViewModel(); avm.artikel = artikel; avm.categorie = _context.Categorie.ToList <Categorie>(); return(View(avm)); }