public ActionResult Edit(City city, int id)
 {
     city            = cityrepository.GetById(id);
     ViewBag.StateId = new SelectList(staterepository.GetAll(), "StateId", "StateName", city.StateId);
     ViewBag.CityId  = new SelectList(cityrepository.GetAll(), "CityId", "CityName", city.CityId);
     return(View(city));
 }
        //helper method
        private void PrepareCityOfLocationForSaving(ref Company newCompany)
        {
            if (newCompany.Locations.Count() == 0)
            {
                return;
            }

            Location locationOfNewCompany = newCompany.Locations
                                            .FirstOrDefault();

            locationOfNewCompany.City = cityService
                                        .GetById(locationOfNewCompany.City.Id);
        }
Beispiel #3
0
        public IActionResult Detail(int id)
        {
            var city = _cityService.GetById(id);

            var model = new CityDetailModel
            {
                Id          = city.Id,
                Name        = city.Name,
                BusStations = _busStationService.GetByCity(id),
                Carriers    = _carrierService.GetByCity(city),
                ImageUrl    = city.ImageUrl,
                ZipCode     = city.ZipCode
            };

            model.OpenWeather = GetWeatherInfo(model.Name);

            return(View(model));
        }
Beispiel #4
0
        public IActionResult GetById(int Id)
        {
            try
            {
                var result = _city.GetById(Id);

                if (result == null)
                {
                    return(NotFound());
                }

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, e));
            }
        }
Beispiel #5
0
        private IEnumerable <Location> AddNewLocation(IEnumerable <Location> locations, Location newLocation)
        {
            List <Location> locationsForReturn;

            newLocation.City = cityService.GetById(newLocation.City.Id);

            if (locations.Count() == 0)
            {
                locationsForReturn = new List <Location>();
                locationsForReturn.Add(newLocation);

                return((IEnumerable <Location>)locationsForReturn);
            }

            locationsForReturn = locations.ToList();
            locationsForReturn.Add(newLocation);

            return((IEnumerable <Location>)locationsForReturn);
        }