Ejemplo n.º 1
0
        // PUT api/GoalList/5
        public HttpResponseMessage PutGoalListDto(int id, GoalListDto goallistdto)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != goallistdto.GoalListId)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

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

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

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Ejemplo n.º 2
0
        // GET api/GoalList/5
        public GoalListDto GetGoalListDto(int id)
        {
            GoalListDto goallistdto = db.GoalListDtoes.Find(id);

            if (goallistdto == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(goallistdto);
        }
Ejemplo n.º 3
0
        // POST api/GoalList
        public HttpResponseMessage PostGoalListDto(GoalListDto goallistdto)
        {
            if (ModelState.IsValid)
            {
                db.GoalListDtoes.Add(goallistdto);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, goallistdto);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = goallistdto.GoalListId }));
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Ejemplo n.º 4
0
        // DELETE api/GoalList/5
        public HttpResponseMessage DeleteGoalListDto(int id)
        {
            GoalListDto goallistdto = db.GoalListDtoes.Find(id);

            if (goallistdto == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.GoalListDtoes.Remove(goallistdto);

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

            return(Request.CreateResponse(HttpStatusCode.OK, goallistdto));
        }