public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Simptom simptom) { if (id != simptom.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(simptom); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SimptomExists(simptom.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(simptom)); }
public IActionResult Create(Simptom simptom) { if (ModelState.IsValid) { try { simptom.SifraSimptoma = (int)NewId(); ctx.Add(simptom); ctx.SaveChanges(); TempData[Constants.Message] = $"Simptom {simptom.SifraSimptoma} uspješno dodan."; TempData[Constants.ErrorOccurred] = false; logger.LogInformation($"Simptom {simptom.SifraSimptoma} uspješno dodan."); return(RedirectToAction(nameof(Index))); } catch (Exception exc) { ModelState.AddModelError(string.Empty, exc.CompleteExceptionMessage()); logger.LogError($"Pogreška prilikom dodavanja novog simptoma {exc.CompleteExceptionMessage()}"); return(View(simptom)); } } else { logger.LogError($"Pogreška prilikom dodavanja novog simptoma"); return(View(simptom)); } }
public async Task <IActionResult> Update(int id, int page = 1, int sort = 1, bool ascending = true) { try { Simptom simptom = await ctx.Simptom.FindAsync(id); if (simptom == null) { logger.LogError($"Pogreška prilikom ažuriranja simptoma. Ne postoji simptom s tom šifrom: {id}"); return(NotFound($"Ne postoji simptom s tom šifrom {id}")); } ViewBag.page = page; ViewBag.sort = sort; ViewBag.ascending = ascending; bool ok = await TryUpdateModelAsync <Simptom>(simptom, "", p => p.Opis); if (ok) { try { TempData[Constants.Message] = $"Simptom {simptom.SifraSimptoma} uspješno ažuriran."; TempData[Constants.ErrorOccurred] = false; await ctx.SaveChangesAsync(); logger.LogInformation($"Simptom {simptom.SifraSimptoma} uspješno ažuriran."); return(RedirectToAction(nameof(Index), new { page, sort, ascending })); } catch (Exception exc) { ModelState.AddModelError(string.Empty, exc.CompleteExceptionMessage()); logger.LogError($"Pogreška prilikom ažuriranja simptoma. {exc.CompleteExceptionMessage()}"); return(View(simptom)); } } else { ModelState.AddModelError(string.Empty, "Podatke o simptomu nije moguće povezati s forme."); logger.LogError($"Pogreška prilikom ažuriranja simptoma. Podatke o simptomu nije moguće povezati s forme."); return(View(simptom)); } } catch (Exception exc) { TempData[Constants.Message] = exc.CompleteExceptionMessage(); TempData[Constants.ErrorOccurred] = true; logger.LogError($"Pogreška prilikom ažuriranja simptoma. {exc.CompleteExceptionMessage()}"); return(RedirectToAction(nameof(Edit), new { page, sort, ascending })); } }
public async Task <IActionResult> Create([Bind("Id,Name")] Simptom simptom) { if (ModelState.IsValid) { _context.Add(simptom); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(simptom)); }