Esempio n. 1
0
        public ActionResult Details(string id)
        {
            try
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }


                CityArea          cityArea          = _unitOfWork.CityArea.GetByID(Convert.ToInt32(id));
                CityAreaViewModel cityAreaViewModel = new CityAreaViewModel();

                cityAreaViewModel.CityAreaName     = cityArea.CityAreaName;
                cityAreaViewModel.SelectedCity     = cityArea.City.CityName;
                cityAreaViewModel.SelectedProvince = cityArea.City.Province.ProvinceName;

                if (cityAreaViewModel != null)
                {
                    return(PartialView("_DetailsCityArea", cityAreaViewModel));
                }
                else
                {
                    return(HttpNotFound());
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 2
0
        public ActionResult AddNew(CityAreaViewModel cityAreaViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    CityAreaRepository cityAreaRepository = new CityAreaRepository(new AutoSolutionContext());
                    bool IsExist = cityAreaRepository.isExist(cityAreaViewModel.CityAreaName, cityAreaViewModel.SelectedCity);
                    if (!IsExist)
                    {
                        CityArea cityArea = new CityArea();

                        cityArea.CityAreaName = cityAreaViewModel.CityAreaName;
                        cityArea.CityId       = Convert.ToInt32(cityAreaViewModel.SelectedCity);
                        _unitOfWork.CityArea.Add(cityArea);
                        _unitOfWork.Complete();
                        _unitOfWork.Dispose();
                        return(RedirectToAction("GetCityArea"));
                    }
                    else
                    {
                        return(RedirectToAction("GetCityArea"));
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(View());
        }
        public CityAreaViewModel AddNewCityArea()
        {
            ProvinceRepository provinceRepository = new ProvinceRepository(new AutoSolutionContext());
            CityRepository     cityRepository     = new CityRepository(new AutoSolutionContext());
            CityAreaViewModel  cityAreaViewModel  = new CityAreaViewModel()
            {
                ProvinceList = provinceRepository.GetProvinces(),
                CityList     = cityRepository.GetCities(),
            };

            return(cityAreaViewModel);
        }
        public CityAreaViewModel GetCityArea(int PageNo, int TotalCount)
        {
            CityRepository     cityRepository     = new CityRepository(new AutoSolutionContext());
            ProvinceRepository provinceRepository = new ProvinceRepository(new AutoSolutionContext());
            var cityAreaViewModel = new CityAreaViewModel()
            {
                ProvinceList = provinceRepository.GetProvinces(),
                CityList     = cityRepository.GetCities(),
                CityAreaList = AutoSolutionContext.CityAreas.OrderBy(x => x.CityAreaName).Skip((PageNo - 1) * 10).Take(10).ToList(),
                Pager        = new Pager(TotalCount, PageNo, 10)
            };

            return(cityAreaViewModel);
        }
 public CityAreaViewModel GetCityArea(int PageNo, int TotalCount, string SearchTerm, string SelectedCity)
 {
     if ((!string.IsNullOrEmpty(SelectedCity)) && (!string.IsNullOrEmpty(SearchTerm)))
     {
         ProvinceRepository provinceRepository = new ProvinceRepository(new AutoSolutionContext());
         CityRepository     cityRepository     = new CityRepository(new AutoSolutionContext());
         int Selecteditem      = Convert.ToInt32(SelectedCity);
         var cityAreaViewModel = new CityAreaViewModel()
         {
             ProvinceList = provinceRepository.GetProvinces(),
             CityList     = cityRepository.GetCities(),
             CityAreaList = AutoSolutionContext.CityAreas.OrderBy(x => x.CityAreaName).Where(x => x.CityAreaName.ToLower().Contains(SearchTerm.ToLower()) && x.CityId == Selecteditem).Skip((PageNo - 1) * 10).Take(10).ToList(),
             Pager        = new Pager(TotalCount, PageNo, 10)
         };
         return(cityAreaViewModel);
     }
     return(null);
 }