コード例 #1
0
        // POST competition
        public HttpResponseMessage Post(CreateCompetitionItem item)
        {
            Competition competition = _mapper.Map<CreateCompetitionItem, Competition>(item);
            if (competition.IsValid)
            {
                _competitionRepository.Add(competition);

                CompetitionItem createdItem = _mapper.Map<Competition, CompetitionItem>(competition);
                return CreatedHttpResponse(createdItem.ID, createdItem);
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest, competition.ValidationErrors);
        }
コード例 #2
0
        // PUT competition/B5608F8E-F449-E211-BB40-1040F3A7A3B1
        public HttpResponseMessage Put(int id, CreateCompetitionItem item)
        {
            Competition competition = _mapper.Map<CreateCompetitionItem, Competition>(item);

            if (competition.IsValid)
            {
                _competitionRepository.Update(competition);
                return Request.CreateResponse(HttpStatusCode.OK);
            }

            return Request.CreateResponse(HttpStatusCode.BadRequest, competition.ValidationErrors);
        }