示例#1
0
        public ActionResult CarDetail(int id)
        {
            var car = DatAcessService.FindCar(id);

            if (car == null)
            {
                return(HttpNotFound());
            }
            return(View(car));
        }
        public ActionResult OrderIndex()
        {
            var ord = DatAcessService.Orders;

            foreach (var o in ord)
            {
                o.Car = DatAcessService.FindCar(o.CarId);
            }
            return(View(ord));
        }
示例#3
0
        public ActionResult Index(string res = null, int page = 1)
        {
            User.Identity.GetUserId();

            var ords = DatAcessService.Orders.Where(o => o.User_Id == User.Identity.GetUserId());

            if (ords.Count() == 0)
            {
                return(View("EmptyCart"));
            }
            foreach (var o in ords)
            {
                o.Car = DatAcessService.FindCar(o.CarId);
            }
            PersonalCabViewModel model = new PersonalCabViewModel()
            {
                User   = DatAcessService.Users.FirstOrDefault(u => u.Id == User.Identity.GetUserId()),
                Orders = ords
            };

            ViewBag.Res     = res;
            ViewBag.CarItem = ords.FirstOrDefault().CarItem;
            return(View(model));
        }
示例#4
0
        public ActionResult Index(string id = null, int page = 1, string sort = null)
        {
            page = page < Convert.ToInt32(Math.Ceiling((double)DatAcessService.Cars.Count() / pageSize)) ? page :
                   Convert.ToInt32(Math.Ceiling((double)DatAcessService.Cars.Count() / pageSize));


            List <CarDTO> crs = new List <CarDTO>();

            if (id == null)
            {
                crs = DatAcessService.Cars
                      .Where(c => c.IsDeleted == false)
                      .OrderBy(car => car.Id)
                      .Skip((page - 1) * pageSize)
                      .Take(pageSize).ToList();
            }
            else
            {
                id = id.Substring(0, id.Length - 1);
                string[] strid = id.Split(Convert.ToChar("I"));


                for (int i = 0; i < strid.Length; i++)
                {
                    crs.Add(DatAcessService.FindCar(Convert.ToInt32(strid[i])));
                }
                crs = crs.Skip((page - 1) * pageSize)
                      .Take(pageSize).ToList();
            }



            IEnumerable <CarDTO> cars = crs.Where(c => c.IsDeleted == false).OrderBy(x => x.Popular);

            if (sort != null)
            {
                if (sort == "ascending")
                {
                    cars = cars.OrderBy(c => c.Price);
                }
                else if (sort == "descending")
                {
                    cars = cars.OrderByDescending(c => c.Price);
                }
            }
            CarsListViewModel model = new CarsListViewModel
            {
                Cars = cars
                ,
                PagingInfo = new PagingInfo
                {
                    TotalItems   = DatAcessService.Cars.Count(),
                    CurrentPage  = page,
                    ItemsPerPage = pageSize,
                }
            };
            List <int> popCar = new List <int>();

            int[] ids = cars.OrderBy(x => x.Popular).Select(x => x.Id).ToArray();
            if (ids.Length > 3)
            {
                for (int i = 0; i < ids.Length / 3; i++)
                {
                    popCar.Add(i);
                }
            }
            else
            {
                popCar.Add(ids.FirstOrDefault());
            }



            ViewBag.Sort = new List <string>()
            {
                "ascending", "descending"
            };
            ViewBag.popCar = popCar;
            ViewBag.cars   = cars;
            return(View("Index", model));
        }