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); }
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(); }