Пример #1
0
        public HttpResponseMessage Put(int id, [FromBody] Aviss A)
        {
            try
            {
                using (USERSDBEntities entities = new USERSDBEntities())
                {
                    var entity = entities.Avisses.FirstOrDefault(e => e.ID == id);
                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Avis with ID = " + id.ToString() + " not found"));
                    }
                    else
                    {
                        entity.NOTE_ACCUEIL      = A.NOTE_ACCUEIL;
                        entity.NOTE_DIAG         = A.NOTE_DIAG;
                        entity.NOTE_FACIL        = A.NOTE_FACIL;
                        entity.NOTE_PROMPATITUDE = A.NOTE_PROMPATITUDE;
                        entity.NOTE_RECOM        = A.NOTE_RECOM;

                        entities.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK, entity));
                    }
                }
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }
Пример #2
0
        public HttpResponseMessage Post([FromBody] Aviss A)
        {
            try
            {
                using (USERSDBEntities entities = new USERSDBEntities())
                {
                    entities.Avisses.Add(A);
                    entities.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, A);
                    message.Headers.Location = new Uri(Request.RequestUri + "/" + A.ID.ToString());
                    return(message);
                }
            }
            catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }