示例#1
0
        public List <OfferDTO> GetOffers(OfferCriteria offerCriteria)
        {
            OfferQuery offerQuery = new OfferQuery(language);

            System.Data.DataTable OfferDT = conn_db.ReadTable(offerQuery.GetOffersWithCondition(offerCriteria.filters, offerCriteria.sort));

            OfferDTO        offersDTO;
            List <OfferDTO> Offers = new List <OfferDTO>();

            if (OfferDT.Rows.Count == 0)
            {
                throw new EmptyViewException(language, Messages.GetMessage(language, TypeM.OFFER, offerM.OFFER_NOT_FOUND));
            }

            foreach (System.Data.DataRow dataRow   in OfferDT.Rows)
            {
                offersDTO               = new OfferDTO();
                offersDTO.OFFER_ID      = dataRow["OFFER_ID"] is DBNull ? 0 : Convert.ToInt32(dataRow["OFFER_ID"]);
                offersDTO.ORDER_ID      = dataRow["ORDER_ID"] is DBNull ? 0 : Convert.ToInt32(dataRow["ORDER_ID"]);
                offersDTO.PRICE         = dataRow["PRICE"] is DBNull ? 0 : Convert.ToDouble(dataRow["PRICE"]);
                offersDTO.SUPPLIER_Name = dataRow["SUPPLIER_Name"] is DBNull ? "" : dataRow["SUPPLIER_Name"].ToString();
                offersDTO.timeValue     = dataRow["timeValue"] is DBNull ? 0 : Convert.ToInt32(dataRow["timeValue"]);
                offersDTO.timeFlag      = dataRow["timeFlag"] is DBNull ? 0 : Convert.ToInt32(dataRow["timeFlag"]);
                offersDTO.supplierImage = dataRow["supplierImage"] is DBNull ? "" : dataRow["supplierImage"].ToString();
                offersDTO.PHONENUMBER   = dataRow["PHONENUMBER"] is DBNull ? "" : dataRow["PHONENUMBER"].ToString();
                offersDTO.lat           = dataRow["LOCATIONX"] is DBNull ? 0 : Convert.ToDouble(dataRow["LOCATIONX"]);
                offersDTO.lng           = dataRow["LOCATIONY"] is DBNull ? 0 : Convert.ToDouble(dataRow["LOCATIONY"]);
                offersDTO.Rating        = dataRow["RATING"] is DBNull ? 0 : Convert.ToDouble(dataRow["RATING"]);
                offersDTO.offerStatus   = dataRow["offer_status"] is DBNull ? 0 : Convert.ToInt32(dataRow["offer_status"]);

                offersDTO.RateType   = new Enums().checkRateTypeWords(offersDTO.Rating, language);
                offersDTO.RateTypeId = (int)new Enums().checkRateType(offersDTO.Rating);

                if (offerCriteria.lat == 0 || offerCriteria.lng == 0 || offersDTO.lat == 0 || offersDTO.lng == 0)
                {
                    offersDTO.DISTANCE = 0;
                    offersDTO.time     = "0";
                }

                else
                {
                    double distanceMiles = Math.Sqrt(
                        Math.Pow((offerCriteria.lat - offersDTO.lat) * 69, 2) +
                        Math.Pow((offerCriteria.lng - offersDTO.lng) * 69.172, 2));
                    offersDTO.DISTANCE = Math.Round(distanceMiles * 1.60934, 2);
                    offersDTO.time     = new ServicesRepository(language).getTime(offerCriteria.lat + "," + offerCriteria.lng, offersDTO.lat + "," + offersDTO.lng);
                }



                Offers.Add(offersDTO);
            }



            return(Offers);
        }