public async Task <CityLanguageViewModel> GetCityById(Guid vId) { CityLanguageViewModel vResult = null; try { var vResponse = await _vApiClient.ExecuteGet <CityLanguageViewModel>("Cities/SelectCityById");//Change name if (vResponse == null) { return(vResult); } var vClientResponse = (ClientResponseViewModel)vResponse.Content; if (vClientResponse.Result == "False") { vResult = null; } else { vResult = JsonConvert.DeserializeObject <CityLanguageViewModel>(vClientResponse.Result); } } catch (Exception vEx) { var Message = vEx.Message; vResult = null; } return(vResult); }
public async Task <IActionResult> EditCity(Guid valId) { try { CityLanguageViewModel vCity = new CityLanguageViewModel(); if (Startup._IdCity != Guid.Empty) { vCity.ListCity = new List <CityViewModel>(); vCity = await _vCityService.GetCityById(valId); return(View(vCity)); } } catch (Exception) { return(View()); } return(View()); }
public async Task <ClientResponseViewModel> EditCity(CityLanguageViewModel vModel) { ClientResponseViewModel vResult = null; try { var vResponse = await _vApiClient.ExecutePost <ClientResponseViewModel>("/Cities", vModel);//change controller if (vResponse == null) { return(vResult); } vResult = (ClientResponseViewModel)vResponse.Content; } catch (Exception vEx) { string vMensage = vEx.Message; vResult = null; } return(vResult); }
public async Task <IActionResult> Add() { CityLanguageViewModel vModel = new CityLanguageViewModel(); try { List <Language> vLanguage = await _vLanguageSerivce.GetLanguage(); List <Guid> vIdLanguage = vLanguage.Select(e => e.Id).ToList(); if (Request.Form.Count != 0 && vIdLanguage.Count != 0) { vModel.ListCity = new List <CityViewModel>(); FileViewModel vFile = new FileViewModel(); if (Request.Form.Files != null && Request.Form.Files.Count > 0) { IFormFile file = Request.Form.Files[0]; byte[] data; using (var br = new BinaryReader(file.OpenReadStream())) data = br.ReadBytes((int)file.OpenReadStream().Length); vFile.FileData = data; vFile.NameFile = file.Name; vFile.Size = file.Length; } ; for (int i = 0; i <= vIdLanguage.Count - 1; i++) { vModel.ListCity.Add(new CityViewModel { Name = Request.Form["Name"], Icon = Request.Form["Icono"], Temperature = !string.IsNullOrEmpty(Request.Form["Temperature"]) ? Convert.ToInt32(Request.Form["Temperature"]) : 0, Altitude = !string.IsNullOrEmpty(Request.Form["Altitude"]) ? Convert.ToInt32(Request.Form["Altitude"]) : 0, Population = !string.IsNullOrEmpty(Request.Form["Population"]) ? Convert.ToInt32(Request.Form["Population"]) : 0, UserCreate = "Admin",//change for session user DateCreate = DateTime.Now, State = 1, Photo = vFile, IdLanguage = vIdLanguage.ElementAt(i), Slogan = Request.Form["data-slogan" + i], Description = Request.Form["data-description" + i], Location = Request.Form["data-location" + i], FarmingProduction = Request.Form["data-farming-production" + i], DescriptionDistricts = Request.Form["data-description-districts" + i], }); } ClientResponseViewModel vResponse = await _vCityService.AddCity(vModel); if (vResponse != null) { if (vResponse.Result == "1") { return(Json(new { content = "1" })); } else if (vResponse.Result == "2") { return(Json(new { content = vResponse.Result })); } else if (vResponse.Result == "5") { return(Json(new { content = vResponse.Result })); } else if (vResponse.Result == "3" || vResponse.Result == "4") { return(Json(new { content = vResponse.Result })); } } } } catch (Exception) { return(Json(new { content = "6" })); } return(Json(new { content = "6" })); }