Exemplo n.º 1
0
        public ActionResult partiallyupdatealbumnforband(Guid bandid, Guid albumnid, [FromBody] JsonPatchDocument <albumnforupdatingdtos> patchDocument)
        {
            if (!_repo.bandexist(bandid))
            {
                return(NotFound());
            }
            var albumnfromrepo = _repo.GetAlbum(bandid, albumnid);

            if (albumnfromrepo == null)
            {
                // return NotFound();
                var albumn = new albumnforupdatingdtos();
                patchDocument.ApplyTo(albumn);
                var albumntoadd = _mapper.Map <album>(albumn);
                albumntoadd.Id = albumnid;

                _repo.addalbumn(bandid, albumntoadd);
                _repo.save();

                var albumntoreturn = _mapper.Map <albumdtos>(albumntoadd);
                return(CreatedAtRoute("getalbumsforband", new { bandid = bandid, albumnid = albumntoreturn.Id }, albumntoreturn));
            }
            var albumntopatch = _mapper.Map <albumnforupdatingdtos>(albumnfromrepo);

            patchDocument.ApplyTo(albumntopatch, ModelState);
            if (!TryValidateModel(albumntopatch))
            {
                return(ValidationProblem(ModelState));
            }
            _mapper.Map(albumntopatch, albumnfromrepo);
            _repo.updatealbumn(albumnfromrepo);
            _repo.save();
            return(NoContent());
        }
Exemplo n.º 2
0
        public ActionResult updatealbumnforband(Guid bandid, Guid albumnid, [FromBody] albumnforupdatingdtos albumn)
        {
            if (!_repo.bandexist(bandid))
            {
                return(NotFound());
            }
            var albumnfromrepo = _repo.GetAlbum(bandid, albumnid);

            if (albumnfromrepo == null)
            {
                //return NotFound();
                var albumntoadd = _mapper.Map <album>(albumn);
                albumntoadd.Id = albumnid;
                _repo.addalbumn(bandid, albumntoadd);
                _repo.save();
                var albumtoreturn = _mapper.Map <albumdtos>(albumntoadd);
                return(CreatedAtRoute("getalbumsforband", new { bandid = bandid, albumnid = albumtoreturn.Id }));
            }
            _mapper.Map(albumn, albumnfromrepo);
            _repo.updatealbumn(albumnfromrepo);
            _repo.save();
            return(NoContent());
        }