Exemplo n.º 1
0
        // POST api/FamilyProfile
        public HttpResponseMessage PostFamilyProfile(FamilyProfile familyprofile)
        {
            if (ModelState.IsValid)
            {
                db.FamilyProfiles.Add(familyprofile);
                db.SaveChanges();

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

            if (id != familyprofile.FamilyId)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }

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

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

            return Request.CreateResponse(HttpStatusCode.OK);
        }