public void CanGetAllCarType() { var repo = new CarTypeRepository(); Assert.AreEqual(2, repo.GetAll().Count); Assert.AreEqual("Used", repo.GetAll().FirstOrDefault().CarTypeName); }
public ActionResult Index(int page = 1, string Brand = "All", string Type = "All", string SortType = "Price") { int pageSize = 5; var cars = carRepository.FindCars(pageSize * (page - 1), pageSize, Brand, Type, SortType); PageInfo pageInfo = new PageInfo { PageNumber = page, PageSize = pageSize, TotalItems = carRepository.FilteredCarsNumber(Brand, Type) }; CarPageViewModel carPageViewModel = new CarPageViewModel { Cars = cars, PageInfo = pageInfo }; var brands = carBrandRepository.GetAll().ToList(); brands.Insert(0, new CarBrand { Brand = "All", BrandID = 0 }); carPageViewModel.Brands = new SelectList(brands.Select(brand => brand.Brand).ToList(), Brand); var carTypes = carTypeRepository.GetAll().ToList(); carTypes.Insert(0, new CarType { Type = "All", TypeId = 0 }); carPageViewModel.CarTypes = new SelectList(carTypes.Select(type => type.Type).ToList(), Type); carPageViewModel.SortType = new SelectList(new List <string> { "Price", "Name" }, SortType); return(View(carPageViewModel)); }
public void CanRemoveCarType() { var repo = new CarTypeRepository(); Assert.AreEqual(2, repo.GetAll().Count); repo.Remove(1); Assert.AreEqual(1, repo.GetAll().Count); }
public void CanAddCarType() { var repo = new CarTypeRepository(); Assert.AreEqual(2, repo.GetAll().Count); repo.Add(new CarType() { CarTypeName = "Restored" }); Assert.AreEqual(3, repo.GetAll().Count); }
public CarTypeModel GetCarTypeById(int carTypeId) { //unitOfWork.StartTransaction(); CarTypeRepository repo = new CarTypeRepository(unitOfWork); CarTypeModel carTypeModel = new CarTypeModel(); CarType carType = new CarType(); AutoMapper.Mapper.Map(carTypeModel, carType); carType = repo.GetAll().Where(x => x.CarTypeId == carTypeId).FirstOrDefault(); //unitOfWork.Commit(); AutoMapper.Mapper.Map(carType, carTypeModel); return carTypeModel; }
public List<CarTypeModel> GetAllCarTypes() { //unitOfWork.StartTransaction(); CarTypeRepository repo = new CarTypeRepository(unitOfWork); List<CarTypeModel> carTypeModelList = new List<CarTypeModel>(); List<CarType> carTypeList = new List<CarType>(); AutoMapper.Mapper.Map(carTypeModelList, carTypeList); carTypeList = repo.GetAll().OrderByDescending(x=>x.CarTypeId).ToList(); //unitOfWork.Commit(); AutoMapper.Mapper.Map(carTypeList, carTypeModelList); return carTypeModelList; }
public bool CheckExistance(int carTypeId) { //unitOfWork.StartTransaction(); CarTypeRepository repo = new CarTypeRepository(unitOfWork); var city = repo.GetAll().Where(x => x.CarTypeId == carTypeId).Count(); //unitOfWork.Commit(); if (city > 0) { return true; } else { return false; } }