Esempio n. 1
0
        public IActionResult Index()
        {
            CityDetailsViewModel cityDetailsViewModel = new CityDetailsViewModel
            {
                Cities  = repository.Cities.ToList(),
                Streets = repository.Streets.ToList()
            };

            return(View(cityDetailsViewModel));
        }
        public IHttpActionResult Get(Guid id)
        {
            CityViewModel        cityModel    = this._cityService.GetCityById(id);
            CityDetailsViewModel detailsModel = new CityDetailsViewModel
            {
                Name           = cityModel.Name,
                HospitalsCount = cityModel.Hospitals.Count,
                PersonsCount   = cityModel.Persons.Count
            };

            return(Ok(detailsModel));
        }
Esempio n. 3
0
        // GET: CityController/Details/5
        public ActionResult Details(int id)
        {
            City city = _cityService.FindBy(id);

            if (city != null)
            {
                CityDetailsViewModel cityDetailsVM = new CityDetailsViewModel();
                cityDetailsVM.Id         = id;
                cityDetailsVM.Citizens   = _peopleService.FindByCity(id);
                cityDetailsVM.CityName   = city.Name;
                cityDetailsVM.NationName = _countryService.FindBy(city.Nation.Id).Name;
                return(View(cityDetailsVM));
            }
            return(RedirectToAction(nameof(Index)));
        }
        public IHttpActionResult Post([FromBody] CreateCityViewModel cityModel)
        {
            try
            {
                Guid   id = this._cityService.InsertCity(cityModel);
                string cityDetailsLocation        = $"{Request.RequestUri}/{id}";
                CityDetailsViewModel detailsModel = new CityDetailsViewModel
                {
#pragma warning disable CA1062 // Validate arguments of public methods
                    Name = cityModel.Name,
#pragma warning restore CA1062 // Validate arguments of public methods
                };
                return(Created(cityDetailsLocation, detailsModel));
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                return(InternalServerError(ex));
            }
        }
Esempio n. 5
0
 public void SaveCityDetails(CityDetailsViewModel cityDetailsViewModel)
 {
     try
     {
         //string uniqueFileName = null;
         if (cityDetailsViewModel.Photo != null)
         {
             string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "Files");
             //uniqueFileName = Guid.NewGuid().ToString() + "_" + cityDetailsViewModel.Photo.FileName;
             string filePath = Path.Combine(uploadsFolder, Guid.NewGuid().ToString() + "_" + cityDetailsViewModel.Photo.FileName);
             cityDetailsViewModel.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
         }
         if (cityDetailsViewModel.StreetsId.Count != 0)
         {
             foreach (var streetId in cityDetailsViewModel.StreetsId)
             {
                 StreetCityDetail streetCityDetail = new StreetCityDetail
                 {
                     CityDetailId = cityDetailsViewModel.CityId,
                     StreetId     = streetId
                 };
                 context.StreetCityDetails.Add(streetCityDetail);
             }
         }
         CityDetail cityDetail = new CityDetail
         {
             FullName   = cityDetailsViewModel.UserFulName,
             HomeNumber = cityDetailsViewModel.HomeNumber,
             FileName   = cityDetailsViewModel.Photo.FileName,
             BirthDate  = cityDetailsViewModel.UserBirthDate,
             CityId     = cityDetailsViewModel.CityId
         };
         context.CityDetails.Add(cityDetail);
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         string exception = ex.ToString();
     }
 }
Esempio n. 6
0
 public CityDetailsView()
 {
     this.InitializeComponent();
     DataContextChanged += (s, e) => { ViewModel = DataContext as CityDetailsViewModel; };
 }
Esempio n. 7
0
 public IActionResult Index(CityDetailsViewModel cityDetailsViewModel)
 {
     //  repository.SaveCityDetails(cityDetailsViewModel);
     return(RedirectToAction(nameof(Index)));
 }