Exemple #1
0
        public BidModel MakeBidApiReady(OpenAuctionBidViewModel viewModel, string bidder)
        {
            BidModel model = new BidModel
            {
                Summa     = viewModel.BidPrice.ToString(),
                AuktionID = viewModel.AuctionId.ToString(),
                Budgivare = bidder
            };

            return(model);
        }
        //TODO Fixa validering av bud (client(isf förklarat), annars själv i bussLayer)
        public IActionResult MakeBid(OpenAuctionBidViewModel newBid)
        {
            if (ModelState.IsValid)
            {
                bool currentBidIsValid = _businessService.GetBidIsValid(newBid.BidPrice, newBid.AuctionId);

                if (currentBidIsValid == true)
                {
                    string bidder = _userService.GetCurrentUserName();

                    BidModel model = _businessService.MakeBidApiReady(newBid, bidder);

                    HttpResponseMessage response = _businessService.MakeBid(model);

                    return(RedirectToAction("ViewAuctionDetails", "Auction", new { auctionId = newBid.AuctionId, message = "Bid has successfully been made" }));
                }
                else
                {
                    return(RedirectToAction("ViewAuctionDetails", "Auction", new { auctionId = newBid.AuctionId, message = "Bid is too low" }));
                }
            }

            return(View(newBid));
        }