示例#1
0
        public ActionResult Read_Proposals([DataSourceRequest] DataSourceRequest request, int bidProposalId)
        {
            var s = _transportBidQuotationHeaderService.FindById(bidProposalId);
            int bidID = s.Bid.BidID;
            int regionID = s.AdminUnit.AdminUnitID;
            int transporterID = s.Transporter.TransporterID;

            var bid = _bidService.FindById(bidID) ?? null;

            var result = new List<PriceQuotationDetail>();

            if (bid != null)
            {
                var bidPlanDetail =
                    _transportBidPlanDetailService.FindBy(t => t.Destination.AdminUnit2.AdminUnit2.AdminUnitID == regionID
                                                            && t.BidPlanID == bid.TransportBidPlanID
                    /*&& t.Quantity > 0*/);
                var df = (from planDetail in bidPlanDetail
                          group planDetail by new
                          {
                              planDetail.DestinationID,
                              planDetail.SourceID
                          }
                              into gr
                              select gr
                          );

                var detailPlans = df.Select(d => d.ToList()).Select(er => er.FirstOrDefault()).ToList();

                foreach (var transportBidPlanDetail in detailPlans)
                {
                    var pdetail = transportBidPlanDetail;

                    var detail = _transportBidQuotationService.FindBy(t => t.BidID == bidID
                                                                    && t.SourceID == pdetail.SourceID
                                                                    && t.DestinationID == pdetail.DestinationID
                                                                    && t.TransporterID == transporterID).FirstOrDefault();
                    if (detail != null)
                    {
                        var t = new PriceQuotationDetail
                        {
                            SourceWarehouse = detail.Hub.Name,
                            Zone = detail.AdminUnit.AdminUnit2.Name,
                            Woreda = detail.AdminUnit.Name,
                            Tariff = detail.Tariff,
                            Remark = detail.Remark,
                            //
                            BidID = detail.BidID,
                            DestinationID = detail.DestinationID,
                            SourceID = detail.SourceID,
                            HeaderId = bidProposalId,
                            TransportBidQuotationID = detail.TransportBidQuotationID * 10 + transporterID,
                            //
                            TransporterID = detail.TransporterID

                        };
                        result.Add(t);
                        continue;

                    }

                    var n = new PriceQuotationDetail()
                    {
                        SourceWarehouse = transportBidPlanDetail.Source.Name,
                        Zone = transportBidPlanDetail.Destination.AdminUnit2.Name,
                        Woreda = transportBidPlanDetail.Destination.Name,
                        Tariff = 0,
                        Remark = String.Empty,
                        //
                        BidID = bidID,
                        DestinationID = transportBidPlanDetail.DestinationID,
                        SourceID = transportBidPlanDetail.SourceID,
                        HeaderId = bidProposalId,
                        //
                        TransportBidQuotationID = transportBidPlanDetail.TransportBidPlanDetailID * 10 + transporterID,
                        TransporterID = transporterID
                    };
                    result.Add(n);
                }
            }

            return Json(result.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
示例#2
0
        public ActionResult ReadWoredasWithOutBidOffer([DataSourceRequest] DataSourceRequest request, int bidID, int regionID)
        {
            var planID = _bidService.FindById(bidID).TransportBidPlanID;

            var bidPlanDetail =
                _transportBidPlanDetailService.FindBy(t => t.Destination.AdminUnit2.AdminUnit2.AdminUnitID == regionID
                                                           && t.BidPlanID == planID);
            var df = (from planDetail in bidPlanDetail
                      group planDetail by new
                      {
                          planDetail.DestinationID,
                          planDetail.SourceID
                      }
                          into gr
                          select gr
                      );

            var detailPlans = df.Select(d => d.ToList()).Select(er => er.FirstOrDefault()).ToList();

            var result = new List<PriceQuotationDetail>();

            foreach (var transportBidPlanDetail in detailPlans)
            {
                var pdetail = transportBidPlanDetail;

                var detail = _transportBidQuotationService.FindBy(t => t.BidID == bidID
                                                                && t.SourceID == pdetail.SourceID
                                                                && t.DestinationID == pdetail.DestinationID).FirstOrDefault();
                if(detail==null)
                {
                    var n = new PriceQuotationDetail()
                    {
                        SourceWarehouse = pdetail.Source.Name,
                        Zone = pdetail.Destination.AdminUnit2.Name,
                        Woreda = pdetail.Destination.Name,
                        Tariff = 0,
                        Remark = String.Empty,
                        BidID = bidID,
                        DestinationID = pdetail.DestinationID,
                        SourceID = pdetail.SourceID
                    };
                    result.Add(n);
                }
            }
            return Json(result.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
        public ActionResult SaveBidProposals([DataSourceRequest] DataSourceRequest request, PriceQuotationDetail bidProposal)
        {
            if (bidProposal != null && ModelState.IsValid)
            {
                //var detail = _transportBidQuotationService.FindById(bidProposal.TransportBidQuotationID);
                var detai = _transportBidQuotationService.FindBy(t =>
                                                                    t.BidID == bidProposal.BidID
                                                                 && t.SourceID == bidProposal.SourceID
                                                                 && t.DestinationID == bidProposal.DestinationID
                                                                 && t.TransporterID == bidProposal.TransporterID);
                var detail = detai.FirstOrDefault();

                if (detail != null)
                {
                    //detail.TransportBidQuotationID = bidProposal.TransportBidQuotationID;
                    detail.BidID = bidProposal.BidID;
                    detail.TransportBidQuotationHeaderID = bidProposal.HeaderId;
                    detail.TransporterID = bidProposal.TransporterID;
                    detail.SourceID = bidProposal.SourceID;
                    detail.DestinationID = bidProposal.DestinationID;
                    detail.Tariff = bidProposal.Tariff;
                    detail.Remark = bidProposal.Remark ?? String.Empty;
                    detail.IsWinner = false;
                    _transportBidQuotationService.UpdateTransportBidQuotation(detail);

                }

                else
                {
                    var newProposal = new TransportBidQuotation();
                    //newProposal.TransportBidQuotationID = bidProposal.TransportBidQuotationID;
                    newProposal.BidID = bidProposal.BidID;
                    newProposal.TransportBidQuotationHeaderID = bidProposal.HeaderId;
                    newProposal.TransporterID = bidProposal.TransporterID;
                    newProposal.SourceID = bidProposal.SourceID;
                    newProposal.DestinationID = bidProposal.DestinationID;
                    newProposal.Tariff = bidProposal.Tariff;
                    newProposal.Remark = bidProposal.Remark ?? String.Empty;
                    newProposal.IsWinner = false;
                    _transportBidQuotationService.AddTransportBidQuotation(newProposal);
                }

                int region = _adminUnitService.FindById(bidProposal.DestinationID).AdminUnit2.AdminUnit2.AdminUnitID;
                var changeable = _transportBidQuotationService.FindBy(t =>
                                                                     t.BidID == bidProposal.BidID
                    /* && t.Destination.AdminUnit2.AdminUnit2.AdminUnitID == region*/);

                //var changeable = _transportBidQuotationService.FindBy(t =>
                //                                                     t.BidID == bidProposal.BidID
                //                                                     && t.Destination.AdminUnit2.AdminUnit2.AdminUnitID == region);

                foreach (var transportBidQuotation in changeable)
                {
                    transportBidQuotation.IsWinner = false;
                    _transportBidQuotationService.UpdateTransportBidQuotation(transportBidQuotation);
                }
            }

            return Json(new[] { bidProposal }.ToDataSourceResult(request, ModelState));
            //return Json(ModelState.ToDataSourceResult());
        }