예제 #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));
            }
        }
예제 #2
0
        public async Task <BandDTO> PutAsync(BandCreateDTO band)
        {
            this.Logger.LogTrace($"{nameof(this.PutAsync)} called");

            var result = await this.BandCreateService.CreateAsync(this.Mapper.Map <BandUpdateModel>(band));

            return(this.Mapper.Map <BandDTO>(result));
        }
예제 #3
0
        public ActionResult <BandDTO> CreateBand([FromBody] BandCreateDTO band)
        {
            var bandEnity = _mapper.Map <Band>(band);

            _bandAlbumRepository.AddBand(bandEnity);
            _bandAlbumRepository.Save();
            var bandToReturn = _mapper.Map <BandDTO>(bandEnity);

            return(CreatedAtRoute("GetBand", new { bandId = bandToReturn.Id }, bandToReturn));
        }