Esempio n. 1
0
        public async Task <ActionResult> Index()
        {
            var municipalities = await _placesService.GetAllMunicipalities();

            var res = mapper.Map <List <Municipality>, List <MunicipalityViewModel> >(municipalities);
            IndexMunicipalityViewModel indexViewModel = new IndexMunicipalityViewModel();

            indexViewModel.ListMunicipalities = res;
            indexViewModel.Municipality       = new MunicipalityViewModel();
            indexViewModel.IsError            = false;
            indexViewModel.IsEditing          = false;
            return(View(indexViewModel));
        }
Esempio n. 2
0
        public async Task <ActionResult> EditMunicipality(string id)
        {
            var municipalities = await _placesService.GetAllMunicipalities();

            var res = mapper.Map <List <Municipality>, List <MunicipalityViewModel> >(municipalities);
            IndexMunicipalityViewModel indexViewModel = new IndexMunicipalityViewModel();

            indexViewModel.ListMunicipalities = res;
            var municipality = res.Where(m => m.Id.ToString().Equals(id)).FirstOrDefault();

            indexViewModel.Municipality = municipality;
            indexViewModel.IsEditing    = true;
            indexViewModel.IsError      = false;
            return(View("Index", indexViewModel));
        }
Esempio n. 3
0
        public async Task <ActionResult> EditMunicipality(MunicipalityViewModel municipality)
        {
            if (ModelState.IsValid)
            {
                var res      = mapper.Map <MunicipalityViewModel, Municipality>(municipality);
                var isEdited = await _placesService.EditMunicipality(res);

                if (isEdited)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError("municipality.Code", "El código ya está registrado");
            }
            var municipalities = await _placesService.GetAllMunicipalities();

            var mun = mapper.Map <List <Municipality>, List <MunicipalityViewModel> >(municipalities);
            IndexMunicipalityViewModel indexViewModel = new IndexMunicipalityViewModel();

            indexViewModel.ListMunicipalities = mun;
            indexViewModel.Municipality       = municipality;
            indexViewModel.IsError            = true;
            indexViewModel.IsEditing          = true;
            return(View("Index", indexViewModel));
        }