Ejemplo n.º 1
0
        public IHttpActionResult PostAkumulators(Akumulators akumulators)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Akumulatori.Add(akumulators);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (AkumulatorsExists(akumulators.Akumulatora_ID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("BatmanApi-Akumulators", new { id = akumulators.Akumulatora_ID }, akumulators));
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutAkumulators(int id, Akumulators akumulators)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != akumulators.Akumulatora_ID)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AkumulatorsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public IHttpActionResult GetAkumulators(int id)
        {
            Akumulators akumulators = db.Akumulatori.Find(id);

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

            return(Ok(akumulators));
        }
Ejemplo n.º 4
0
        public IHttpActionResult DeleteAkumulators(int id)
        {
            Akumulators akumulators = db.Akumulatori.Find(id);

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

            db.Akumulatori.Remove(akumulators);
            db.SaveChanges();

            return(Ok(akumulators));
        }