public bool DeleteTransportBidQuotationHeader(TransportBidQuotationHeader transportBidQuotationHeader)
 {
     if (transportBidQuotationHeader == null) return false;
     _unitOfWork.TransportBidQuotationHeaderRepository.Delete(transportBidQuotationHeader);
     _unitOfWork.Save();
     return true;
 }
 public bool UpdateTransportBidQuotationHeader(TransportBidQuotationHeader item)
 {
     if (item == null) return false;
     _unitOfWork.TransportBidQuotationHeaderRepository.Edit(item);
     _unitOfWork.Save();
     return true;
 }
 public bool AddTransportBidQuotationHeader(TransportBidQuotationHeader item)
 {
     _unitOfWork.TransportBidQuotationHeaderRepository.Add(item);
     _unitOfWork.Save();
     return true;
 }
        public ActionResult Edit_proposal(TransportBidQuotationHeader proposal)
        {
            ViewBag.BIDS = new SelectList(_bidService.GetAllBid(), "BidID", "BidNumber");
            ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2), "AdminUnitID", "Name");
            ViewBag.Transporters = new SelectList(_transporterService.GetAllTransporter(), "TransporterID", "Name");

            if (ModelState.IsValid)
            {
                var e = _transportBidQuotationHeaderService.FindById(proposal.TransportBidQuotationHeaderID);

            //                e.BidBondAmount = proposal.BidBondAmount;

                _transportBidQuotationHeaderService.UpdateTransportBidQuotationHeader(e);
                ModelState.AddModelError("Success", @"Proposal updated successfully");
                return RedirectToAction("BidProposalHeader");
            }
               return View(proposal);
        }
        public ActionResult Create(TransportBidQuotationHeader bidProposal)
        {
            ViewBag.BIDS = new SelectList(_bidService.GetAllBid(), "BidID", "BidNumber");
            ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2), "AdminUnitID", "Name");
            ViewBag.Transporters = new SelectList(_transporterService.GetAllTransporter(), "TransporterID", "Name");

            if (ModelState.IsValid)
            {

                var exisiting = _transportBidQuotationHeaderService.FindBy(m => m.BidId == bidProposal.BidId
                                                                && m.TransporterId == bidProposal.TransporterId
                                                                && m.RegionID == bidProposal.RegionID);

                if (exisiting.Count==0)
                {
                    bidProposal.Status = 1;
                    bidProposal.BidQuotationDate = DateTime.Now;
                    _transportBidQuotationHeaderService.AddTransportBidQuotationHeader(bidProposal);
                    TempData["CustomMessage"] = "Bid proposal successfully created";
                    return RedirectToAction("BidProposalHeader");
                }
                else
                {
                    TempData["CustomError"] = "Such a bid proposal has already been proposed";
                }

            }
            return RedirectToAction("BidProposalHeader");
        }
 public ActionResult Create()
 {
     ViewBag.BIDS = new SelectList(_bidService.FindBy(m=>m.StatusID== (int)BidStatus.Approved || m.StatusID==(int)BidStatus.Active), "BidID", "BidNumber");//gets approved and active bids
     ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2), "AdminUnitID", "Name");
     ViewBag.Transporters = new SelectList(_transporterService.GetAllTransporter(), "TransporterID", "Name");
     var header = new TransportBidQuotationHeader();
     var user = (UserIdentity)System.Web.HttpContext.Current.User.Identity;
     header.EnteredBy = user.FullName;
     return View(header);
 }
        // BidId should also be used to filter the data
        public List<TransportBidQuotation> GetSecondWinner(int transporterId, int woredaId)
        {
            var secondTransporter = 2;
            const int firstTransporter = 1;
            var bidQoutation =
                _unitOfWork.TransportBidQuotationRepository.FindBy(
                    t => t.DestinationID == woredaId && t.TransporterID != transporterId);
            var secondWinner = new List<TransportBidQuotation>();
            var winnerTransporter = new List<TransportBidQuotation>();

            if (bidQoutation.Count > 0)
            {
                if (bidQoutation.Count == 1)
                    secondTransporter = 1;

                secondWinner = bidQoutation
                    .GroupBy(g => g.TransportBidQuotationID)
                    .OrderByDescending(o => o.Key)
                    .Select(s => new {Qoutation = s.ToList()})
                    .ToList()[secondTransporter - 1].Qoutation;

            }

            //DRMFSS
            var drmfssTransporters = GetDrmfssTransporters().Where(m=>m.TransporterID!=transporterId);
            foreach (var transporter in drmfssTransporters)
            {

                var drmfssTransporter = new TransportBidQuotation { TransporterID = transporter.TransporterID};
                var drmfssTransporterHeaderInfo = new TransportBidQuotationHeader()
                                                      {
                                                          TransporterId = transporter.TransporterID,
                                                          Transporter = _unitOfWork.TransporterRepository.FindById(transporter.TransporterID)
                                                      };

                drmfssTransporter.TransportBidQuotationHeader = drmfssTransporterHeaderInfo;
                secondWinner.Add(drmfssTransporter);
            }

            return secondWinner;
        }