public IActionResult Delete(int id) { var artikl = ctx.Artikl.Find(); if (artikl != null) { try { string naziv = artikl.NazArtikla; ctx.Remove(artikl); ctx.SaveChanges(); var result = new { message = $"Artikl {naziv} sa šifrom {id} uspješno obrisan.", successful = true }; return(Json(result)); } catch (Exception exc) { var result = new { message = "Pogreška prilikom brisanja mjesta: " + exc.CompleteExceptionMessage(), successful = false }; return(Json(result)); } } else { return(NotFound($"Artikl sa šifrom {id} ne postoji")); } }
public async Task <IActionResult> Delete(int IdPartnera, int page = 1, int sort = 1, bool ascending = true) { var partner = await ctx.Partner .AsNoTracking() .Where(p => p.IdPartnera == IdPartnera) .SingleOrDefaultAsync(); if (partner != null) { try { ctx.Remove(partner); await ctx.SaveChangesAsync(); TempData[Constants.Message] = $"Partner {partner.IdPartnera} uspješno obrisan."; TempData[Constants.ErrorOccurred] = false; } catch (Exception exc) { TempData[Constants.Message] = "Pogreška prilikom brisanja partnera: " + exc.CompleteExceptionMessage(); TempData[Constants.ErrorOccurred] = true; } } else { TempData[Constants.Message] = "Ne postoji partner s id-om: " + IdPartnera; TempData[Constants.ErrorOccurred] = true; } return(RedirectToAction(nameof(Index), new { page = page, sort = sort, ascending = ascending })); }
public IActionResult Delete(string OznDrzave, int page = 1, int sort = 1, bool ascending = true) { var drzava = ctx.Drzava .AsNoTracking() .Where(d => d.OznDrzave == OznDrzave) .SingleOrDefault(); if (drzava != null) { try { string naziv = drzava.NazDrzave; ctx.Remove(drzava); ctx.SaveChanges(); TempData[Constants.Message] = $"Država {naziv} uspješno obrisana"; TempData[Constants.ErrorOccurred] = false; logger.LogInformation($"Država {naziv} uspješno obrisana"); } catch (Exception exc) { TempData[Constants.Message] = "Pogreška prilikom brisanja države: " + exc.CompleteExceptionMessage(); logger.LogError("Pogreška prilikom brisanja države: " + exc.CompleteExceptionMessage()); TempData[Constants.ErrorOccurred] = true; } } else { TempData[Constants.Message] = "Ne postoji država s oznakom: " + OznDrzave; TempData[Constants.ErrorOccurred] = true; } return(RedirectToAction(nameof(Index), new { page = page, sort = sort, ascending = ascending })); }
public async Task <IActionResult> Delete(int IdDokumenta, string filter, int page = 1, int sort = 1, bool ascending = true) { var dokument = await ctx.Dokument .AsNoTracking() .Where(d => d.IdDokumenta == IdDokumenta) .SingleOrDefaultAsync(); if (dokument != null) { try { ctx.Remove(dokument); await ctx.SaveChangesAsync(); TempData[Constants.Message] = $"Dokument {dokument.IdDokumenta} uspješno obrisan."; TempData[Constants.ErrorOccurred] = false; } catch (Exception exc) { TempData[Constants.Message] = "Pogreška prilikom brisanja dokumenta: " + exc.CompleteExceptionMessage(); TempData[Constants.ErrorOccurred] = true; } } else { TempData[Constants.Message] = "Ne postoji dokument s id-om: " + IdDokumenta; TempData[Constants.ErrorOccurred] = true; } return(RedirectToAction(nameof(Index), new { filter = filter, page = page, sort = sort, ascending = ascending })); }
public IActionResult Delete(int id) { var mjesto = ctx.Mjesto .AsNoTracking() .Where(m => m.IdMjesta == id) .SingleOrDefault(); if (mjesto != null) { try { string naziv = mjesto.NazMjesta; ctx.Remove(mjesto); ctx.SaveChanges(); var result = new { message = $"Mjesto {naziv} sa šifrom {id} obrisano.", successful = true }; return(Json(result)); } catch (Exception exc) { var result = new { message = "Pogreška prilikom brisanja mjesta: " + exc.CompleteExceptionMessage(), successful = false }; return(Json(result)); } } else { return(NotFound($"Mjesto sa šifrom {id} ne postoji")); } }