Beispiel #1
0
        public ActionResult ComposeGC(int projectId)
        {
            int companyId = _service.GetUserProfile(_security.GetUserId(User.Identity.Name)).CompanyId;

            // get invitation to project
            Invitation invite = _service.GetInvites(projectId, companyId).SingleOrDefault();

            // if passed bid date, block changes
            if (invite.BidPackage.BidDateTime < DateTime.Now)
            {
                return RedirectToRoute("Project_default", new { controller = "Bid", action = "ReviewGC", projectId = projectId });
            }

            GCBidEditModel viewModel = new GCBidEditModel();

            // if user has an invite
            if (invite != null)
            {
                viewModel.ProjectId = projectId;
                viewModel.ProjectName = _service.GetProject(projectId).Title;
                viewModel.BidPackageId = invite.BidPackageId;
                IEnumerable<BaseBid> baseBids = _service.GetCompanyBaseBidsForProject(companyId, projectId);

                // FIXME: need to account for scope changes after a draft is saved
                // if there isn't a saved draft
                if (baseBids == null || baseBids.Count() == 0)
                {
                    viewModel.BaseBids = _service.GetBidPackageScopes(invite.BidPackageId)
                        .OrderBy(s => s.CsiNumber)
                        .Select(s => new BaseBidEditItem
                        {
                            ScopeDescription = s.CsiNumber + " " + s.Description,
                            ScopeId = s.Id
                        });
                }
                else
                {
                    viewModel.BaseBids = baseBids
                        .OrderBy(b => b.Scope.CsiNumber)
                        .Select(b => new BaseBidEditItem
                    {
                        ScopeDescription = b.Scope.CsiNumber + " " + b.Scope.Description,
                        ScopeId = b.ScopeId,
                        Amount = b.Amount
                    });
                }
                return View(viewModel);
            }
            else
            {
                throw new Exception("company does not have invite to this project");
            }
        }
Beispiel #2
0
        public ActionResult ComposeGC(GCBidEditModel viewModel)
        {
            int companyId = _service.GetUserProfile(_security.GetUserId(User.Identity.Name)).CompanyId;

            if (ModelState.IsValid)
            {

                // get invitation to project
                Invitation invite = _service.GetInvites(viewModel.ProjectId, companyId).SingleOrDefault();

                // if passed bid date, block changes
                if (invite.BidPackage.BidDateTime < DateTime.Now)
                {
                    throw new Exception("passed bid date");
                }

                IEnumerable<BaseBid> baseBids = viewModel.BaseBids.Select(b => new BaseBid { Amount = b.Amount, ProjectId = viewModel.ProjectId, SentToId = companyId, ScopeId = b.ScopeId });
                IEnumerable<ComputedBid> computedBids = viewModel.BaseBids.Select(b => new ComputedBid { RiskFactor = 1.00m, BidPackageId = viewModel.BidPackageId, SentToId = companyId, ScopeId = b.ScopeId });

                Dictionary<int, IEnumerable<ComputedBid>> computedBidDic = new Dictionary<int, IEnumerable<ComputedBid>>();
                computedBidDic.Add(viewModel.BidPackageId, computedBids);

                switch (viewModel.btn)
                {
                    case "Save":
                        if (_service.SaveDraft(baseBids, computedBidDic))
                        {
                            return View(viewModel);
                        }
                        else
                        {
                            Util.MapValidationErrors(_service.ValidationDic, this.ModelState);
                            return View(viewModel);
                        }
                    case "Submit":
                        if (_service.SaveFinalBid(baseBids, computedBidDic, companyId, DateTime.Now))
                        {
                            return RedirectToRoute("Project_default", new { controlle = "Bid", action = "ReviewGC", projectId = viewModel.ProjectId });
                        }
                        else
                        {
                            Util.MapValidationErrors(_service.ValidationDic, this.ModelState);
                            return View(viewModel);
                        }
                    default:
                        throw new Exception("invalid action");
                }

            }
            else
            {
                return View(viewModel);
            }
        }