public ActionResult Create(StateProvinceViewModel model) { try { if (model.CountryId == 0) { ModelState.AddModelError("", "select country"); } if (ModelState.IsValid) { var stateProvince = new StateProvince { Name = model.Name, Published = model.Published, DisplayOrder = model.DisplayOrder, Abbreviation = model.Abbreviation, CountryId = model.CountryId }; _stateProvinceService.InsertStateProvince(stateProvince); SuccessNotification("State added successfully."); return(RedirectToAction("List")); } model.AvailableCountry = GetCountryList(); ErrorNotification("Fill required fields"); return(View(model)); } catch (System.Exception) { throw; } }
public ActionResult Create() { var model = new StateProvinceViewModel(); model.AvailableCountry = GetCountryList(); return(View(model)); }
public ActionResult Edit(int Id) { if (!IsValidateId(Id)) { return(HttpNotFound()); } var stateProvince = _stateProvinceService.GetStateProvinceById(Id); if (stateProvince == null) { return(HttpNotFound()); } var model = new StateProvinceViewModel { Id = stateProvince.Id, Name = stateProvince.Name, CountryName = _countryService.GetCountryById(stateProvince.Id).Name, DisplayOrder = stateProvince.DisplayOrder, Published = stateProvince.Published, CountryId = stateProvince.CountryId, Abbreviation = stateProvince.Abbreviation, AvailableCountry = GetCountryList() }; return(View(model)); }
public ViewResult Create() { var stateProvinceVm = new StateProvinceViewModel { IsActive = true, Countries = new SelectList(_countryService.GetAllCountries(), "Id", "Name") }; return(View(stateProvinceVm)); }
public ActionResult Edit(StateProvinceViewModel stateProvinceVm) { if (ModelState.IsValid) { var stateProvince = Mapper.Map <StateProvinceViewModel, StateProvince>(stateProvinceVm); _stateProvinceService.UpdateStateProvince(stateProvince); _unitOfWork.Commit(); return(RedirectToAction("Index")); } stateProvinceVm.Countries = new SelectList(_countryService.GetAllCountries(), "Id", "Name", stateProvinceVm.CountryId); return(View(stateProvinceVm)); }
/// <summary> /// To the view model. /// </summary> /// <param name="model">The model.</param> /// <returns></returns> public static StateProvinceViewModel ToViewModel(this StateProvinceModel model) { if (model == null) { return(null); } var entity = new StateProvinceViewModel { StateProvinceID = model.StateProvinceID, StateProvinceName = model.StateProvinceName }; return(entity); }
/// <summary> /// To the model. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public static StateProvinceModel ToModel(this StateProvinceViewModel entity) { if (entity == null) { return(null); } var model = new StateProvinceModel { StateProvinceID = entity.StateProvinceID, StateProvinceName = entity.StateProvinceName }; return(model); }
public ActionResult Edit(StateProvinceViewModel model) { if (ModelState.IsValid) { var stateProvince = _stateProvinceService.GetStateProvinceById(model.Id); stateProvince.Id = model.Id; stateProvince.Name = model.Name; stateProvince.DisplayOrder = model.DisplayOrder; stateProvince.Published = model.Published; stateProvince.CountryId = model.CountryId; stateProvince.Abbreviation = model.Abbreviation; _stateProvinceService.UpdateStateProvince(stateProvince); return(RedirectToAction("List")); } model.AvailableCountry = GetCountryList(); return(View(model)); }
public ActionResult Edit(StateProvinceViewModel model) { if (ModelState.IsValid) { var stateProvince = _stateProvinceService.GetStateProvinceById(model.Id); stateProvince.Id = model.Id; stateProvince.Name = model.Name; stateProvince.DisplayOrder = model.DisplayOrder; stateProvince.Published = model.Published; stateProvince.CountryId = model.CountryId; stateProvince.Abbreviation = model.Abbreviation; _stateProvinceService.UpdateStateProvince(stateProvince); SuccessNotification("State updated successfully."); return(RedirectToAction("List")); } model.AvailableCountry = GetCountryList(); ErrorNotification("Fill required fields"); return(View(model)); }
public ActionResult Create(StateProvinceViewModel model) { if (model.CountryId == 0) { ModelState.AddModelError("", "select country"); } if (ModelState.IsValid) { var stateProvince = new StateProvince { Name = model.Name, Published = model.Published, DisplayOrder = model.DisplayOrder, Abbreviation = model.Abbreviation, CountryId = model.CountryId }; _stateProvinceService.InsertStateProvince(stateProvince); return(RedirectToAction("List")); } model.AvailableCountry = GetCountryList(); return(View(model)); }