public async Task <IHttpActionResult> PutKupac(int id, Kupac kupac)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != kupac.IDKupac)
            {
                return(BadRequest());
            }

            db.Entry(kupac).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!KupacExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public async Task <ActionResult> Create([Bind(Include = "IDKupac,Ime,Prezime,Email,Telefon,GradID")] Kupac kupac)
        {
            if (ModelState.IsValid)
            {
                db.Kupacs.Add(kupac);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.GradID = new SelectList(db.Grads, "IDGrad", "Naziv", kupac.GradID);
            return(View(kupac));
        }
        // PUT: odata/Okupacs(5)
        public async Task <IHttpActionResult> Put([FromODataUri] int key, Delta <Kupac> patch)
        {
            Validate(patch.GetEntity());

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Kupac kupac = await db.Kupacs.FindAsync(key);

            if (kupac == null)
            {
                return(NotFound());
            }

            patch.Put(kupac);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!KupacExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(kupac));
        }