Exemplo n.º 1
0
        public IActionResult Edit(PartnerViewModel model, int page = 1, int sort = 1, bool ascending = true)
        {
            if (model == null)
            {
                return(NotFound("Nema poslanih podataka"));
            }
            var partner = ctx.Partner.Find(model.IdPartnera);

            if (partner == null)
            {
                return(NotFound("Ne postoji partner s id-om: " + model.IdPartnera));
            }
            ValidateModel(model);

            if (ModelState.IsValid)
            {
                try
                {
                    CopyValues(partner, model);

                    //vezani dio je stvoren s new Osoba() ili new Tvrtka() pa je entity stated Added što bi proizvelo Insert pa ne update
                    if (partner.Osoba != null)
                    {
                        ctx.Entry(partner.Osoba).State = EntityState.Modified;
                    }
                    if (partner.Tvrtka != null)
                    {
                        ctx.Entry(partner.Tvrtka).State = EntityState.Modified;
                    }

                    ctx.SaveChanges();
                    TempData[Constants.Message]       = $"Partner {model.IdPartnera} uspješno ažuriran";
                    TempData[Constants.ErrorOccurred] = false;
                    return(RedirectToAction(nameof(Index), new { page = page, sort = sort, ascending = ascending }));
                }
                catch (Exception exc)
                {
                    ModelState.AddModelError(string.Empty, exc.CompleteExceptionMessage());
                    DohvatiNaziveMjesta(model);
                    return(View(model));
                }
            }
            else
            {
                DohvatiNaziveMjesta(model);
                return(View(model));
            }
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "CustomerId,FirstName,LastName,Email,Password,Address,City,State,DOB")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Exemplo n.º 3
0
 public ActionResult Edit(Klient klient)
 {
     if (ModelState.IsValid)
     {
         db.Entry(klient).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(klient));
 }