예제 #1
0
        // PUT api/PetWalker/5
        public async Task <IHttpActionResult> PutPetWalker(int id, PetWalker petwalker)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != petwalker.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PetWalkerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult UpdatePetWalker(int id, [FromBody] PetWalker PetWalker)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != PetWalker.PetWalkerID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #3
0
        public async Task <IHttpActionResult> GetPetWalker(int id)
        {
            PetWalker petwalker = await db.PetWalkers.FindAsync(id);

            if (petwalker == null)
            {
                return(NotFound());
            }

            return(Ok(petwalker));
        }
예제 #4
0
        public async Task <IHttpActionResult> PostPetWalker(PetWalker petwalker)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PetWalkers.Add(petwalker);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = petwalker.Id }, petwalker));
        }
        public IHttpActionResult AddPetWalker([FromBody] PetWalker PetWalker)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PetWalkers.Add(PetWalker);
            db.SaveChanges();

            return(Ok(PetWalker.PetWalkerID));
        }
예제 #6
0
        public async Task <IHttpActionResult> DeletePetWalker(int id)
        {
            PetWalker petwalker = await db.PetWalkers.FindAsync(id);

            if (petwalker == null)
            {
                return(NotFound());
            }

            db.PetWalkers.Remove(petwalker);
            await db.SaveChangesAsync();

            return(Ok(petwalker));
        }
        //Delete a petwalker from the database
        // DELETE: api/PetWalkerData/DeletePetWalker/2
        //[ResponseType(typeof(PetWalker))]????
        public IHttpActionResult DeletePetWalker(int id)
        {
            PetWalker PetWalker = db.PetWalkers.Find(id);

            if (PetWalker == null)
            {
                return(NotFound());
            }

            db.PetWalkers.Remove(PetWalker);
            db.SaveChanges();

            return(Ok());
        }
        public static void Init(string[] args)
        {
            PetWalker pw = new PetWalker();

            Dog lassie = new Dog {
                Name = "Lassie", FurColor = "Golden", Attitude = "Heroic"
            };

            pw.Walk(lassie);

            Goose carl = new Goose {
                Name = "Carl", Attitude = "Asshole", FeatherColor = "Snow White"
            };

            pw.Walk(carl);
        }
        public ActionResult Edit(int id, PetWalker PetWalkerInfo)
        {
            Debug.WriteLine(PetWalkerInfo.PetWalkerName);
            string url = "petwalkerdata/updatepetwalker/" + id;

            Debug.WriteLine(jss.Serialize(PetWalkerInfo));
            HttpContent content = new StringContent(jss.Serialize(PetWalkerInfo));

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            HttpResponseMessage response = client.PostAsync(url, content).Result;

            if (response.IsSuccessStatusCode)
            {
                return(RedirectToAction("Details", new { id = id }));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
        public IHttpActionResult FindPetWalker(int id)
        {
            PetWalker PetWalker = db.PetWalkers.Find(id);

            if (PetWalker == null)
            {
                return(NotFound());
            }

            //put into a 'friendly object format'
            PetWalkerDto PetWalkerDto = new PetWalkerDto
            {
                PetWalkerID   = PetWalker.PetWalkerID,
                PetWalkerName = PetWalker.PetWalkerName,
                PetWalkerBio  = PetWalker.PetWalkerBio,
            };


            //pass along data as 200 status code OK response

            return(Ok(PetWalkerDto));
        }
        public IHttpActionResult GetPetWalkerForAppointment(int id)
        {
            PetWalker PetWalker = db.PetWalkers
                                  .Where(pw => pw.Appointments.Any(a => a.AppointmentID == id))
                                  .FirstOrDefault();

            //if not found, return 404 status code.
            if (PetWalker == null)
            {
                return(NotFound());
            }

            //put into a 'friendly object format'
            PetWalkerDto PetWalkerDto = new PetWalkerDto
            {
                PetWalkerID   = PetWalker.PetWalkerID,
                PetWalkerName = PetWalker.PetWalkerName,
                PetWalkerBio  = PetWalker.PetWalkerBio
            };


            //pass along data as 200 status code OK response
            return(Ok(PetWalkerDto));
        }