예제 #1
0
        public static IList<AutoSearch> GetAutos()
        {
            IList<AutoSearch> autos = new List<AutoSearch>();

            using (CarsEntity autorentEntity = new CarsEntity())
            {
                try
                {
                    var queryAutos = from am in autorentEntity.AutoModels
                                     join a in autorentEntity.Autoes on am.Id equals a.ModelId
                                     join ap in autorentEntity.AutoPhotos on a.Number equals ap.AutoNumber
                                     into j
                                     from ap in j.DefaultIfEmpty()
                                     select new
                                     {
                                         am.Maker,
                                         am.ConceptName,
                                         am.Class,
                                         a.KmRate,
                                         a.DayRate,
                                         a.Status,
                                         a.Number,
                                         ap.PhotoFileName
                                     };

                    foreach (var item in queryAutos)
                    {
                        AutoSearch auto = new AutoSearch();
                        auto.Number = item.Number;
                        auto.Make = item.Maker;
                        auto.Model = item.ConceptName;
                        auto.ClassAuto = (e_AutoClass)Convert.ToInt32(item.Class);
                        auto.PriceKm = item.KmRate;
                        auto.PriceDay = item.DayRate;
                        auto.CurrentStatus = (CurrentStatus)item.Status;
                        auto.Photo = item.PhotoFileName;

                        autos.Add(auto);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    throw ex;
                }

            }
            return autos;
        }
예제 #2
0
        public static IList<AutoSearch> GetAutos(AutoSearch autoSearch)
        {
            IList<AutoSearch> autos = new List<AutoSearch>();

            if (!string.IsNullOrEmpty(autoSearch.Make) && !string.IsNullOrEmpty(autoSearch.Model))
            {
                using (CarsEntity autorentEntity = new CarsEntity())
                {
                    try
                    {
                        string classAuto = ((int)autoSearch.ClassAuto).ToString();
                        var queryAutos = from am in autorentEntity.AutoModels
                                         join a in autorentEntity.Autoes on am.Id equals a.ModelId
                                         join ap in autorentEntity.AutoPhotos on a.Number equals ap.AutoNumber
                                         into j
                                         from ap in j.DefaultIfEmpty()
                                         where am.Class == classAuto &&
                                         am.Maker == autoSearch.Make &&
                                         am.ConceptName == autoSearch.Model
                                         select new
                                         {
                                             am.Maker,
                                             am.ConceptName,
                                             am.Class,
                                             a.KmRate,
                                             a.DayRate,
                                             a.Status,
                                             a.Number,
                                             ap.PhotoFileName
                                         };
                        string rawQuery = ((System.Data.Objects.ObjectQuery)queryAutos).ToTraceString();

                        foreach (var item in queryAutos)
                        {
                            AutoSearch auto = new AutoSearch();
                            auto.Number = item.Number;
                            auto.Make = item.Maker;
                            auto.Model = item.ConceptName;
                            auto.ClassAuto = (e_AutoClass)Convert.ToInt32(item.Class);
                            auto.PriceKm = item.KmRate;
                            auto.PriceDay = item.DayRate;
                            auto.CurrentStatus = (CurrentStatus)item.Status;
                            auto.Photo = item.PhotoFileName;

                            autos.Add(auto);
                        }
                    }
                    catch (InvalidOperationException ex)
                    {
                        throw ex;
                    }
                }
            }
            return autos;
        }
예제 #3
0
        public ActionResult Index(SearchCar searchcar = null, int page = 1, string sort = "Make", string sortDir = "Ascending")
        {
            int totalRecords = 10;
            IList<SearchCar> searchCarList = null;

            if (searchcar.Model != null && searchcar.Make != null)
            {
                AutoSearch autoS = new AutoSearch();
                searchcar.AssignTo(autoS);
                IList<AutoSearch> autoSearchList = AutoAPI.GetAutos(autoS);
                searchCarList = new List<SearchCar>();

                foreach (AutoSearch item in autoSearchList)
                {
                    var autose = new SearchCar
                    {
                        ClassAuto = item.ClassAuto,
                        Make = item.Make,
                        Model = item.Model,
                        Photo = item.Photo,
                        Number = item.Number,
                        PriceDay = item.PriceDay,
                        PriceKm = item.PriceKm,
                        CurrentStatus = item.CurrentStatus
                    };
                    searchCarList.Add(autose);
                }
            }

            else
            {
                IList<AutoSearch> autoSearchList = AutoAPI.GetAutos();
                searchCarList = new List<SearchCar>();

                foreach (AutoSearch item in autoSearchList)
                {
                    var autose = new SearchCar
                    {
                        ClassAuto = item.ClassAuto,
                        Make = item.Make,
                        Model = item.Model,
                        Photo = item.Photo,
                        Number = item.Number,
                        PriceDay=item.PriceDay,
                        PriceKm=item.PriceKm,
                         CurrentStatus=item.CurrentStatus
                    };
                    searchCarList.Add(autose);
                }
            }

            PagedSearchCarModel model = new PagedSearchCarModel
            {
                PageSize = pageSize,
                PageNumber = page,
                Car = searchCarList,
                TotalRows = totalRecords
            };

            if (Request.IsAjaxRequest())
            { return PartialView("AjaxSearchCar_Grid", model); }

            return View(model);
        }