Exemplo n.º 1
0
        public IHttpActionResult PostLeverandør(Leverandør leverandør)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Leverandør.Add(leverandør);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (LeverandørExists(leverandør.CVR))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = leverandør.CVR }, leverandør));
        }
Exemplo n.º 2
0
        public IHttpActionResult PutLeverandør(int id, Leverandør leverandør)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != leverandør.CVR)
            {
                return(BadRequest());
            }

            db.Entry(leverandør).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 3
0
        public IHttpActionResult GetLeverandør(int id)
        {
            Leverandør leverandør = db.Leverandør.Find(id);

            if (leverandør == null)
            {
                return(NotFound());
            }

            return(Ok(leverandør));
        }
Exemplo n.º 4
0
        public IHttpActionResult DeleteLeverandør(int id)
        {
            Leverandør leverandør = db.Leverandør.Find(id);

            if (leverandør == null)
            {
                return(NotFound());
            }

            db.Leverandør.Remove(leverandør);
            db.SaveChanges();

            return(Ok(leverandør));
        }