Example #1
0
        // GET: UslugaLjudi/Create
        public IActionResult Create(int uslugaId, int referentniTipOpremeId)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    UslugaOprema uslugaOprema = new UslugaOprema();
                    uslugaOprema.UslugaId = uslugaId;
                    uslugaOprema.ReferentniTipOpremeId = referentniTipOpremeId;


                    _context.UslugaOprema.Add(uslugaOprema);
                    _context.SaveChanges();
                    //logger.LogInformation($"Osoba {osoba.Ime} dodana.");
                    // TempData[Constants.Message] = $"Osoba {} dodana.";
                    //  TempData[Constants.ErrorOccurred] = false;
                    return(RedirectToAction("Index", "Usluga"));
                }
                catch (Exception)
                {
                    //  logger.LogError("Pogreška prilikom dodavanje nove osobe: {0}", exc.CompleteExceptionMessage());
                    //  ModelState.AddModelError(string.Empty, exc.CompleteExceptionMessage());
                    return(View());
                }
            }
            else
            {
                //PrepareDropDownLists();
                return(View());
            }
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, [Bind("UslugaOpremaId,UslugaId,ReferentniTipOpremeId")] UslugaOprema uslugaOprema)
        {
            if (id != uslugaOprema.UslugaOpremaId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(uslugaOprema);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UslugaOpremaExists(uslugaOprema.UslugaOpremaId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ReferentniTipOpremeId"] = new SelectList(_context.ReferentniTipOpreme, "ReferentniTipOpremeId", "Naziv", uslugaOprema.ReferentniTipOpremeId);
            ViewData["UslugaId"] = new SelectList(_context.Usluga, "UslugaId", "Naziv", uslugaOprema.UslugaId);
            return(View(uslugaOprema));
        }