public void AddNewAuction(string userEmail, Auction item) { var owner = db.Users.Where(e => e.Email == userEmail).FirstOrDefault(); if (owner == null) throw new FaultException("User not found!"); item.AutionStatus = AuctionStatus.New; item.Owner = owner; item.IsApproval = false; item.StartTime = DateTime.Now; item.EndTime = DateTime.Now; item.AutionStatus = AuctionStatus.New; db.AutionProducts.Add(item); db.SaveChanges(); }
public Auction TranslateEntityAuctionProduct(Auction auction) { if (auction == null) return null; Auction newItem = new Auction(); newItem.Id = auction.Id; newItem.Owner = auction.Owner; newItem.Name = auction.Name; newItem.Price = auction.Price; newItem.AuctionComments = auction.AuctionComments; newItem.IsApproval = auction.IsApproval; newItem.PhotoUrl = auction.PhotoUrl; newItem.Category = auction.Category; newItem.StartTime = auction.StartTime; newItem.EndTime = auction.EndTime; newItem.AutionStatus = auction.AutionStatus; newItem.BestBid = auction.BestBid; newItem.Description = auction.Description; newItem.Bids = new List<Bid>(); List<Bid> tmp = auction.Bids.OrderByDescending(e => e.Price).ToList(); foreach (Bid bid in tmp) { var newBid = db.Bids.Include("User").Where(e => e.Id == bid.Id).FirstOrDefault(); newItem.Bids.Add(newBid); } newItem.AuctionComments = new List<AuctionComment>(); List<AuctionComment> tmpCmt = auction.AuctionComments.OrderByDescending(e => e.Time).ToList(); foreach (AuctionComment cmt in tmpCmt) { var newCmt = db.AuctionComments.Include("CommentUser").Where(e => e.Id == cmt.Id).FirstOrDefault(); newItem.AuctionComments.Add(newCmt); } return newItem; }