Ejemplo n.º 1
0
        public List <UserOffer> GetSupplierOffers(OfferCriteria offerCriteria, int user_id)
        {
            OfferQuery offerQuery = new OfferQuery(language);
            OrderQuery orderQuery = new OrderQuery(language);

            System.Data.DataTable OfferDT = new System.Data.DataTable();


            switch (offerCriteria.offerType)
            {
            case (int)OfferType.offerNotAccepted:
                OfferDT = conn_db.ReadTable(offerQuery.GetsupplierOffersUnConfirmed(user_id, language));
                break;

            case (int)OfferType.offerAccepted:
                OfferDT = conn_db.ReadTable(offerQuery.GetsupplierOffersConfirmed(user_id, language));
                break;

            case (int)OfferType.offerIsFixing:
                OfferDT = conn_db.ReadTable(offerQuery.GetsupplierOffersStart(user_id, language));
                break;

            case (int)OfferType.offerFinishFixing:
                OfferDT = conn_db.ReadTable(offerQuery.GetsupplierOffersfinish(user_id, language));
                break;

            default:
                OfferDT = conn_db.ReadTable(offerQuery.GetsupplierOffersUnConfirmed(user_id, language));
                break;
            }


            UserOffer        userOffer;
            List <UserOffer> userOffers = new List <UserOffer>();

            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)
            {
                userOffer = new UserOffer();
                userOffer.ORDERTYPE_NAME = dataRow["ORDERTYPE_NAME"] is DBNull ? "" : dataRow["ORDERTYPE_NAME"].ToString();
                userOffer.colorname      = dataRow["COLOR_NAME"] is DBNull ? "" : dataRow["COLOR_NAME"].ToString();

                userOffer.firstName = dataRow["FIRSTNAME"].ToString();
                userOffer.lastName  = dataRow["LASTNAME"].ToString();
                userOffer.carImage  = dataRow["CARIMAGE"].ToString();
                userOffer.userImage = dataRow["userIMAGE"].ToString();

                if (language == Messages.language.ar.ToString())
                {
                    userOffer.brandname = dataRow["BRANDNAME_AR"].ToString();
                    userOffer.modelname = dataRow["MODELNAME_AR"].ToString();
                }
                else
                {
                    userOffer.brandname = dataRow["BRANDNAME_EN"].ToString();
                    userOffer.modelname = dataRow["MODELNAME_EN"].ToString();
                }


                userOffer.OFFER_ID      = dataRow["OFFER_ID"] is DBNull ? 0 : Convert.ToInt32(dataRow["OFFER_ID"]);
                userOffer.ORDER_ID      = dataRow["ORDER_ID"] is DBNull ? 0 : Convert.ToInt32(dataRow["ORDER_ID"]);
                userOffer.PRICE         = dataRow["PRICE"] is DBNull ? 0 : Convert.ToDouble(dataRow["PRICE"]);
                userOffer.SUPPLIER_Name = dataRow["SUPPLIER_Name"] is DBNull ? "" : dataRow["SUPPLIER_Name"].ToString();
                userOffer.timeValue     = dataRow["timeValue"] is DBNull ? 0 : Convert.ToInt32(dataRow["timeValue"]);
                userOffer.timeFlag      = dataRow["timeFlag"] is DBNull ? 0 : Convert.ToInt32(dataRow["timeFlag"]);
                userOffer.supplierImage = dataRow["supplierImage"] is DBNull ? "" : dataRow["supplierImage"].ToString();
                userOffer.PHONENUMBER   = dataRow["PHONENUMBER"] is DBNull ? "" : dataRow["PHONENUMBER"].ToString();
                userOffer.lat           = dataRow["LOCATIONX"] is DBNull ? 0 : Convert.ToDouble(dataRow["LOCATIONX"]);
                userOffer.lng           = dataRow["LOCATIONY"] is DBNull ? 0 : Convert.ToDouble(dataRow["LOCATIONY"]);
                userOffer.Rating        = dataRow["RATING"] is DBNull ? 0 : Convert.ToDouble(dataRow["RATING"]);
                userOffer.offerStatus   = dataRow["offer_status"] is DBNull ? 0 : Convert.ToInt32(dataRow["offer_status"]);

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

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

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

                userOffers.Add(userOffer);
            }
            return(userOffers);
        }