public async Task <IActionResult> Update(CategoryLocalTravelViewModel model, string saveCommand = null) { await PrepareCityList(model); if (!ModelState.IsValid) { return(View("CategoryLocalTravelForm", model)); } var entity = new CategoryLocalTravel(); _mapper.Map(model, entity); var response = await HttpRequestFactory.Put(Constants.BaseApiUrl + "CategoryLocalTravel/" + model.Id, entity); var outmodel = response.ContentAsType <SingleModelResponse <CategoryLocalTravel> >(); if (outmodel.DidError || !response.IsSuccessStatusCode) { ViewBag.ErrorMsg = outmodel.ErrorMessage ?? response.ReasonPhrase; return(View("CategoryLocalTravelForm", model)); } AlertShow(); if (saveCommand != Constants.SaveContinute) { return(RedirectToAction("Index")); } model = _mapper.Map(outmodel.Model, model); return(RedirectToAction("Edit", new { id = model.Id })); }
public async Task <IActionResult> Create() { var model = new CategoryLocalTravelViewModel(); await PrepareCityList(model); return(View("CategoryLocalTravelForm", model)); }
public async Task <IActionResult> Edit(int id) { var outputModel = await GetSingle(id); var model = new CategoryLocalTravelViewModel(); _mapper.Map(outputModel.Model, model); await PrepareCityList(model); return(View("CategoryLocalTravelForm", model)); }
private async Task PrepareCityList(CategoryLocalTravelViewModel model) { var response = await HttpRequestFactory.Get(Constants.BaseApiUrl + "CategoryCity"); var outputModel = response.ContentAsType <ListModelResponse <CategoryCity> >(); model.Cities = outputModel.Model .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.CityName }).ToList(); }