Exemple #1
0
    public void UpdateResponseDelay(int action, ClosedProject cp, SidejobEntities context)
    {
        if (action == 0) return;
        switch (action)
        {
            case 1:
                var rd = new ResponseDelay
                             {
                                 BidderID = BidderID,
                                 CurrencyID = cp.CurrencyID,
                                 BidderRole = BidderRole,
                                 DateFinished = DateTime.UtcNow.Date,
                                 HighestBid = cp.HighestBid,
                                 PosterID = PosterID,
                                 ReminderLevel = 1,
                                 Status = 3
                             };
                context.AddToResponseDelays(rd);
                context.SaveChanges();
                break;

            case 2:
                var rd2 = (from c in context.ResponseDelays
                           where c.BidderID == BidderID
                                 && c.PosterID == PosterID && c.Status == 3
                           select c).FirstOrDefault();
                if (rd2 != null)
                {
                    rd2.Status = 4;
                    context.SaveChanges();
                }
                break;

            case 3:
                ArchiveProject(context);
                var rd3 = (from c in context.ResponseDelays
                           where c.BidderID == BidderID
                                 && c.PosterID == PosterID
                           select c).FirstOrDefault();
                if (rd3 != null)
                {
                    context.DeleteObject(rd3);
                    context.DeleteObject(cp);
                    var p = (from c in context.Projects
                             where c.ProjectID == ProjectID
                             select c).FirstOrDefault();
                    if (p != null)
                    {
                        p.StatusInt = 6;
                        context.SaveChanges();
                    }

                }
                break;
        }
    }
    /////////////////////ADD TO CLOSED PROJECT/////////////////////////
    /////////////////////ADD TO RESPONSE DELAY/////////////////////////
    public void AddToResponseDelay(int projectId, ClosedProject cp)
    {
        //Added the new record with status = 3
        //because the first time it will be for bidder

        //Check if exist already in the tables
        using (var context = new SidejobEntities())
        {
            var rd = (from c in context.ResponseDelays
                      where c.ProjectID == projectId
                      select c).FirstOrDefault();
            if (rd == null)
            {
                var newResponseDelay = new  SidejobModel.ResponseDelay
                                           {
                                               ProjectID = projectId,
                                               DateFinished = DateTime.Now.Date,
                                               PosterID = cp.PosterID,
                                               PosterRole = cp.PosterRole,
                                               BidderID = cp.BidderID,
                                               BidderRole = cp.BidderRole,
                                               HighestBid = cp.HighestBid,
                                               CurrencyID = cp.CurrencyID,
                                               Status = 3
                                           };
                context.AddToResponseDelays(newResponseDelay);
                context.SaveChanges();
            }
        }
    }