Ejemplo n.º 1
0
        public IHttpActionResult Post(BandCreateDTO bandPost)
        {
            if (ModelState.IsValid)
            {
                //Create enty in DB
                band bandLib = new band
                {
                    name          = bandPost.name,
                    country       = bandPost.country,
                    genre         = bandPost.genre,
                    formationDate = bandPost.formationDate
                };
                entities.bands.Add(bandLib);
                entities.SaveChanges();

                //Set up return model
                BandDetailDTO band = new BandDetailDTO
                {
                    name          = bandLib.name,
                    country       = bandLib.country,
                    genre         = bandLib.genre,
                    formationDate = bandLib.formationDate,
                    id            = bandLib.id
                };

                //Return status created + new path(Location)
                return(CreatedAtRoute("DefaultApi", new { id = band.id }, band));
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult Put(BandDetailDTO band)
        {
            if (ModelState.IsValid)
            {
                //Find and update the band
                band bandLib = entities.bands.Find(band.id);
                if (bandLib != null)
                {
                    bandLib.name          = band.name;
                    bandLib.country       = band.country;
                    bandLib.genre         = band.genre;
                    bandLib.formationDate = band.formationDate;

                    entities.Entry(bandLib).State = EntityState.Modified;
                    entities.SaveChanges();

                    return(Ok(band));
                }
                else
                {
                    return(NotFound());
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }