public async Task <Response> AddBuyer(BidBuyerJoinRequest bidBuyerJoinRequest) { BidEntity bid = await _context.Bids.Where(b => b.Id == bidBuyerJoinRequest.BidId).Include(b => b.CurrentParticipancies).FirstOrDefaultAsync().ConfigureAwait(false); if (bid == null) { return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = BidNotFoundFailString }); } bid.CurrentParticipancies.Add(new ParticipancyEntity { BidId = bidBuyerJoinRequest.BidId, BuyerId = bidBuyerJoinRequest.BuyerId, NumOfUnits = bidBuyerJoinRequest.Items }); bid.UnitsCounter += bidBuyerJoinRequest.Items; try { _context.Bids.Update(bid); await _context.SaveChangesAsync().ConfigureAwait(false); } catch (Exception ex) { return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message }); } return(new Response() { IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage() }); }
public async Task <ActionResult> AddBuyer(string bidId, BidBuyerJoinRequest bidBuyerJoinRequest) { if (bidBuyerJoinRequest.BidId == null) { bidBuyerJoinRequest.BidId = bidId; } Response response = await this.bidsManager.AddBuyer(bidBuyerJoinRequest).ConfigureAwait(false); if (response.IsOperationSucceeded) { return(this.StatusCode(StatusCodes.Status201Created, response.SuccessOrFailureMessage)); } return(this.StatusCode(StatusCodes.Status304NotModified, response.SuccessOrFailureMessage)); }
public async Task <ActionResult> AddBuyer(string bidId, BidBuyerJoinRequest bidBuyerJoinRequest) { bidBuyerJoinRequest.BuyerId = GetRequestUserId(); if (bidBuyerJoinRequest.BidId == null) { bidBuyerJoinRequest.BidId = bidId; } else if (bidBuyerJoinRequest.BidId != bidId) { return(this.StatusCode(StatusCodes.Status400BadRequest, $"bidId:{bidId} mentioned in request path dosen't match bidId:{bidBuyerJoinRequest.BidId} in request Body")); } Response response = await this.bidsManager.AddBuyer(bidBuyerJoinRequest).ConfigureAwait(false); if (response.IsOperationSucceeded) { return(this.StatusCode(StatusCodes.Status201Created, response.SuccessOrFailureMessage)); } return(this.StatusCode(StatusCodes.Status304NotModified, response.SuccessOrFailureMessage)); }
public async Task <Response> AddBuyer(BidBuyerJoinRequest bidBuyerJoinRequest) { BidEntity bid = await _context.Bids.Where(b => b.Id == bidBuyerJoinRequest.BidId).Include(b => b.CurrentParticipancies).Include(b => b.Product).FirstOrDefaultAsync().ConfigureAwait(false); if (bid == null) { return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = BidNotFoundFailString }); } if (!await this.isValidJoinAsync(bid.Product, bidBuyerJoinRequest.BuyerId)) { // new Response Error Code return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = "Buyer already participates in an active bid with this product" }); } bid.CurrentParticipancies.Add(_mapper.Map <ParticipancyEntity>(bidBuyerJoinRequest)); bid.UnitsCounter += bidBuyerJoinRequest.NumOfUnits; try { _context.Bids.Update(bid); await _context.SaveChangesAsync().ConfigureAwait(false); } catch (Exception ex) { return(new Response() { IsOperationSucceeded = false, SuccessOrFailureMessage = ex.Message }); } return(new Response() { IsOperationSucceeded = true, SuccessOrFailureMessage = this.getSuccessMessage() }); }
public Task <Response> AddBuyer(BidBuyerJoinRequest bidBuyerJoinRequest) { throw new NotImplementedException(); }