public IActionResult AcceptBid(SubContractorBid bid) { var currentUser = GetCurrentUserProfile(); //Verify that the POST request is coming from= the project owner if (currentUser.contractor.Id == bid.SubContractorId) { bid.SubAccepted = DateTime.Now; _bidRepository.AcceptBid(bid); return(Ok(CreatedAtAction("Get", new { id = bid.Id }, bid))); } return(Unauthorized()); }
public DatabaseCode AcceptBid(int bidID, Guid userID) { int productID = bidRepository.GetProductIDForBid(bidID); ProductModel product = productService.GetProduct(productID); if (productService.IsProductCreatedByUser(userID, productID)) { var bidAcceptedResult = bidRepository.AcceptBid(bidID); if (bidAcceptedResult.dbCode == DatabaseCode.Updated) { notificationService.Insert(new NotificationModel() { Information = string.Format("Your bid for product {0} has been accepted! You will be contacted shortly by the seller.", product.ReferenceForView), ReceivingUserID = bidAcceptedResult.userID, AdditionalInformation = JsonConvert.SerializeObject(new { productID }) }); (List <Bid> list, DatabaseCode dbCode)bidsRejected = bidRepository.DeclineBidsForProduct(userID, bidID, productID); if (bidsRejected.dbCode == DatabaseCode.Updated) { foreach (var item in bidsRejected.list) { notificationService.Insert(new NotificationModel() { Information = string.Format("Your bid for product {0} has been declined and the product has been awarded.", product.ReferenceForView), ReceivingUserID = item.userid, AdditionalInformation = JsonConvert.SerializeObject(new { productID, bidID = item.id }) }); } } return(bidsRejected.dbCode); } return(DatabaseCode.Error); } return(DatabaseCode.NotAllowed); }