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 }
public async Task <ActionResult <AuctionCreateDTO> > UpdateAuctionById(string id, AuctionCreateDTO newAuction) { var check = await _auctRepo.GetAuctionById(id); if (check != null) { var auction = new AppAuction { AuctionId = newAuction.AuctionId, SellerId = newAuction.SellerId, BuyerId = newAuction.BuyerId, CardId = newAuction.CardId, PriceSold = (double)newAuction.PriceSold, SellDate = (DateTime)newAuction.SellDate, //for auction details PriceListed = newAuction.PriceListed, BuyoutPrice = newAuction.BuyoutPrice, NumberBids = (int)newAuction.NumberBids, SellType = newAuction.SellType, ExpDate = newAuction.ExpDate }; bool result = await _auctRepo.UpdateAuction(id, auction); if (result) { return(NoContent()); //update successfull } else { return(BadRequest()); //something wrong with update } } return(NotFound()); //Return 404 if no auction details found }