public async Task <ActionResult <AuctionReadDTO> > GetAuctionById(string id) { var auction = await _auctRepo.GetAuctionById(id); if (auction != null) { var auctionDTO = new AuctionReadDTO { AuctionId = auction.AuctionId, SellerId = auction.SellerId, BuyerId = auction.BuyerId, CardId = auction.CardId, PriceSold = (double)auction.PriceSold, SellDate = (DateTime)auction.SellDate, //for auction details PriceListed = auction.PriceListed, BuyoutPrice = auction.BuyoutPrice, NumberBids = (int)auction.NumberBids, SellType = auction.SellType, ExpDate = auction.ExpDate }; return(Ok(auctionDTO)); //return auction } return(NotFound()); //Return 404 if no auction found }
public async Task <ActionResult <AuctionCreateDTO> > Post(AuctionCreateDTO newAuction) { //check if auction exists var check = await _auctRepo.GetAuctionById(newAuction.AuctionId); if (check == null) { //for repo var createdAuction = new AppAuction() { // auction AuctionId = await _auctRepo.IdGen(), SellerId = newAuction.SellerId, BuyerId = null, CardId = newAuction.CardId, PriceSold = 0, //SellDate = (DateTime)newAuction.SellDate, //auction details PriceListed = newAuction.PriceListed, BuyoutPrice = newAuction.BuyoutPrice, NumberBids = 0, SellType = "", ExpDate = newAuction.ExpDate }; await _auctRepo.CreateAuction(createdAuction); //for response var auctionReadDTO = new AuctionReadDTO { //auction AuctionId = createdAuction.AuctionId, SellerId = createdAuction.SellerId, //BuyerId = createdAuction.BuyerId, CardId = createdAuction.CardId, //PriceSold = (double)createdAuction.PriceSold, //SellDate = (DateTime)createdAuction.SellDate, //auction details PriceListed = createdAuction.PriceListed, BuyoutPrice = createdAuction.BuyoutPrice, //NumberBids = (int)createdAuction.NumberBids, //SellType = createdAuction.SellType, ExpDate = createdAuction.ExpDate }; return(CreatedAtAction(nameof(GetAuctionById), new { id = auctionReadDTO.AuctionId }, auctionReadDTO)); //201 new auction created } return(Conflict()); //auction already exists and cant be created }