public async Task <IHttpActionResult> PutVideoAlbum(int id, VideoAlbumDto videoAlbumDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != videoAlbumDto.ID)
            {
                return(BadRequest());
            }
            var videoAlbum = DtoToEntityIMapper.Map <VideoAlbumDto, VideoAlbum>(videoAlbumDto); ////

            UoW.GetRepository <VideoAlbum>().ModifyEntityState(videoAlbum);

            try
            {
                await UoW.SaveAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VideoAlbumExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> PostVideoAlbum(VideoAlbumDto videoAlbumDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var videoAlbum = DtoToEntityIMapper.Map <VideoAlbumDto, VideoAlbum>(videoAlbumDto); ////

            UoW.GetRepository <VideoAlbum>().Insert(videoAlbum);
            await UoW.SaveAsync();

            return(CreatedAtRoute("DefaultApi", new { id = videoAlbum.ID }, videoAlbum));
        }
Beispiel #3
0
        public async Task <ActionResult <VideoAlbumDto> > PostVideoAlbum([FromBody] VideoAlbumDto videoAlbumDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            VideoAlbum videoAlbum = DtoToEntityIMapper.Map <VideoAlbumDto, VideoAlbum>(videoAlbumDto);

            repository.Add(videoAlbum);
            await uoW.SaveAsync();

            return(CreatedAtAction("GetVideoAlbum", new { id = videoAlbum.ID }, videoAlbumDto));
        }
Beispiel #4
0
        public async Task <ActionResult <VideoAlbumDto> > GetVideoAlbum([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var videoAlbum = await repository.GetAsync(a => a.ID == id);

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

            VideoAlbumDto videoAlbumDto = EntityToDtoIMapper.Map <VideoAlbum, VideoAlbumDto>(videoAlbum);

            return(Ok(videoAlbumDto));
        }
Beispiel #5
0
        public async Task <ActionResult <VideoAlbumDto> > PutVideoAlbum([FromRoute] int id, [FromBody] VideoAlbumDto videoAlbumDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != videoAlbumDto.ID)
            {
                return(BadRequest());
            }

            VideoAlbum videoAlbum = DtoToEntityIMapper.Map <VideoAlbumDto, VideoAlbum>(videoAlbumDto);

            repository.ModifyEntryState(videoAlbum, EntityState.Modified);

            try
            {
                await uoW.SaveAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VideoAlbumExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }