コード例 #1
0
        public ContributionDto CreateContribution(ContributionDto contributionDto)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var contribution = Mapper.Map <ContributionDto, Contribution>(contributionDto);

            _db.Contributions.Add(contribution);
            _db.SaveChanges();

            contributionDto.consID = contribution.consID;

            return(contributionDto);
        }
コード例 #2
0
        public void UpdateContribution(int id, ContributionDto contributionDto)
        {
            if (!ModelState.IsValid)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            var contributionInDb = _db.Contributions.SingleOrDefault(c => c.consID == id);

            if (contributionInDb == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            Mapper.Map(contributionDto, contributionInDb);

            _db.SaveChanges();
        }