Exemple #1
0
        public async Task <SimplePage <UserWithRolesDto> > Search(UserRequestCriteria criteria)
        {
            IQueryable <AppIdentityUser> query = _dbContext.Users;

            if (criteria.IncludeRoles)
            {
                query = query.Include(_ => _.Roles);
            }

            if (!string.IsNullOrWhiteSpace(criteria.Q))
            {
                query = query.Where(_ =>
                                    _.FirstName.Contains(criteria.Q) || _.LastName.Contains(criteria.Q) ||
                                    _.Email.Contains(criteria.Q));
            }

            if (criteria.Roles?.Any() == true)
            {
                var roles = criteria.Roles.Select(_ => _rolesHelper.GetRoleId(_));
                query = query.Where(user =>
                                    user.Roles.Select(role => role.RoleId).Any(roleId => roles.Contains(roleId)));
            }

            var page = await query.GetSimplePage(criteria);

            var result = _mapper.Map <SimplePage <UserWithRolesDto> >(page);

            return(result);
        }
Exemple #2
0
 public Task <SimplePage <UserWithRolesDto> > Search([FromQuery] UserRequestCriteria criteria) =>
 _usersService.Search(criteria);
        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);
        }
        public List <UserRequestCriteria> GetAllRequests(int user_id, int pageSize, int pageNumber)
        {
            //OfferQuery offerQuery = new OfferQuery(language);
            OrderQuery orderQuery = new OrderQuery(language);

            System.Data.DataTable Supplier = conn_db.ReadTable(orderQuery.GetSupplierByUserId(user_id));
            int    city_id       = 0;
            int    supplier_type = 0;
            int    supplier_id   = 0;
            double supplier_lat  = 0;
            double supplier_lng  = 0;

            if (Supplier.Rows.Count > 0)
            {
                supplier_id   = Supplier.Rows[0]["ID"] is DBNull ? 0 : Convert.ToInt32(Supplier.Rows[0]["ID"]);
                city_id       = Supplier.Rows[0]["city_id"] is DBNull ? 0 : Convert.ToInt32(Supplier.Rows[0]["city_id"]);
                supplier_type = Supplier.Rows[0]["SUPPLIER_TYPE_ID"] is DBNull ? 0 : Convert.ToInt32(Supplier.Rows[0]["SUPPLIER_TYPE_ID"]);

                supplier_lat = Supplier.Rows[0]["LOCATIONX"] is DBNull ? 0 : Convert.ToDouble(Supplier.Rows[0]["LOCATIONX"].ToString());
                supplier_lng = Supplier.Rows[0]["LOCATIONY"] is DBNull ? 0 : Convert.ToDouble(Supplier.Rows[0]["LOCATIONY"].ToString());
            }



            System.Data.DataTable dataTable = conn_db.ReadTable(orderQuery.GetAllRequests(city_id, supplier_type, supplier_id, pageSize, pageNumber, language));



            if (dataTable.Rows.Count == 0)
            {
                throw new EmptyViewException(language);
            }


            UserRequestCriteria        userRequestCriteria  = new UserRequestCriteria();
            List <UserRequestCriteria> ListRequestCriterias = new List <UserRequestCriteria>();

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

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


                if (supplier_lat == 0 || supplier_lng == 0 || userRequestCriteria.lat == 0 || userRequestCriteria.lng == 0)
                {
                    userRequestCriteria.time     = "0";
                    userRequestCriteria.distance = 0;
                }


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


                ListRequestCriterias.Add(userRequestCriteria);
            }
            return(ListRequestCriterias);
        }
        public List <UserRequestCriteria> GetRequestsByUser_id(int user_id)
        {
            //OfferQuery offerQuery = new OfferQuery(language);
            OrderQuery orderQuery = new OrderQuery(language);
            OfferQuery offerQuery = new OfferQuery(language);


            System.Data.DataTable dataTable = conn_db.ReadTable(orderQuery.GetRequestsByUser_id(user_id, language));


            if (dataTable.Rows.Count == 0)
            {
                throw new EmptyViewException(language);
            }


            UserRequestCriteria        userRequestCriteria  = new UserRequestCriteria();
            List <UserRequestCriteria> ListRequestCriterias = new List <UserRequestCriteria>();

            foreach (System.Data.DataRow row in dataTable.Rows)
            {
                userRequestCriteria          = new UserRequestCriteria();
                userRequestCriteria.ORDER_ID = row["ORDER_ID"] is DBNull ? 0 : Convert.ToInt32(row["ORDER_ID"]);
                userRequestCriteria.USER_ID  = row["USER_ID"] is DBNull ? 0 : Convert.ToInt32(row["USER_ID"].ToString());
                try
                {
                    userRequestCriteria.ORDERDATE = Convert.ToDateTime(row["ORDERDATE"].ToString()).ToString("dd-MM-yyyy");
                }
                catch (Exception ex)
                {
                    userRequestCriteria.ORDERDATE = "";
                }
                userRequestCriteria.PLATENUMBER    = row["PLATENUMBER"].ToString();
                userRequestCriteria.ORDER_IDENTITY = row["ORDER_IDENTITY"].ToString();
                userRequestCriteria.firstName      = row["FIRSTNAME"].ToString();
                userRequestCriteria.lastName       = row["LASTNAME"].ToString();
                userRequestCriteria.phoneNumber    = row["PHONENUMBER"].ToString();
                userRequestCriteria.ORDERTYPE_ID   = row["ORDERTYPE_ID"] is DBNull ? 0 : Convert.ToInt32(row["ORDERTYPE_ID"]);
                userRequestCriteria.ORDERTYPE_NAME = row["ORDERTYPE_NAME"].ToString();
                userRequestCriteria.VEHICLE_ID     = row["VEHICLE_ID"]  is DBNull ? 0 :  Convert.ToInt32(row["VEHICLE_ID"]);
                userRequestCriteria.ORDER_STATUS   = row["ORDER_STATUS"]  is DBNull ? 0 : Convert.ToInt32(row["ORDER_STATUS"]);
                userRequestCriteria.ISACTIVE       = row["ISACTIVE"]  is DBNull ? 1 : Convert.ToInt32(row["ISACTIVE"].ToString());
                userRequestCriteria.OFFERS_COUNT   = row["OFFERS_COUNT"]  is DBNull ? 0 : Convert.ToInt32(row["OFFERS_COUNT"].ToString());
                if (language == Messages.language.ar.ToString())
                {
                    userRequestCriteria.BRANDNAME = row["BRANDNAME_AR"].ToString();
                    userRequestCriteria.MODELNAME = row["MODELNAME_AR"].ToString();
                }
                else
                {
                    userRequestCriteria.BRANDNAME = row["BRANDNAME_EN"].ToString();
                    userRequestCriteria.MODELNAME = row["MODELNAME_EN"].ToString();
                }
                userRequestCriteria.carIMAGE  = row["carImage"].ToString();
                userRequestCriteria.userIMAGE = row["userImage"].ToString();

                userRequestCriteria.Note      = row["NOTE"].ToString();
                userRequestCriteria.COLORNAME = row["COLOR_NAME"].ToString();
                userRequestCriteria.lat       = row["lat"] is DBNull ? 0 : Convert.ToDouble(row["lat"].ToString());
                userRequestCriteria.lng       = row["lng"] is DBNull ? 0 : Convert.ToDouble(row["lng"].ToString());
                userRequestCriteria.offer_id  = -1;

                if (userRequestCriteria.ORDER_STATUS == (int)orderStatus.FINISHED)
                {
                    System.Data.DataTable offerTable = conn_db.ReadTable(new OfferQuery(language).GetOfferDetailsByOrderId(userRequestCriteria.ORDER_ID));
                    if (offerTable.Rows.Count > 0)
                    {
                        userRequestCriteria.offer_id = Int32.Parse(offerTable.Rows[0]["OFFER_ID"].ToString());
                    }
                    else
                    {
                        userRequestCriteria.offer_id = -1;
                    }
                }

                ListRequestCriterias.Add(userRequestCriteria);
            }
            return(ListRequestCriterias);
        }