Beispiel #1
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));
        }
Beispiel #2
0
        public ActionResult <BandDto> CreateBand(CreateBandDto bandDto)
        {
            var band = _mapper.Map <Band>(bandDto);

            _repository.AddBand(band);
            _repository.Save();
            var bandToReturn = _mapper.Map <BandDto>(band);

            return(CreatedAtRoute("GetBand", new { bandId = band.Id }, bandToReturn));
        }
Beispiel #3
0
        public ActionResult <AlbumDto> CreateAlbumForBand(Guid bandId, [FromBody] AlbumForCreatingDto album)
        {
            var albumEntity = _mapper.Map <Entities.Album>(album);

            _bandAlbumRepository.AddAlbum(bandId, albumEntity);
            _bandAlbumRepository.Save();

            var albumToReturn = _mapper.Map <AlbumDto>(albumEntity);

            return(CreatedAtRoute("GetAlbumForBand", new { bandId = bandId, albumId = albumToReturn.Id }, albumToReturn));
        }
Beispiel #4
0
        public ActionResult <BandDto> CreateBand([FromBody] BandForCreatingDto band)
        {
            Band bandEntity = _mapper.Map <Band>(band);

            _bandAlbumRepository.AddBand(bandEntity);
            _bandAlbumRepository.Save();

            BandDto bandToReturn = _mapper.Map <BandDto>(bandEntity);

            return(CreatedAtRoute("GetBand", new { bandId = bandToReturn.Id }, bandToReturn));
        }
Beispiel #5
0
        public ActionResult <BandDto> CreateBand([FromBody] BandForCreatingDto band)
        {
            var bandEntity = _mapper.Map <Entities.Band>(band);

            bandEntity.ID = Guid.NewGuid();

            _bandAlbumRepository.AddBand(bandEntity);
            _bandAlbumRepository.Save();

            var bandToReturn = _mapper.Map <BandDto>(bandEntity);

            return(CreatedAtRoute("getBand", new { bandID = bandToReturn.ID }, bandToReturn));
        }
        public async Task <ActionResult <BandDto> > CreateNewBand([FromBody] BandForCreatingDto band)
        {
            // returning band

            var bandEntity = _mapper.Map <Band>(band);

            _bandAlbumRepository.AddBand(bandEntity); // After adding the BandEntity will get band ID
            await _bandAlbumRepository.Save();

            var bandToReturn = _mapper.Map <BandDto>(bandEntity);

            return(CreatedAtRoute("GetBand", new { bandId = bandToReturn.Id }, bandToReturn));  // The third argument is the body used for returning the 201
        }
Beispiel #7
0
        public ActionResult <AlbumDTO> CreateAlbumForBand(Guid bandId, [FromBody] AlbumCreateDTO album)
        {
            if (!_bandAlbumRepository.BandExists(bandId))
            {
                return(NotFound());
            }
            var albumEntity = _mapper.Map <Entities.Album>(album);

            _bandAlbumRepository.AddAlbum(bandId, albumEntity);
            _bandAlbumRepository.Save();
            var albumReturn = _mapper.Map <AlbumDTO>(albumEntity);

            return(CreatedAtRoute("GetAlbum", new { bandId = bandId, albumId = albumReturn.Id }, albumReturn));
        }
Beispiel #8
0
        public ActionResult <AlbumDto> CreateAlbum(CreateAlbumDto albumDto)
        {
            if (!_repository.IsBandExists(albumDto.BandId))
            {
                return(NotFound());
            }
            var album = _mapper.Map <Album>(albumDto);

            _repository.AddAlbum(album);
            _repository.Save();

            var albumToReturn = _mapper.Map <AlbumDto>(album);

            return(CreatedAtRoute("GetAlbum", new { albumId = albumToReturn.Id }, albumToReturn));
        }
        public ActionResult<AlbumDto> CreateAlbumForBand(Guid bandId, [FromBody] AlbumForCreatingDto album)
        {
            if (!_bandAlbumRepository.BandExists(bandId))
            {
                return NotFound();
            }

            Album albumEntity = _mapper.Map<Album>(album);
            _bandAlbumRepository.AddAlbum(bandId, albumEntity);
            _bandAlbumRepository.Save();

            AlbumDto albumToReturn = _mapper.Map<AlbumDto>(albumEntity);

            return CreatedAtRoute("GetAlbumForBand", new { bandId = bandId, albumId = albumToReturn.Id }, albumToReturn);
        }
Beispiel #10
0
        public ActionResult <BandDto> CreateBand([FromBody] BandForCreatingDto band)
        {
            var bandEntity = _mapper.Map <Entities.Band>(band);

            _bandAlbumRepository.AddBand(bandEntity);
            _bandAlbumRepository.Save();

            var bandToReturn = _mapper.Map <BandDto>(bandEntity);

            var links = CreateLinksForBand(bandToReturn.Id, null);
            var linkedResourceToReturn = bandToReturn.ShapeData(null)
                                         as IDictionary <string, object>;

            linkedResourceToReturn.Add("links", links);

            return(CreatedAtRoute("GetBand", new { bandId = linkedResourceToReturn["Id"] }, linkedResourceToReturn));
        }
        public ActionResult <AlbumsDto> CreateAlbumForBand(Guid bandId, [FromBody] AlbumForCreatingDto album)
        {
            if (!_bandAlbumRepository.BandExists(bandId))
            {
                return(NotFound());
            }

            var albumEntity = _mapper.Map <Entities.Album>(album); //map to a object the database understands

            _bandAlbumRepository.AddAlbum(bandId, albumEntity);
            _bandAlbumRepository.Save();

            var albumToReturn = _mapper.Map <AlbumsDto>(albumEntity);

            return(CreatedAtRoute("GetAlbumForBand",
                                  new { bandId = bandId, albumId = albumToReturn.Id }, albumToReturn)); //return a location header and 201 created response
        }
Beispiel #12
0
        public ActionResult <BandDto> CreateBand(BandCreationDto creationDto)
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, ModelState));
            }

            creationDto.Founded ??= DateTime.Now;

            var band = _mapper.Map <Band>(creationDto);

            _bandAlbumRepository.AddBand(band);
            _bandAlbumRepository.Save();

            var bandDto = _mapper.Map <BandDto>(band);

            return(CreatedAtRoute("GetBand", new { bandId = bandDto.Id }, bandDto));
        }
        public ActionResult <BandDto> CreateBand([FromBody] BandForCreatingDto band)
        {
            var bandEntity = _mapper.Map <Entities.Band>(band); //map to a object the database understands

            _bandAlbumRepository.AddBand(bandEntity);           //currently the id property is 00000 and once the entity is added to the context then it gets a GUID Id
            _bandAlbumRepository.Save();

            var bandToReturn = _mapper.Map <BandDto>(bandEntity);

            return(CreatedAtRoute("GetBand", new { bandId = bandToReturn.Id }, bandToReturn)); //Header Location →https://localhost:5001/api/bands/08d7b5bc-cb24-422d-821b-a3d10226036e
        }
        public ActionResult <BandDto> CreateBand([FromBody] BandForCreatingDto band)
        {
            var bandEntity = _mapper.Map <Band>(band);

            _repo.AddBand(bandEntity);
            _repo.Save();

            var bandtoReturn = _mapper.Map <BandDto>(bandEntity);

            return(CreatedAtRoute("GetBand", new { bandId = bandtoReturn.BandId }, bandtoReturn));
        }
Beispiel #15
0
        public ActionResult <Band_Dto> CreateBand([FromBody] BandForCreating_Dto newband)
        {
            var bandEntity = _mapper.Map <Entities.m_cls_Band>(newband); // Profiles

            _bandAlbumRepository.AddBand(bandEntity);
            _bandAlbumRepository.Save();

            var bandToReturn = _mapper.Map <Band_Dto>(bandEntity);

            // redirect to GetBand route (Name = GetBand)
            return(CreatedAtRoute("GetBand", new { bandId = bandToReturn.Id }, bandToReturn));
        }
Beispiel #16
0
        public ActionResult <AlbumDto> PostAlbum(Guid bandId, AlbumCreationDto creationDto)
        {
            if (!_bandAlbumRepository.BandExists(bandId))
            {
                return(StatusCode(StatusCodes.Status404NotFound, new { error = "Band does not exist " }));
            }

            if (!ModelState.IsValid)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, ModelState));
            }

            var album = _mapper.Map <Album>(creationDto);

            _bandAlbumRepository.AddAlbum(bandId, album);
            _bandAlbumRepository.Save();

            var albumDto = _mapper.Map <AlbumDto>(album);

            return(CreatedAtRoute("GetAlbumForBand", new { bandId, albumId = albumDto.BandId }, albumDto));
        }
Beispiel #17
0
        public ActionResult <BandDto> CreateBand([FromBody] BandForCreatingDto band)
        {
            var bandEntity = _mapper.Map <Entities.Band>(band);

            //adds to the context, in order for us to save in the database we have to add save method
            _bandAlbumRepository.AddBand(bandEntity);
            _bandAlbumRepository.Save();

            var bandToReturn = _mapper.Map <BandDto>(bandEntity);

            return(CreatedAtRoute("GetBand", new { bandId = bandToReturn.Id }, bandToReturn));
        }
        public ActionResult <IEnumerable <BandDto> > CreateBandCollection([FromBody] IEnumerable <BandForCreatingDto> bandCollection)
        {
            var bandEntities = _mapper.Map <IEnumerable <Entities.Band> >(bandCollection);

            foreach (var band in bandEntities)
            {
                _bandAlbumRepository.AddBand(band);
            }
            _bandAlbumRepository.Save();

            return(Ok());
        }
        public ActionResult <AlbumDto> CreateForAlbumForBand(Guid bandId, [FromBody] AlbumForCreatingDto _album)
        {
            if (!_bandAlbumRepository.BandExists(bandId))
            {
                return(NotFound());
            }
            var AlbumEntity = _mapper.Map <Album>(_album);

            _bandAlbumRepository.AddAlbum(bandId, AlbumEntity);
            _bandAlbumRepository.Save();
            var AlbumToReturn = _mapper.Map <AlbumDto>(AlbumEntity);

            return(CreatedAtRoute("GetAlbumForBand", new { bandId = AlbumToReturn.BandId, albumId = AlbumToReturn.Id }, AlbumToReturn));
        }
Beispiel #20
0
        public ActionResult <IEnumerable <BandDto> > CreateBandCollection([FromBody] IEnumerable <BandForCreatingDto> bandCollection)
        {
            var bandEntities = _mapper.Map <IEnumerable <Band> >(bandCollection);

            foreach (var band in bandEntities)
            {
                _repository.AddBand(band);
            }
            _repository.Save();
            var bandCollectionToReturn = _mapper.Map <IEnumerable <BandDto> >(bandEntities);
            var IdsString = string.Join(",", bandCollectionToReturn.Select(a => a.Id));

            return(CreatedAtRoute("GetBandCollection", new { ids = IdsString }, bandCollectionToReturn));
        }
Beispiel #21
0
        public ActionResult <IEnumerable <BandDto> > CreateColletion([FromBody] IEnumerable <BandForCreatingDto> _bands)
        {
            var BandEntity = _mapper.Map <IEnumerable <Band> >(_bands);

            foreach (var Band in BandEntity)
            {
                _bandAlbumRepository.AddBand(Band);
            }

            _bandAlbumRepository.Save();
            var bandsCreating = _mapper.Map <IEnumerable <BandDto> >(BandEntity);

            return(Ok(bandsCreating));
        }
        public ActionResult <BandDto> CreateBand([FromBody] BandForCreatingDto band)
        {
            var bandEntity = _mapper.Map <Band>(band);

            if (bandEntity == null)
            {
                return(BadRequest("Band is Empty"));
            }

            _bandAlbumRepository.AddBand(bandEntity);
            _bandAlbumRepository.Save();

            var bandToReturn = _mapper.Map <BandDto>(bandEntity);

            return(CreatedAtRoute(nameof(GetBand), new { bandId = bandToReturn.Id }, bandToReturn));
        }
Beispiel #23
0
        public ActionResult <AlbumDto> CreatingAlbum(Guid bandId, [FromBody] CreatingAlbumForDto album)
        {
            if (!_repo.BandExist(bandId))
            {
                return(NotFound());
            }

            var albumEntity = _mapper.Map <Entities.Album>(album);

            _repo.AddAlbum(bandId, albumEntity);
            _repo.Save();

            var albumToReturn = _mapper.Map <AlbumDto>(albumEntity);

            return(CreatedAtRoute("GetAlbumForBand", new { bandId = bandId, albumId = albumToReturn.Id }, albumToReturn));
        }
Beispiel #24
0
        public ActionResult <IEnumerable <Band> > CreateAGroupOfBandsAtAGo(IEnumerable <BandCreationDto> bandCreationDtos)
        {
            var bandsToCreate = _mapper.Map <IEnumerable <Band> >(bandCreationDtos);

            foreach (var band in bandsToCreate)
            {
                _bandAlbumRepository.AddBand(band);
            }

            _bandAlbumRepository.Save();

            var bandsToReturn = _mapper.Map <IEnumerable <BandDto> >(bandsToCreate);

            var ids = string.Join(",", bandsToReturn.Select(x => x.Id));

            return(CreatedAtRoute("GetCollectionOfBands", new { ids }, bandsToReturn));
        }
Beispiel #25
0
        public async Task <ActionResult <IEnumerable <BandDto> > > CreateBandCollection([FromBody] IEnumerable <BandForCreatingDto> bandCollection)
        {
            var bandsEntities = _mapper.Map <IEnumerable <Band> >(bandCollection);

            _bandAlbumRepository.AddBands(bandsEntities);

            await _bandAlbumRepository.Save();

            // Select Method
            // bandsEntities.Select(b => b.Id);
            // Linq
            // from b in bandsEntities select b.Id

            var bandsToReturn = _mapper.Map <IEnumerable <BandDto> >(bandsEntities);

            return(CreatedAtRoute("GetBandsByIds", new { bandIds = from b in bandsToReturn select b.Id }, bandsToReturn));
        }
        public ActionResult <IEnumerable <Band_Dto> > CreateBandCollection([FromBody] IEnumerable <BandForCreating_Dto> newbandCollection)
        {
            var bandEntities = _mapper.Map <IEnumerable <Entities.m_cls_Band> >(newbandCollection);

            foreach (var band in bandEntities)
            {
                _bandAlbumRepository.AddBand(band);
            }

            _bandAlbumRepository.Save();

            //var bandCollectionToReturn = _mapper.Map<IEnumerable<Band_Dto>>(bandEntities);
            //var IdsString = string.Join(",", bandCollectionToReturn.Select(a => a.Id));

            //return CreatedAtRoute("GetBandCollection", new { ids = IdsString }, bandCollectionToReturn);

            return(Ok());
        }
Beispiel #27
0
        public ActionResult <AlbumDto> CreateAlbumForBand(Guid bandID, [FromBody] AlbumForCreatingDto album)
        {
            if (!_bandAlbumRepository.BandExists(bandID))
            {
                return(NotFound());
            }

            var albumEntity = _mapper.Map <Entities.Album>(album);

            _bandAlbumRepository.AddAlbum(bandID, albumEntity);
            _bandAlbumRepository.Save();

            var returnAlbum = _mapper.Map <AlbumDto>(albumEntity);

            return(CreatedAtRoute("GetAlbumsForBand", new { bandID = bandID, albumID = returnAlbum.ID }, returnAlbum));
        }
        public async Task <ActionResult <AlbumDto> > CreateNewAlbum(Guid bandId, [FromBody] AlbumForCreatingDto album)
        {
            // Checking if the band Exist
            if (!await _bandAlbumRepository.BandExists(bandId))
            {
                return(NotFound());
            }

            var albumEntity = _mapper.Map <Album>(album);

            _bandAlbumRepository.AddAlbum(bandId, albumEntity);
            await _bandAlbumRepository.Save();

            var albumToReturn = _mapper.Map <AlbumDto>(albumEntity);

            return(CreatedAtRoute(
                       "GetAlbumForBand",
                       new { bandId = bandId, albumId = albumToReturn.Id },
                       albumToReturn
                       ));
        }