Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Naziv")] ReferentniTip referentniTip)
        {
            if (id != referentniTip.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(referentniTip);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReferentniTipExists(referentniTip.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(referentniTip));
        }
Exemplo n.º 2
0
        public IActionResult Create(ReferentniTip referentnitip)
        {
            logger.LogTrace(JsonSerializer.Serialize(referentnitip));
            if (ModelState.IsValid)
            {
                try
                {
                    ctx.Add(referentnitip);
                    ctx.SaveChanges();

                    logger.LogInformation(new EventId(1000), $"Referentni tip {referentnitip.Naziv} dodan.");

                    TempData[Constants.Message]       = $"Referentni tip {referentnitip.Naziv} dodan.";
                    TempData[Constants.ErrorOccurred] = false;
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception exc)
                {
                    logger.LogError("Pogreška prilikom dodavanje novog refernetnog tipa: {0}", exc.CompleteExceptionMessage());
                    ModelState.AddModelError(string.Empty, exc.CompleteExceptionMessage());
                    return(View(referentnitip));
                }
            }
            else
            {
                return(View(referentnitip));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,Naziv")] ReferentniTip referentniTip)
        {
            if (ModelState.IsValid)
            {
                _context.Add(referentniTip);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(referentniTip));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Update(string id, int page = 1, int sort = 1, bool ascending = true)
        {
            //za različite mogućnosti ažuriranja pogledati
            //attach, update, samo id, ...
            //https://docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/crud#update-the-edit-page

            try
            {
                ReferentniTip referentnitip = await ctx.ReferentniTip.FindAsync(id);

                if (referentnitip == null)
                {
                    return(NotFound("Neispravna naziv referentnog tipa: " + id));
                }

                if (await TryUpdateModelAsync <ReferentniTip>(referentnitip, "",
                                                              rt => rt.Naziv
                                                              ))
                {
                    ViewBag.Page      = page;
                    ViewBag.Sort      = sort;
                    ViewBag.Ascending = ascending;
                    try
                    {
                        await ctx.SaveChangesAsync();

                        TempData[Constants.Message]       = "referentni tip ažurirana.";
                        TempData[Constants.ErrorOccurred] = false;
                        return(RedirectToAction(nameof(Index), new { page, sort, ascending }));
                    }
                    catch (Exception exc)
                    {
                        ModelState.AddModelError(string.Empty, exc.CompleteExceptionMessage());
                        return(View(referentnitip));
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Podatke o referentnom tipu nije moguće povezati s forme");
                    return(View(referentnitip));
                }
            }
            catch (Exception exc)
            {
                TempData[Constants.Message]       = exc.CompleteExceptionMessage();
                TempData[Constants.ErrorOccurred] = true;
                return(RedirectToAction(nameof(Edit), id));
            }
        }