Exemple #1
0
        public QueryResult <Vehicle> GetAll(VehicleQuery filter, bool withDeleted = false)
        {
            var result = new QueryResult <Vehicle>();

            var query = _vehicles.GetAll(vehicles => vehicles
                                         .Include(v => v.Model).ThenInclude(m => m.Make)
                                         .Include(v => v.Features).ThenInclude(vf => vf.Feature), withDeleted);

            if (filter.MakeId.HasValue)
            {
                query = query.Where(x => x.Model.MakeId == filter.MakeId.Value);
            }

            if (filter.ModelId.HasValue)
            {
                query = query.Where(x => x.ModelId == filter.ModelId.Value);
            }

            var columnsMap = new Dictionary <string, Expression <Func <Vehicle, object> > >()
            {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.ContactName
            };

            query = query.ApplyOrdering(filter, columnsMap);

            result.TotalItems = query.Count();

            query = query.ApplyPaging(filter);

            result.Items = query.ToList();

            return(result);
        }
Exemple #2
0
        public async Task <QueryResult <Vehicle> > ListVehiclesAsync(VehicleQuery queryObj = null)
        {
            var queryItems = _context.Vehicles
                             .Include(v => v.Model).ThenInclude(m => m.Make)
                             .AsQueryable();

            if (queryObj != null)
            {
                queryItems = queryItems.ApplyFiltering(queryObj);
            }

            if (queryObj != null)
            {
                queryItems = queryItems.ApplyOrdering(queryObj, _columnsMap);
            }

            var result = new QueryResult <Vehicle>
            {
                TotalItems = await queryItems.CountAsync()
            };

            if (queryObj != null)
            {
                queryItems = queryItems.ApplyPaging(queryObj);
            }

            result.Items = await queryItems.ToListAsync();

            return(result);
        }
Exemple #3
0
        public async Task <QueryResult <Vehicle> > GetAll(VehicleQuery vehicleQuery)
        {
            var result = new QueryResult <Vehicle>();
            var query  = _dbContext.Vehicles
                         .Include(v => v.Model)
                         .ThenInclude(m => m.Make)
                         .AsQueryable();

            if (vehicleQuery.MakeId.HasValue)
            {
                query = query.Where(v => v.Model.MakeId == vehicleQuery.MakeId.Value);
            }

            var columnsMap = new Dictionary <string, Expression <Func <Vehicle, object> > >()
            {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.ContactName
            };

            //columnsMap.Add("make", v => v.Model.Make.Name);

            query = query.ApplyOrdering(vehicleQuery, columnsMap);

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(vehicleQuery);

            result.Items = await query.ToListAsync();

            return(result);
        }
        public List <string> GetCarImages(int order_id, int ordertype)
        {
            VehicleQuery vehicleQuery = new VehicleQuery(language);
            string       modelImage   = "";



            System.Data.DataTable dataTable = conn_db.ReadTable(vehicleQuery.GetObjectByColname("car_images_v", "order_id", order_id));
            if (dataTable.Rows.Count == 0)
            {
                if (ordertype == 6)
                {
                    modelImage = new Enums().APP_DIRECTORY + "images/OrderImages/satha.png";
                }
                else
                {
                    throw new EmptyViewException(language, Messages.GetMessage(language, TypeM.VEHICLE, vehicleM.IMAGE_NOT_FOUND));
                }
            }


            List <string> listCarImages = new List <string>();

            foreach (System.Data.DataRow row in dataTable.Rows)
            {
                listCarImages.Add(row["Pic_url"].ToString());
            }

            if (listCarImages.Count == 0)
            {
                listCarImages.Add(modelImage);
            }
            return(listCarImages);
        }
Exemple #5
0
        public async Task <QueryResult <Vehicle> > GetVehiclesAsync(VehicleQuery queryObj)
        {
            var result = new QueryResult <Vehicle>();

            var query = _context.Vehicles
                        .Include(v => v.Model)
                        .ThenInclude(m => m.Make)
                        .Include(v => v.Features)
                        .ThenInclude(vf => vf.Feature)
                        .AsQueryable();

            if (queryObj.MakeId.HasValue)
            {
                query = query.Where(x => x.Model.MakeId == queryObj.MakeId.Value);
            }

            if (queryObj.ModelId.HasValue)
            {
                query = query.Where(x => x.ModelId == queryObj.ModelId.Value);
            }

            var columnsMap = new Dictionary <string, Expression <Func <Vehicle, object> > >
            {
                { "make", v => v.Model.Make.Name },
                { "model", v => v.Model.Name },
                { "contactName", v => v.ContactName }
            };

            query             = query.ApplyOrdering(queryObj, columnsMap);
            result.TotalItems = await query.CountAsync();

            result.Items = query.ApplyPaging(queryObj);

            return(result);
        }
Exemple #6
0
        public async Task <QueryResult <Vehicle> > getVehicles(VehicleQuery queryobj)
        {
            var result = new QueryResult <Vehicle>();
            var query  = context.Vehicle
                         .Include(v => v.Model)
                         .ThenInclude(m => m.Make)
                         .Include(v => v.VehicleFeature)
                         .ThenInclude(vf => vf.Feature)
                         .AsQueryable();

            if (queryobj.Makeid.HasValue == true)
            {
                query = query.Where(v => v.Model.MakeId == queryobj.Makeid.Value);
            }

            var colsmap = new Dictionary <string, Expression <Func <Vehicle, object> > >()
            {
                ["Make"]         = v => v.Model.Make.name,
                ["Model"]        = v => v.Model.name,
                ["Contact Name"] = v => v.ConName
            };

            query = query.Sorter(queryobj, colsmap);

            result.totalItems = await query.CountAsync();

            query = query.ApplyPager(queryobj);

            result.Items = await query.ToListAsync();

            return(result);
        }
Exemple #7
0
        public async Task <QueryResoult <Vehicle> > GetVehicles(VehicleQuery queryObj)
        {
            var resoult = new QueryResoult <Vehicle>();

            var query = context.Vehicles
                        .Include(v => v.VehicleFeatures).ThenInclude(vf => vf.Feature)
                        .Include(v => v.Model).ThenInclude(m => m.Make)
                        .AsQueryable();

            if (queryObj.MakeId.HasValue)
            {
                query = query.Where(v => v.Model.MakeID == queryObj.MakeId.Value);
            }

            var columnsMap = new Dictionary <string, Expression <Func <Vehicle, object> > >()
            {
                ["make"] = v => v.Model.Make.Name
            };

            query = query.ApplyOrdering(queryObj, columnsMap);

            resoult.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(queryObj);

            resoult.Items = await query.ToListAsync();

            return(resoult);
        }
Exemple #8
0
        public async Task <QueryResult <Vehicle> > GetVehicles(VehicleQuery queryObject)
        {
            var result = new QueryResult <Vehicle>();
            var query  = context.Vehicles
                         .Include(v => v.Model)
                         .ThenInclude(m => m.Make)
                         .AsQueryable();

            query = query.ApplyFiltering(queryObject);

            //Expression tree (dictionary) to map the sorting columns to the linq expressions
            var columnsMap = new Dictionary <string, Expression <Func <Vehicle, object> > >() // object because we can then reference any property of the vehicle and not only string properties.
            {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.ContactName,
                //["id"] = v => v.Id
            };

            query = query.ApplyOrdering(queryObject, columnsMap);

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(queryObject);

            result.Items = await query.ToListAsync();

            return(result);
        }
        public async Task <QueryResult <Vehicle> > GetVehicles(VehicleQuery queryObj)
        {
            QueryResult <Vehicle> result = new QueryResult <Vehicle>();

            var query = context.Vehicles
                        .Include(v => v.Features)
                        .ThenInclude(vf => vf.Feature)
                        .Include(v => v.Model)
                        .ThenInclude(vm => vm.Make)
                        .AsQueryable();

            if (queryObj.MakeId.HasValue && queryObj.MakeId != 0)
            {
                query = query.Where(x => x.Model.MakeId == queryObj.MakeId);
            }

            var sortColumnMap = new Dictionary <string, Expression <Func <Vehicle, object> > >()
            {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.ContactName,
            };

            query = query.ApplySorting(queryObj, sortColumnMap);

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(queryObj);

            result.Items = await query.ToListAsync();

            return(result);
        }
Exemple #10
0
        public async Task <IEnumerable <Vehicle> > GetVehicles(VehicleQuery queryObj)
        {
            var query = _context.Vehicles
                        .Include(v => v.Model)
                        .ThenInclude(vm => vm.Make)
                        .Include(v => v.Features)
                        .ThenInclude(f => f.Feature)
                        .AsQueryable();

            if (queryObj.MakeId.HasValue)
            {
                query = query.Where(v => v.Model.MakeId == queryObj.MakeId.Value);
            }

            if (queryObj.ModelId.HasValue)
            {
                query = query.Where(v => v.ModelId == queryObj.ModelId.Value);
            }

            var ColumnsMap = new Dictionary <string, Expression <Func <Vehicle, object> > > ()
            {
                ["make"] = v => v.Model.Make.Name, ["model"] = v => v.Model.Name, ["contactName"] = v => v.ContactName, ["id"] = v => v.Id
            };

            query = query.ApplySorting(queryObj, ColumnsMap);

            return(await query.ToListAsync());
        }
        public async Task <QueryResult <VehicleModel> > GetVehicles(VehicleQuery vehicleQuery)
        {
            var result = new QueryResult <VehicleModel>();

            var query = context.VehicleModels
                        .Include(v => v.Vehicle)
                        .ThenInclude(m => m.Manufacturer)
                        .AsQueryable();

            query = query.ApplyFiltering(vehicleQuery);

            var columnsMap = new Dictionary <string, Expression <Func <VehicleModel, object> > >()
            {
                ["manufacturer"] = v => v.Vehicle.Manufacturer.Name,
                ["vehicle"]      = v => v.Vehicle.Name,
                ["contactName"]  = v => v.ContactName
            };

            query = query.ApplyOrdering(vehicleQuery, columnsMap);

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(vehicleQuery);

            result.Items = await query.ToListAsync();

            return(result);
        }
        public IEnumerable <Vehicle> GetVehicles(VehicleQuery filter)
        {
            var vehicles = context.Vehicles
                           .Include(v => v.VehicleFeatures)
                           .ThenInclude(vf => vf.Feature)
                           .Include(v => v.Model)
                           .ThenInclude(m => m.Make).AsQueryable();

            if (filter.MakeId.HasValue)
            {
                vehicles = vehicles.Where(v => v.Model.MakeId == filter.MakeId.Value);
            }
            if (filter.ModelId.HasValue)
            {
                vehicles = vehicles.Where(v => v.ModelId == filter.ModelId);
            }

            #region Sorting
            var sortLogic = new Dictionary <string, Expression <Func <Vehicle, object> > >
            {
                ["make"]        = v => v.Model.MakeId,
                ["model"]       = v => v.ModelId,
                ["contactName"] = v => v.ContactName,
            };

            vehicles = vehicles.ApplyOrdering(filter, sortLogic);
            #endregion

            return(vehicles);
        }
Exemple #13
0
        public async Task <QueryResult <Vehicle> > GetVehicles(VehicleQuery queryObj)
        {
            var result = new QueryResult <Vehicle>();
            var query  = context.Vehicles
                         .Include(v => v.Model)
                         .ThenInclude(m => m.Make)
                         .Include(v => v.Features)
                         .ThenInclude(vf => vf.Feature).AsQueryable();

            if (queryObj.MakeId.HasValue)
            {
                query = query.Where(v => v.Model.MakeId == queryObj.MakeId.Value);
            }

            Dictionary <string, Expression <Func <Vehicle, object> > > columnsMap = new Dictionary <string, Expression <Func <Vehicle, object> > >() //object initialization
            {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.ContactName
                                  //["id"] = v => v.Id
            };

            query = query.ApplyOrdering(queryObj, columnsMap);

            result.TotalItems = await query.CountAsync();

            //paging implementation
            query = query.ApplyPaging(queryObj);

            result.Items = await query.ToListAsync();

            return(result);
        }
Exemple #14
0
        public async Task <List <Vehicle> > GetAll(VehicleQuery queryObj, bool includeRelated = true)
        {
            var query = Context.Vehicles
                        .Include(v => v.VehicleModel)
                        .ThenInclude(m => m.Make)
                        .Include(v => v.Features)
                        .ThenInclude(vf => vf.Feature)
                        .AsQueryable();

            var sortingDictionary = new Dictionary <string, Expression <Func <Vehicle, object> > >()
            {
                ["make"] = v => v.VehicleModel.Make.Name,
                ["name"] = v => v.Name
            };

            if (queryObj.MakeId.HasValue)
            {
                query = query.Where(v => v.VehicleModel.MakeId == queryObj.MakeId);
            }
            query = query.ApplyOrdering(queryObj, sortingDictionary);

            query = query.ApplyPaging(queryObj);

            var vehiclesList = await query.ToListAsync();

            return(vehiclesList);
        }
        public async Task <QueryResult <Vehicle> > GetVehicles(VehicleQuery queryObj)
        {
            var result = new QueryResult <Vehicle>();

            var query = appDbContext.Vehicle
                        .Include(v => v.Model)
                        .ThenInclude(m => m.Make)
                        .Include(v => v.Features)
                        .ThenInclude(vf => vf.Feature)
                        .AsQueryable();

            var dictionary = new Dictionary <string, Expression <Func <Vehicle, object> > >
            {
                { "make", v => v.Model.Make.Name },
                { "model", v => v.Model.Name },
                { "contactName", v => v.ContactName },
                { "id", v => v.Id }
            };

            query = query.ApplyOrdering(queryObj, dictionary);

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(queryObj);

            result.Items = await query.ToListAsync();

            return(result);
        }
Exemple #16
0
        public async Task <IEnumerable <Vehicle> > GetVehicles(VehicleQuery queryObj)
        {
            // return await context.Vehicles
            // .Include(v => v.Model)
            //     .ThenInclude(md => md.Make)
            // .Include(v => v.Features)
            //     .ThenInclude(vf => vf.Feature)
            // .ToListAsync();

            //filter, using dynamically query
            var query = context.Vehicles
                        .Include(v => v.Model)
                        .ThenInclude(md => md.Make)
                        .Include(v => v.Features)
                        .ThenInclude(vf => vf.Feature)
                        .AsQueryable();

            if (queryObj.MakeId.HasValue)
            {
                query = query.Where(v => v.Model.MakeId == queryObj.MakeId.Value);
            }
            // sorting
            if (queryObj.SortBy == "make")
            {
                query = (queryObj.IsSortAscending) ? query.OrderBy(v => v.Model.Make.Name) : query.OrderByDescending(v => v.Model.Make.Name);
            }

            //Expression<Func<Vehicle, Object>>


            return(await query.ToListAsync());
        }
Exemple #17
0
        public async Task <QueryResult <Vehicle> > GetVehiclesAsync(VehicleQuery vehicleQuery)
        {
            var result = new QueryResult <Vehicle>();
            var query  = Vehicles();

            if (vehicleQuery.MakeId.HasValue)
            {
                query = query.Where(v => v.Model.MakeId == vehicleQuery.MakeId.Value);
            }

            var columnsMapping = new Dictionary <string, Expression <Func <Vehicle, object> > >()
            {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.Contact.Name,
                ["id"]          = v => v.Id,
            };

            result.TotalItems = await query.CountAsync();

            query = query.ApplyOrdering(vehicleQuery, columnsMapping);

            query        = query.ApplyPaging(vehicleQuery);
            result.Items = query;
            return(result);
        }
Exemple #18
0
        public async Task <QueryResultResource <VehicleResource> > GetVehicles(VehicleQueryResource filterResource)
        {
            VehicleQuery filter      = mapper.Map <VehicleQueryResource, VehicleQuery>(filterResource);
            var          queryResult = await repository.GetVehicles(filter);

            return(mapper.Map <QueryResult <Vehicle>, QueryResultResource <VehicleResource> >(queryResult));
        }
Exemple #19
0
        public async Task <QueryResultDto <VehicleDto> > GetVehicles(VehicleQuery queryObj)
        {
            var queryresult = new QueryResult <Vehicle>();
            var allVehicles = _context.Vehicles.Include(x => x.Model).ThenInclude(m => m.Make).Include(x => x.Features).AsQueryable();

            if (queryObj.MakeId.HasValue)
            {
                allVehicles = allVehicles.Where(x => x.Model.MakeId == queryObj.MakeId);
            }
            //  Expression<Func<Vehicle, object>> exc;
            //  Func<Vehicle, string> func = v => v.ContactName;

            Dictionary <string, Expression <Func <Vehicle, object> > > columnMap =
                new Dictionary <string, Expression <Func <Vehicle, object> > >()
            {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.ContactName,
                ["id"]          = v => v.Id
            };

            //allVehicles = ApplyOrderBy(queryObj, allVehicles, columnMap);
            queryresult.TotalItems = await allVehicles.CountAsync();

            allVehicles = allVehicles.ApplyPaging(queryObj);
            allVehicles = allVehicles.ApplyOrderBy(queryObj, columnMap);

            queryresult.Items = await allVehicles.ToListAsync();

            var response = _mapper.Map <QueryResultDto <VehicleDto> >(queryresult);

            return(response);
        }
        public List <Model> GetModels(string lang, int brandId)
        {
            VehicleQuery vehicleQuery = new VehicleQuery(language);

            System.Data.DataTable dataTable = conn_db.ReadTable(vehicleQuery.GetModelsByBrandId(brandId));

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

            Model        model;
            List <Model> models = new List <Model>();

            foreach (System.Data.DataRow row in dataTable.Rows)
            {
                model          = new Model();
                model.model_id = Convert.ToInt32(row["id"].ToString());
                if (lang == "ar")
                {
                    model.modelName = row["MODELNAME_AR"].ToString();
                }
                else
                {
                    model.modelName = row["MODELNAME_EN"].ToString();
                }


                model.brand_id = row["BRAND_ID"] is DBNull ? 0 :  Convert.ToInt32(row["BRAND_ID"].ToString());

                models.Add(model);
            }
            return(models);
        }
Exemple #21
0
        public async Task <IEnumerable <Vehicle> > GetVehicles(VehicleQuery queryObj)
        {
            var query = context.Vehicles
                        .Include(v => v.Features)
                        .ThenInclude(vf => vf.Feature)
                        .Include(v => v.Model)
                        .ThenInclude(m => m.Make).AsQueryable();

            if (queryObj.MakeId.HasValue)
            {
                query = query.Where(x => x.Model.MakeId == queryObj.MakeId.Value);
            }
            if (queryObj.ModelId.HasValue)
            {
                query = query.Where(x => x.Model.Id == queryObj.ModelId.Value);
            }

            var dictMap = new Dictionary <string, Expression <Func <Vehicle, object> > > {
                { "make", x => x.Model.Make.Name },
                { "model", x => x.Model.Name },
                { "contactName", x => x.ContactName }
            };

            query = query.ApplyOrdering <Vehicle>(queryObj, dictMap);

            // query = query.ApplyPaging<Vehicle>(queryObj);

            return(await query.ToListAsync());
        }
        public List <Color> GetColors(string lang)
        {
            VehicleQuery vehicleQuery = new VehicleQuery(language);

            System.Data.DataTable dataTable = conn_db.ReadTable(vehicleQuery.GetMasterTranslated("color", lang));

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

            Color        color;
            List <Color> models = new List <Color>();

            foreach (System.Data.DataRow row in dataTable.Rows)
            {
                color           = new Color();
                color.color_id  = Convert.ToInt32(row["id"].ToString());
                color.colorName = row["color_Name"].ToString();


                models.Add(color);
            }
            return(models);
        }
Exemple #23
0
        public async Task <QueryResult <Vehicle> > GetVehicles(VehicleQuery queryObj)
        {
            IQueryable <Vehicle> query = _context.Vehicles;

            query = query.ApplyFiltering(queryObj);

            var count = await query.CountAsync();

            query = query
                    .Include(v => v.Features).ThenInclude(f => f.Feature)
                    .Include(v => v.Model).ThenInclude(m => m.Make)
                    .AsQueryable();

            var orderMapping = new Dictionary <string, Expression <Func <Vehicle, object> > > {
                [nameof(VehicleResource.Make).ToLower()]  = v => v.Model.Make.Name,
                [nameof(VehicleResource.Model).ToLower()] = v => v.Model.Name,
                [nameof(Vehicle.ContactName).ToLower()]   = v => v.ContactName,
                [nameof(Vehicle.Id).ToLower()]            = v => v.Id
            };

            query = query.ApplyOrdering(queryObj, orderMapping);

            query = query.ApplyPaging(queryObj);

            return(new QueryResult <Vehicle> {
                TotalItems = count,
                Items = await query.ToListAsync()
            });
        }
Exemple #24
0
        public async Task <QueryResult <Vehicle> > GetVehicles(VehicleQuery queryObj)
        {
            var result = new QueryResult <Vehicle>();
            var query  = context.Vehicles
                         .Include(v => v.Model)
                         .ThenInclude(m => m.Make)
                         .Include(v => v.VehicleFeatures)
                         .ThenInclude(vf => vf.Feature)
                         .AsQueryable();

            query = query.ApplyFiltering(queryObj);

            var columnsMap = new Dictionary <string, Expression <Func <Vehicle, object> > >()
            {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.ContactName,
                // ["id"] = v=>v.Id,
            };

            query             = query.ApplOrdering(queryObj, columnsMap);
            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(queryObj);
            // if (queryObj.SortBy == "make")
            // {
            //     query = (queryObj.IsSortAscending) ? query.OrderBy(v=>v.Model.Make.Name) : query.OrderByDescending(v=>v.Model.Make.Name);
            // }
            result.Items = await query.ToListAsync();

            return(result);
        }
        public async Task <IEnumerable <Vehicle> > GetVehicles(VehicleQuery queryObj)
        {
            var query = context.Vehicles
                        .Include(v => v.VehicleFeatures)
                        .ThenInclude(vf => vf.Feature)
                        .Include(v => v.Model)
                        .ThenInclude(m => m.Make)
                        .AsQueryable();

            if (queryObj.MakeId.HasValue)
            {
                query = query.Where(v => v.Model.MakeId == queryObj.MakeId);
            }

            var columnsMap = new Dictionary <string, Expression <Func <Vehicle, object> > >
            {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.ContactName
            };

            query = query.ApplyOrdering(queryObj, columnsMap);

            query = query.ApplyPagging(queryObj);

            return(await query.ToListAsync());
        }
        public List <FixPaperDTO> GetFixPaper(int user_id)
        {
            VehicleQuery vehicleQuery = new VehicleQuery(language);

            System.Data.DataTable dataTable  = conn_db.ReadTable(vehicleQuery.GetObjectByColname("fixPaper_v", "user_id", user_id));
            FixPaperDTO           fixPaper   = new FixPaperDTO();
            List <FixPaperDTO>    listPapers = new List <FixPaperDTO>();

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

            foreach (System.Data.DataRow row in dataTable.Rows)
            {
                fixPaper                 = new FixPaperDTO();
                fixPaper.id              = Convert.ToInt32(row["ID"].ToString());
                fixPaper.paper_id        = row["PAPER_ID"].ToString();
                fixPaper.issueDate       = Convert.ToDateTime(row["ISSUEDATE"].ToString()).ToString("dd-MM-yyyy");
                fixPaper.expiryDate      = Convert.ToDateTime(row["EXPIRYDATE"].ToString()).ToString("dd-MM-yyyy");
                fixPaper.status          = Convert.ToInt32(row["status"].ToString());
                fixPaper.car_plateNumber = row["CAR_PLATENUMBER"].ToString();

                listPapers.Add(fixPaper);
            }


            return(listPapers);
        }
Exemple #27
0
        public async Task <QueryResult <Vehicle> > GetVehicles(VehicleQuery queryObj)
        {
            var result = new QueryResult <Vehicle>();

            var query = context.Vehicles
                        .Include(v => v.Model)
                        .ThenInclude(m => m.Make)
                        .AsQueryable();

            query = query.ApplyFiltering(queryObj);

            var columnsMap = new Dictionary <string, Expression <Func <Vehicle, object> > >()
            {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.ContactName
            };

            query = query.ApplyOrdering(queryObj, columnsMap);

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(queryObj);

            result.Items = await query.ToListAsync();

            return(result);
        }
        public List <Brand> GetBrands(string lang)
        {
            VehicleQuery vehicleQuery = new VehicleQuery(language);

            System.Data.DataTable dataTable = conn_db.ReadTable(vehicleQuery.GetObjectByColname("car_brand", "isactive", 1));

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

            Brand        brand;
            List <Brand> Brands = new List <Brand>();

            foreach (System.Data.DataRow row in dataTable.Rows)
            {
                brand          = new Brand();
                brand.brand_id = Convert.ToInt32(row["id"].ToString());
                if (lang == "ar")
                {
                    brand.brandName = row["BRANDNAME_AR"].ToString();
                }
                else
                {
                    brand.brandName = row["BRANDNAME_EN"].ToString();
                }


                brand.Logo = row["LOGO"].ToString();

                Brands.Add(brand);
            }
            return(Brands);
        }
        public async Task <QueryResult <Vehicle> > GetVehicles(VehicleQuery queryObj)
        {
            var result = new QueryResult <Vehicle>();

            var query = _context.Vehicles
                        .Include(v => v.Features)
                        .ThenInclude(vf => vf.Feature)
                        .Include(v => v.Model)
                        .ThenInclude(m => m.Make)
                        .AsQueryable();

            // Filter by MakeId
            if (queryObj.MakeId.GetValueOrDefault() > 0)
            {
                query = query.Where(v => v.Model.MakeId == queryObj.MakeId.Value);
            }

            var columnsMap = new Dictionary <string, Expression <Func <Vehicle, object> > >()
            {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.Contact.Name,
                ["id"]          = v => v.Id
            };

            query = query.ApplyOrdering(queryObj, columnsMap);

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(queryObj);

            result.Items = await query.ToListAsync();

            return(result);
        }
        public async Task <QueryResult <Vehicle> > GetVehicles(VehicleQuery queryObject)
        {
            var result = new QueryResult <Vehicle>();

            var query = _context.Vehicles
                        .Include(v => v.Features)
                        .ThenInclude(vf => vf.Feature)
                        .Include(v => v.Model)
                        .ThenInclude(m => m.Make)
                        .AsQueryable();

            if (queryObject.MakeId.HasValue)
            {
                query = query.Where(v => v.Model.MakeId == queryObject.MakeId.Value);
            }

            if (queryObject.ModelId.HasValue)
            {
                query = query.Where(v => v.ModelId == queryObject.ModelId.Value);
            }

            var columnsMap = new Dictionary <string, Expression <Func <Vehicle, object> > >()
            {
                ["make"]        = v => v.Model.Make.Name,
                ["model"]       = v => v.Model.Name,
                ["contactName"] = v => v.ContactName,
                // ["id"] = v => v.Id,
            };

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging <Vehicle>(queryObject);

            // query = ApplyOrdering(queryObject, query, columnsMap);
            query = query.ApplyOrdering <Vehicle>(queryObject, columnsMap);

            /*
             * if (queryObject.SortBy == "make")
             * {
             *  query = (queryObject.IsSortAscending) ? query.OrderBy(v => v.Model.Make.Name) : query.OrderByDescending(v => v.Model.Make.Name);
             * }
             * if (queryObject.SortBy == "model")
             * {
             *  query = (queryObject.IsSortAscending) ? query.OrderBy(v => v.Model.Name) : query.OrderByDescending(v => v.Model.Name);
             * }
             * if (queryObject.SortBy == "contactName")
             * {
             *  query = (queryObject.IsSortAscending) ? query.OrderBy(v => v.ContactName) : query.OrderByDescending(v => v.ContactName);
             * }
             * if (queryObject.SortBy == "id")
             * {
             *  query = (queryObject.IsSortAscending) ? query.OrderBy(v => v.Id) : query.OrderByDescending(v => v.Id);
             * }
             */

            result.Items = await query.ToListAsync();

            return(result);
        }