public IActionResult GetAllCountries() { var countries = _repository.GetCountries(). Select(n => new CountryDto() { Id = n.Id.ToString(), Name = n.Name, Capital = n.Capital, Population = n.Population.GetValueOrDefault(), Region = n.Region }); return(Ok(countries)); }
public IActionResult Index() { var countries = _countriesRepository.GetCountries(); var model = new CountriesViewModel(); var list = new List <CountryViewModel>(); foreach (var elem in countries) { var country = new CountryViewModel { Arabic = elem.NameAr, English = elem.NameEn, CreatedAt = elem.CreatedAt, Id = elem.Id }; list.Add(country); } model.Countries = list; return(View(model)); }
public IActionResult Add() { var model = new ProductModel(); var measurments = _productsRepository.GetMeasurments(); var categories = _categoriesRepository.GetCategories(); var countries = _countriesRepository.GetCountries(); var measurmentList = new List <Measurment>(); var categoryList = new List <Category>(); var countryList = new List <Country>(); foreach (var elem in measurments) { var measurment = new Measurment { Id = elem.Id, UnitEn = elem.UnitEn, UnitAr = elem.UnitAr }; measurmentList.Add(measurment); } foreach (var elem in categories) { var category = new Category { Id = elem.Id, NameEn = elem.NameEn, NameAr = elem.NameAr }; categoryList.Add(category); } foreach (var elem in countries) { var country = new Country { Id = elem.Id, NameAr = elem.NameAr, NameEn = elem.NameEn }; countryList.Add(country); } model.Measurments = measurmentList; model.Categories = categoryList; model.Countries = countryList; return(View(model)); }
// GET api/Countries public IEnumerable <Country> Get() { return(db.GetCountries()); }
public IActionResult Index() { return(View(new IndexViewModel { Products = _productsRepository.GetProducts().Count(), Orders = _ordersRepository.GetOrders().Count(), Categories = _categoriesRepository.GetCategories().Count(), Countries = _countriesRepository.GetCountries().Count(), Users = _usersRepository.GetUsers().Count() })); }
public IActionResult Index(int productPage, int PageSize = 5, int CategoryId = 0) { int countryId = 1; if (Request.Cookies["Contry"] != null) { countryId = Convert.ToInt32(Request.Cookies["Contry"]); } var products = _productRepository.GetProductByContry(countryId, CategoryId); var category = _categoriesRepository.GetCategories(); var CategoryVM = new List <CategoryViewModel>(); foreach (var item in category) { if (Request.Cookies["Language"] == "ar") { var CategoryViewModel = new CategoryViewModel() { Id = item.Id, Name = item.NameAr }; CategoryVM.Add(CategoryViewModel); } else { var CategoryViewModel = new CategoryViewModel() { Id = item.Id, Name = item.NameEn }; CategoryVM.Add(CategoryViewModel); } } StringBuilder param = new StringBuilder(); param.Append("/Product?productPage=:"); var count = products.Count(); var Countries = _countryRepository.GetCountries(); List <CountryVM> CountriesList = new List <CountryVM>(); foreach (var item in Countries) { CountryVM country = new CountryVM(); if (Request.Cookies["Language"] == "en") { country.Id = item.Id; country.Name = item.NameEn; } else { country.Id = item.Id; country.Name = item.NameAr; } CountriesList.Add(country); } ListProductVM listPorductVM = new ListProductVM(); List <ProductViewModel> ListProducts = new List <ProductViewModel>(); foreach (var item in products) { var ProductPictuer = _productRepository.GetProductPictuerById(item.Id); var ProductSpecification = _productRepository.GetProductSpecification(item.Id); if (Request.Cookies["Language"] == "en") { ProductViewModel product = new ProductViewModel() { Id = item.Id, CategoryId = item.CategoryId, Contry = countryId, Name = item.NameEn, Description = item.DescreptionEn, PictuerUrl = ProductPictuer.Image, Price = ProductSpecification.Price }; ListProducts.Add(product); } else { ProductViewModel product = new ProductViewModel() { Id = item.Id, CategoryId = item.CategoryId, Contry = countryId, Name = item.NameAr, Description = item.DescreptionAr, PictuerUrl = ProductPictuer.Image, Price = ProductSpecification.Price }; ListProducts.Add(product); } } listPorductVM.ProductViewModel = ListProducts; listPorductVM.Categories = CategoryVM; listPorductVM.Countries = CountriesList; listPorductVM.PagingInfo = new PagingInfo { CurrentPage = productPage, ItemsPerPage = PageSize, TotalItems = count, urlParam = param.ToString() }; listPorductVM.ProductViewModel = listPorductVM.ProductViewModel.OrderBy(x => x.Name).Skip((productPage - 1) * PageSize) .Take(PageSize).ToList(); return(View(listPorductVM)); }
public async Task <IActionResult> Index() { if (Request.Cookies["Language"] == null) { var locale = Request.HttpContext.Features.Get <IRequestCultureFeature>(); var BrowserCulture = locale.RequestCulture.UICulture.ToString(); CookieOptions option = new CookieOptions(); option.Expires = DateTime.Now.AddDays(30); Response.Cookies.Append("Language", BrowserCulture, option); } var countries = _countriesRepository.GetCountries(); var products = await _productRepository.GetFeaturedProducts(); var categories = _categriesRepository.GetLastFourCategories(); List <CategoryViewModel> CategorysVM = new List <CategoryViewModel>(); List <ProductViewModel> productsVM = new List <ProductViewModel>(); if (Request.Cookies["Language"] == "ar") { foreach (var item in products) { ProductViewModel product = new ProductViewModel() { Id = item.Id, CategoryId = item.CategoryId, Description = item.DescreptionAr, Name = item.NameAr, Price = _productRepository.GetProductSpecification(item.Id).Price, PictuerUrl = _productRepository.GetProductPictuerById(item.Id).Image }; productsVM.Add(product); } foreach (var item in categories) { CategoryViewModel CategoryVM = new CategoryViewModel() { Banner = item.Banner, Name = item.NameAr }; CategorysVM.Add(CategoryVM); } } else { foreach (var item in products) { ProductViewModel product = new ProductViewModel() { Id = item.Id, CategoryId = item.CategoryId, Description = item.DescreptionEn, Name = item.NameEn, Price = _productRepository.GetProductSpecification(item.Id).Price, PictuerUrl = _productRepository.GetProductPictuerById(item.Id).Image }; productsVM.Add(product); } foreach (var item in categories) { CategoryViewModel CategoryVM = new CategoryViewModel() { Banner = item.Banner, Name = item.NameEn }; CategorysVM.Add(CategoryVM); } } var model = new CountriesViewModel(); var list = new List <CountryViewModel>(); foreach (var elem in countries) { var country = new CountryViewModel { Arabic = elem.NameAr, English = elem.NameEn, CreatedAt = elem.CreatedAt, Id = elem.Id }; list.Add(country); } model.Countries = list; model.products = productsVM; model.Categries = CategorysVM; return(View(model)); }
public ActionResult Index() { var countryInfoList = _countriesRepository.GetCountries(); var countryDropdownList = new List <SelectListItem>(); if (countryInfoList != null) { foreach (var country in countryInfoList) { countryDropdownList.Add(new SelectListItem() { Text = country.name, Value = country.code }); } } CountryModel countryModel = new CountryModel { countryInfo = countryInfoList, countryDropdownItems = countryDropdownList }; var selectedCountryCode = _countriesRepository.GetCountries()?.First()?.code; var cityInfoList = _citiesRepository.GetCitiesRequest(selectedCountryCode); var cityDropdownList = new List <SelectListItem>(); if (cityInfoList != null) { foreach (var city in cityInfoList) { cityDropdownList.Add(new SelectListItem() { Text = city.city, Value = city.city }); } } CityModel cityModel = new CityModel { cityInfo = cityInfoList, cityDropdownItems = cityDropdownList }; var selectedCityName = cityInfoList.FirstOrDefault().city; var measurementsInfoList = _measurementsRepository.GetMeasurementsRequest(selectedCityName); var measurementsDTOList = MeasurementsMapper.MapMeasurements(measurementsInfoList); MeasurementsDTOModel measurementsDTOModel = new MeasurementsDTOModel { measurementsDTO = measurementsDTOList }; AreaSelectionViewModel areaSelectionViewModel = new AreaSelectionViewModel() { countryModel = countryModel, cityModel = cityModel, measurementsDTOModel = measurementsDTOModel }; return(View(areaSelectionViewModel)); }
public IHttpActionResult GetCountries() { var countries = countriesRepository.GetCountries(); return(Ok(countries)); }