Exemplo n.º 1
0
        // POST api/Statusi
        public HttpResponseMessage Poststatusi(statusi statusi)
        {
            if (ModelState.IsValid)
            {
                db.statusi.Add(statusi);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, statusi);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = statusi.idStatusa }));
                return response;
            }
            else
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }
        }
Exemplo n.º 2
0
        // PUT api/Statusi/5
        public HttpResponseMessage Putstatusi(int id, statusi statusi)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            if (id != statusi.idStatusa)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
            }

            return Request.CreateResponse(HttpStatusCode.OK);
        }