Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Odjeli odjeli = db.Odjeli.Find(id);

            db.Odjeli.Remove(odjeli);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "id,naziv")] Odjeli odjeli)
 {
     if (ModelState.IsValid)
     {
         db.Entry(odjeli).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(odjeli));
 }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "id,naziv")] Odjeli odjeli)
        {
            if (ModelState.IsValid)
            {
                db.Odjeli.Add(odjeli);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(odjeli));
        }
Exemplo n.º 4
0
        // GET: Odjeli/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Odjeli odjeli = db.Odjeli.Find(id);

            if (odjeli == null)
            {
                return(HttpNotFound());
            }
            return(View(odjeli));
        }
Exemplo n.º 5
0
        public ActionResult Create(PodaciAddVM vm)
        {
            Odjeli odjeli = new Odjeli();

            if (ModelState.IsValid)
            {
                odjeli.Naziv = vm.Naziv;
                db.Odjelii.Add(odjeli);
                db.SaveChanges();

                TempData["Message"] = "Uspjesno dodavanje!";
                return(RedirectToAction("Create"));
            }
            return(View(vm));
        }
        public async Task <IActionResult> Update(int id, int page = 1, int sort = 1, bool ascending = true)
        {
            try
            {
                Odjeli odjel = await _ctx.Odjeli.FindAsync(id);

                if (odjel == null)
                {
                    return(NotFound($"Ne postoji odjel s oznakom {id}"));
                }

                ViewBag.Page      = page;
                ViewBag.Sort      = sort;
                ViewBag.Ascending = ascending;
                bool ok = await TryUpdateModelAsync <Odjeli>(odjel,
                                                             "", b => b.IdOdjela, b => b.Naziv);

                if (ok)
                {
                    try
                    {
                        TempData[Constants.Message]       = $"odjel {odjel.Naziv} uspjesno azuriran.*";
                        TempData[Constants.ErrorOccurred] = false;
                        await _ctx.SaveChangesAsync();

                        return(RedirectToAction(nameof(Index), new { page, sort, ascending }));
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError(string.Empty, e.Message);
                        return(View(odjel));
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Podatke o odjelu nije moguce povezati.");
                    return(View(odjel));
                }
            }
            catch (Exception e)
            {
                TempData[Constants.Message]       = "Pogreska prilikom azuriranja odjela." + e.Message;
                TempData[Constants.ErrorOccurred] = true;
                return(RedirectToAction(nameof(Edit), new { id, page, sort, ascending }));
            }
        }
 public IActionResult Create(Odjeli odjel)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _ctx.Add(odjel);
             _ctx.SaveChanges();
             TempData[Constants.Message]       = $"Odjel {odjel.Naziv} uspjesno dodan.*";
             TempData[Constants.ErrorOccurred] = false;
             return(RedirectToAction(nameof(Index)));
         }
         catch (Exception e)
         {
             ModelState.AddModelError(string.Empty, e.Message);
             return(View(odjel));
         }
     }
     else
     {
         return(View(odjel));
     }
 }