Example #1
0
        public Domain.Entities.Order.OrdersDetails   GetOrderDetails(int user_id, int order_id, double lat, double lng, int offer_id)
        {
            OrderQuery orderQuery = new OrderQuery(language);
            OfferQuery offerQuery = new OfferQuery(language);

            System.Data.DataTable OrderDT = conn_db.ReadTable(orderQuery.GetRequestByOrder_id(order_id, language));
            int orderStatus = 0;

            if (OrderDT.Rows.Count > 0)
            {
                orderStatus = OrderDT.Rows[0]["order_status"] is DBNull ?  0:Convert.ToInt32(OrderDT.Rows[0]["order_status"]);
            }

            System.Data.DataTable OrderDetailsAssign = conn_db.ReadTable(offerQuery.GetOrderDetailsAssigns(order_id));
            System.Data.DataTable OfferDT            = new System.Data.DataTable();

            if (orderStatus == (int)Enums.orderStatus.UNCONFIRMED)
            {
                OfferDT = conn_db.ReadTable(offerQuery.GetOffertempOfferByOffer_id(offer_id));
            }
            else
            {
                OfferDT = conn_db.ReadTable(offerQuery.GetOfferDetailsByOrderId(order_id));
            }

            UserRequestCriteria userRequestCriteria = new UserRequestCriteria();
            OfferDTO            offersDTO           = new OfferDTO();

            if (OrderDT.Rows.Count == 0)
            {
                throw new EmptyViewException(language, Messages.GetMessage(language, TypeM.ACCIDENT, orderM.Order_DATA_NOT_FOUND));
            }



            userRequestCriteria.ORDER_ID = OrderDT.Rows[0]["ORDER_ID"] is DBNull ? 0 : Convert.ToInt32(OrderDT.Rows[0]["ORDER_ID"]);
            userRequestCriteria.USER_ID  = OrderDT.Rows[0]["USER_ID"]  is DBNull ? 0 : Convert.ToInt32(OrderDT.Rows[0]["USER_ID"].ToString());
            try
            {
                userRequestCriteria.ORDERDATE = Convert.ToDateTime(OrderDT.Rows[0]["ORDERDATE"].ToString()).ToString("dd-MM-yyyy");
            }
            catch (Exception ex)
            {
                userRequestCriteria.ORDERDATE = "";
            }
            userRequestCriteria.PLATENUMBER    = OrderDT.Rows[0]["PLATENUMBER"].ToString();
            userRequestCriteria.ORDER_IDENTITY = OrderDT.Rows[0]["ORDER_IDENTITY"].ToString();
            userRequestCriteria.firstName      = OrderDT.Rows[0]["FIRSTNAME"].ToString();
            userRequestCriteria.lastName       = OrderDT.Rows[0]["LASTNAME"].ToString();
            userRequestCriteria.CountryCode    = OrderDT.Rows[0]["COUNTRY_CODE"] is DBNull ? 0 : Convert.ToInt32(OrderDT.Rows[0]["COUNTRY_CODE"].ToString());
            userRequestCriteria.phoneNumber    = OrderDT.Rows[0]["PHONENUMBER"].ToString();
            userRequestCriteria.ORDERTYPE_ID   = OrderDT.Rows[0]["ORDERTYPE_ID"]  is DBNull ? 0 : Convert.ToInt32(OrderDT.Rows[0]["ORDERTYPE_ID"].ToString());
            userRequestCriteria.ORDERTYPE_NAME = OrderDT.Rows[0]["ORDERTYPE_NAME"].ToString();
            userRequestCriteria.VEHICLE_ID     = OrderDT.Rows[0]["VEHICLE_ID"]  is DBNull ? 0 :  Convert.ToInt32(OrderDT.Rows[0]["VEHICLE_ID"].ToString());
            userRequestCriteria.ORDER_STATUS   = OrderDT.Rows[0]["ORDER_STATUS"] is DBNull ? 0 : Convert.ToInt32(OrderDT.Rows[0]["ORDER_STATUS"].ToString());
            userRequestCriteria.ISACTIVE       = OrderDT.Rows[0]["ISACTIVE"] is DBNull ? 0 : Convert.ToInt32(OrderDT.Rows[0]["ISACTIVE"].ToString());
            userRequestCriteria.OFFERS_COUNT   = OrderDT.Rows[0]["OFFERS_COUNT"]  is DBNull ? 0 : Convert.ToInt32(OrderDT.Rows[0]["OFFERS_COUNT"].ToString());
            if (language == Messages.language.ar.ToString())
            {
                userRequestCriteria.BRANDNAME = OrderDT.Rows[0]["BRANDNAME_AR"].ToString();
                userRequestCriteria.MODELNAME = OrderDT.Rows[0]["MODELNAME_AR"].ToString();
            }
            else
            {
                userRequestCriteria.BRANDNAME = OrderDT.Rows[0]["BRANDNAME_EN"].ToString();
                userRequestCriteria.MODELNAME = OrderDT.Rows[0]["MODELNAME_EN"].ToString();
            }
            userRequestCriteria.carIMAGE  = OrderDT.Rows[0]["carImage"].ToString();
            userRequestCriteria.userIMAGE = OrderDT.Rows[0]["userImage"].ToString();
            userRequestCriteria.Note      = OrderDT.Rows[0]["NOTE"].ToString();
            userRequestCriteria.COLORNAME = OrderDT.Rows[0]["COLOR_NAME"].ToString();

            userRequestCriteria.lat = OrderDT.Rows[0]["lat"] is DBNull ? 0 : Convert.ToDouble(OrderDT.Rows[0]["lat"].ToString());
            userRequestCriteria.lng = OrderDT.Rows[0]["lng"] is DBNull ? 0 : Convert.ToDouble(OrderDT.Rows[0]["lng"].ToString());


            if (lat == 0 || lng == 0 || userRequestCriteria.lat == 0 || userRequestCriteria.lng == 0)
            {
                userRequestCriteria.time     = "0";
                userRequestCriteria.distance = 0;
            }
            else
            {
                double distanceMiles1 = Math.Sqrt(
                    Math.Pow((lat - userRequestCriteria.lat) * 69, 2) +
                    Math.Pow((lng - userRequestCriteria.lng) * 69.172, 2));
                userRequestCriteria.distance = Math.Round(distanceMiles1 * 1.60934, 2);
                userRequestCriteria.time     = new ServicesRepository(language).getTime(lat + "," + lng, userRequestCriteria.lat + "," + userRequestCriteria.lng);
            }



            if (OfferDT.Rows.Count > 0)
            {
                offersDTO.OFFER_ID      = OfferDT.Rows[0]["OFFER_ID"] is DBNull ? 0 : Convert.ToInt32(OfferDT.Rows[0]["OFFER_ID"]);
                offersDTO.offerStatus   = OfferDT.Rows[0]["OFFER_STATUS"] is DBNull ? 0: Convert.ToInt32(OfferDT.Rows[0]["OFFER_STATUS"]);
                offersDTO.ORDER_ID      = OfferDT.Rows[0]["ORDER_ID"] is DBNull ? 0 : Convert.ToInt32(OfferDT.Rows[0]["ORDER_ID"]);
                offersDTO.PRICE         = OfferDT.Rows[0]["PRICE"] is DBNull ? 0 : Convert.ToDouble(OfferDT.Rows[0]["PRICE"]);
                offersDTO.SUPPLIER_Name = OfferDT.Rows[0]["SUPPLIER_Name"] is DBNull ? "" : OfferDT.Rows[0]["SUPPLIER_Name"].ToString();
                offersDTO.timeValue     = OfferDT.Rows[0]["timeValue"] is DBNull ? 0 : Convert.ToInt32(OfferDT.Rows[0]["timeValue"]);
                offersDTO.timeFlag      = OfferDT.Rows[0]["timeFlag"] is DBNull ? 0 : Convert.ToInt32(OfferDT.Rows[0]["timeFlag"]);
                offersDTO.supplierImage = OfferDT.Rows[0]["supplierImage"] is DBNull ? "" :  OfferDT.Rows[0]["supplierImage"].ToString();
                offersDTO.CountryCode   = OfferDT.Rows[0]["COUNTRY_CODE"] is DBNull ? 0 : Convert.ToInt32(OfferDT.Rows[0]["COUNTRY_CODE"]);
                offersDTO.PHONENUMBER   = OfferDT.Rows[0]["PHONENUMBER"] is DBNull ? "" : OfferDT.Rows[0]["PHONENUMBER"].ToString();
                offersDTO.lat           = OfferDT.Rows[0]["LOCATIONX"] is DBNull ? 0 : Convert.ToDouble(OfferDT.Rows[0]["LOCATIONX"]);
                offersDTO.lng           = OfferDT.Rows[0]["LOCATIONY"] is DBNull ? 0 : Convert.ToDouble(OfferDT.Rows[0]["LOCATIONY"]);
                offersDTO.Rating        = OfferDT.Rows[0]["RATING"] is DBNull ? 0 : Convert.ToDouble(OfferDT.Rows[0]["RATING"]);

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


                if (lat == 0 || lng == 0 || offersDTO.lat == 0 || offersDTO.lng == 0)
                {
                    offersDTO.time     = "0";
                    offersDTO.DISTANCE = 0;
                }
                else
                {
                    double distanceMiles2 = Math.Sqrt(
                        Math.Pow((lat - offersDTO.lat) * 69, 2) +
                        Math.Pow((lng - offersDTO.lng) * 69.172, 2));
                    offersDTO.DISTANCE = Math.Round(distanceMiles2 * 1.60934, 2);
                    offersDTO.time     = new ServicesRepository(language).getTime(lat + "," + lng, offersDTO.lat + "," + offersDTO.lng);
                }
            }
            infoAssign        info;
            List <infoAssign> infoAssigns = new List <infoAssign>();

            if (OrderDetailsAssign.Rows.Count > 0)
            {
                foreach (System.Data.DataRow row in OrderDetailsAssign.Rows)
                {
                    info = new infoAssign();
                    if (language == Messages.language.ar.ToString())
                    {
                        info.key   = row["LISTNAME_AR"].ToString();
                        info.value = row["CONTENTNAME_AR"].ToString();
                    }
                    else
                    {
                        info.key   = row["LISTNAME_EN"].ToString();
                        info.value = row["CONTENTNAME_EN"].ToString();
                    }
                    infoAssigns.Add(info);
                }
            }


            userRequestCriteria.info = infoAssigns;
            Domain.Entities.Order.OrdersDetails orderDatails = new Domain.Entities.Order.OrdersDetails();
            orderDatails.order = userRequestCriteria;
            orderDatails.offer = offersDTO;



            return(orderDatails);
        }