示例#1
0
        public IHttpActionResult Add(ArtistModel artistModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newAtist = ArtistModel.ToArtist(artistModel);

            this.data.Artists.Add(newAtist);
            this.data.SaveChanges();

            artistModel.ID = newAtist.ID;
            return(Ok(artistModel));
        }
        // POST api/Artists
        public HttpResponseMessage PostArtist(ArtistModel artist)
        {
            if (artist == null)
            {
                var errResponse = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error!");
                return(errResponse);
            }

            Artist artistToAdd = artist.ToArtist();
            var    entity      = this.repository.Add(artistToAdd);

            var response = this.Request.CreateResponse(HttpStatusCode.Created, entity);

            response.Headers.Location =
                new Uri(this.Request.RequestUri + artist.ArtistId.ToString(CultureInfo.InvariantCulture));
            return(response);
        }
示例#3
0
        public IHttpActionResult Update(int id, ArtistModel artistModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existingArtist = this.data.Artists.Get(id);

            if (existingArtist == null)
            {
                return(BadRequest(BabRequestMessage));
            }

            ArtistModel.ToArtist(artistModel, existingArtist);

            this.data.Artists.Update(existingArtist);
            this.data.SaveChanges();

            return(Ok(artistModel));
        }