public async Task <IActionResult> PostAsync([FromRoute] string bountyId, [FromBody] SimpleBountyItemDto bountyItemType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var bountyCampaing = await _dbContext.FindAsync <BountyCampaing>(bountyId); if (bountyCampaing == null) { return(NotFound()); } var user = await _dbContext.GetCurrentUserAsync(User); if (user == null) { return(NotFound()); } await _dbContext.Entry(bountyCampaing).Collection(b => b.Activities).LoadAsync(); var newBountyItem = new BountyCampaingActivity { Name = bountyItemType.Name, NeedToApprove = bountyItemType.NeedToApprove, Price = bountyItemType.Price.Value, CreatedByUser = user }; bountyCampaing.Activities.Add(newBountyItem); await _dbContext.SaveChangesAsync(); return(CreatedAtAction("GetAsync", new { id = newBountyItem.Id }, newBountyItem)); }
public async Task <IActionResult> PutAsync([FromRoute] string bountyId, [FromRoute] string id, [FromBody] SimpleBountyItemDto value) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var bountyItemType = _dbContext.Find <BountyCampaingActivity>(id); if (bountyItemType == null || bountyItemType.BountyCampaingId != bountyId) { return(NotFound()); } bountyItemType.Name = value.Name; bountyItemType.Price = value.Price.Value; bountyItemType.NeedToApprove = value.NeedToApprove; try { await _dbContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!(await BountyCampaingItemTypeExistsAsync(bountyId, id))) { return(NotFound()); } else { throw; } } return(NoContent()); }