public void AddToClosedProject(int projectId) { int bidderid = 0; using (var context = new SidejobEntities()) { var cp = (from c in context.ClosedProjects where c.ProjectID == projectId select c).FirstOrDefault(); if (cp != null) { var bidder = (from p in context.Projects where p.ProjectID == projectId select p).FirstOrDefault(); if (bidder != null) { if (bidder.HighestBidderID != null) { bidderid = (int)bidder.HighestBidderID; } } var newclosedproject = from p in context.Projects join b in context.Bids on p.ProjectID equals b.ProjectID where p.ProjectID == projectId && b.BidderID == bidderid select new ClosedProject { ProjectID = projectId, DateFinished = DateTime.Now.Date, PosterID = p.PosterID, PosterRole = p.PosterRole, BidderID = p.HighestBidderID, BidderRole = b.BidderRole, HighestBid = p.HighestBid, CurrencyID = b.CurrencyID, Status = 3 }; context.AddToClosedProjects((ClosedProject)newclosedproject); context.SaveChanges(); GetBidderPosterProjectProperties(projectId, 0, (ClosedProject)newclosedproject); } } }
/////////////////////ADD TO CLOSED PROJECT///////////////////////// public void AddToClosedProject(int projectId) { int bidderid = 0; using (var context = new SidejobEntities()) { var cp = (from c in context.ClosedProjects where c.ProjectID == projectId select c).FirstOrDefault(); if (cp == null) { var bidder = (from p in context.Projects where p.ProjectID == projectId select p).FirstOrDefault(); if (bidder != null) { if (bidder.HighestBidderID != null) { bidderid = (int)bidder.HighestBidderID; } } var chosenproject = (from p in context.Projects where p.ProjectID == projectId select p).FirstOrDefault(); var chosenbid = (from p in context.Bids where p.BidderID == bidderid select p).FirstOrDefault(); if (chosenproject != null && chosenbid != null) { var newcp = new ClosedProject { ProjectID = projectId, DateFinished = DateTime.UtcNow.Date, PosterID = chosenproject.PosterID, PosterRole = chosenproject.PosterRole, BidderID = chosenproject.HighestBidderID, BidderRole = chosenbid.BidderRole, HighestBid = chosenproject.HighestBid, CurrencyID = chosenbid.CurrencyID, Status = 3 }; context.AddToClosedProjects(newcp); context.SaveChanges(); GetBidderPosterProjectProperties(projectId, 0, newcp); } } } }