Esempio n. 1
0
        public HttpResponseMessage GetById(Guid id)
        {
            Superhero superhero = Superheroes.FirstOrDefault(c => c.Id == id);

            return(superhero == null
                ? Request.CreateErrorResponse(HttpStatusCode.NotFound, "Superhero not found")
                : Request.CreateResponse(HttpStatusCode.OK, superhero));
        }
Esempio n. 2
0
        public HttpResponseMessage Post(PostSuperheroModel postSuperheroModel)
        {
            // Map a PostSuperheroModel object to Superhero object
            Superhero superhero = Mapper.Map <Superhero>(postSuperheroModel);

            superhero.Id = Guid.NewGuid();
            Superheroes.Add(superhero);

            return(Request.CreateResponse(HttpStatusCode.Created, superhero));
        }
Esempio n. 3
0
        /// <summary>
        /// Delete a superhero
        /// </summary>
        /// <remarks>
        /// Delete a superhero
        /// </remarks>
        /// <param name="id">Id of the superhero to delete</param>
        /// <returns></returns>
        public HttpResponseMessage Delete(Guid id)
        {
            Superhero existingSuperhero = Superheroes.FirstOrDefault(c => c.Id == id);

            if (existingSuperhero == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Superhero not found"));
            }

            Superheroes.Remove(existingSuperhero);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Esempio n. 4
0
        public HttpResponseMessage Put(PutSuperheroModel putSuperheroModel)
        {
            Superhero existingSuperhero = Superheroes.FirstOrDefault(c => c.Id == putSuperheroModel.Id);

            if (existingSuperhero == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Superhero not found"));
            }

            Superhero superhero = Mapper.Map <Superhero>(putSuperheroModel);

            Superheroes.Remove(existingSuperhero);
            Superheroes.Add(superhero);

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