public JsonResult AddAuctinon(AuctionModel auctionModel) { var auction = new Auction(); auction.Caption = auctionModel.Caption; auction.Price = auctionModel.Price; auction.Description = auctionModel.Description; auction.Bids = new List<Bids>(); auction.LatestBid = 0; _auctionService.SaveOrUpdate(auction); return new JsonResult { Data = Helpers.AuctionModelFromEntiry(auction), JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }
public static AuctionModel AuctionModelFromEntiry(Auction auction) { var model = new AuctionModel() { Id = auction.Id, Caption = auction.Caption, Description = auction.Description, Price = auction.Price, Created = DateTime.Parse(auction.Created), LatestBid = auction.LatestBid, Bids = (from b in auction.Bids select new BidModel() { Id = b.Id, Amount = b.Amount, Created = DateTime.Parse(b.Created), AuctionId = auction.Id }).ToList() }; return model; }