public async Task <IActionResult> Post([FromBody] Outbid outbid) { try { if (ModelState.IsValid) { // Check if amount is not already existed if (await _auctionsDbContext.Outbids.AnyAsync(o => o.BidId == outbid.BidId && o.Amount >= outbid.Amount)) { //return StatusCode(400, $"someone already did outbid on this amount:{outbid.Amount} or more!"); } outbid.Id = Guid.NewGuid(); await _auctionsDbContext.Outbids.AddAsync(outbid); await _auctionsDbContext.SaveChangesAsync(); return(Ok()); } else { return(StatusCode(400, ModelState)); } } catch (Exception exc) { throw; } }
public async Task <ActionResult> Post([FromBody] Outbid outBidModel) { try { if (ModelState.IsValid) { var message = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(outBidModel))) { MessageId = Guid.NewGuid().ToString(), //$"{outBidModel.BidId}-{outBidModel.Amount}", //SessionId = outBidModel.BidId.ToString() }; await _messagingBrokerSender.SendAsync(message); return(Ok()); } else { return(StatusCode(400, ModelState)); } } catch (Exception exc) { throw; } }