public static PlaceViewModel MapToPlaceViewModel(this Place place) { var obj = new PlaceViewModel { PlaceId = place.PlaceId, PlaceName = place.PlaceName, Description = place.Description, InternalRanking = place.InternalRanking, PlaceTypeId = place.PlaceTypeId, //RelatedPlaces = place.RelatedPlaces, Articles = place.Articles, SlideShowPictures = place.SlideshowPictures, Latitude = place.Latitude, Longitude = place.Longitude }; string str = string.Empty; //foreach (var p in place.RelatedPlaces) //{ // str += p.PlaceId.ToString() + ','; //} //obj.RelatedPlaceIds = str; str = string.Empty; foreach (var a in place.Articles) { str += a.ArticleId.ToString() + ','; } obj.RelatedArticleIds = str; str = string.Empty; foreach (var s in place.SlideshowPictures) { str += s.PictureId.ToString() + ','; } obj.RelatedSlideShowPictureIds = str; return obj; }
public ActionResult Index(int id = 0) { var domainResponse = _placeManager.GetPlaceWithChildPlacesById(id); if (domainResponse.Result == null) { return HttpNotFound(); } PlaceViewModel model = new PlaceViewModel { PlaceName = domainResponse.Result.PlaceName }; return View(model); }
public ActionResult Create(PlaceViewModel model) { if (ModelState.IsValid) { var placeObj = PreparePlaceViewModelToUpdate(model); var response = _placeManager.CreateNewPlace(placeObj); if (response.Success && response.Result.PlaceId > 0) return RedirectToAction("Index"); else ModelState.AddModelErrors("", response.Messages); } ViewBag.PlaceTypeId = PopulatePlaceTypesSelectList(); ViewBag.ParentStateId = PopulateParentStateSelectList(); ViewBag.ParentCityTownId = PopulateParentCityTownSelectList(); ViewBag.ParentAttractionId = PopulateParentAttractionSelectList(); return View(model); }
private Place PreparePlaceViewModelToUpdate(PlaceViewModel viewModel) { var articleIds = !string.IsNullOrEmpty(viewModel.RelatedArticleIds) ? viewModel.RelatedArticleIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : new string[]{}; var placeIds = !string.IsNullOrEmpty(viewModel.RelatedPlaceIds) ? viewModel.RelatedPlaceIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { }; var slideShowPicIds = !string.IsNullOrEmpty(viewModel.RelatedSlideShowPictureIds) ? viewModel.RelatedSlideShowPictureIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : new string[] { }; var placeObj = viewModel.TransformToPlaceObject(); foreach (var id in articleIds) { var article = new Article { ArticleId = int.Parse(id) }; if (placeObj.Articles == null) placeObj.Articles = new List<Article>(); placeObj.Articles.Add(article); } /*foreach (var id in placeIds) { var place = new Place { PlaceId = int.Parse(id) }; if (placeObj.RelatedPlaces == null) placeObj.RelatedPlaces = new List<Place>(); placeObj.RelatedPlaces.Add(place); }*/ foreach (var id in slideShowPicIds) { var picture = new Picture { PictureId = int.Parse(id) }; if (placeObj.SlideshowPictures == null) placeObj.SlideshowPictures = new List<Picture>(); placeObj.SlideshowPictures.Add(picture); } return placeObj; }
public ActionResult Edit(PlaceViewModel place) { if (ModelState.IsValid) { var placeObj = PreparePlaceViewModelToUpdate(place); var response = _placeManager.EditPlace(placeObj); if (response.Success) { TempData[Constants.TempdataKeys.EditArticleSuccessKey] = true; return RedirectToAction("Index"); } else { ModelState.AddModelErrors("", response.Messages); } } ViewBag.PlaceTypeId = PopulatePlaceTypesSelectList(place.PlaceTypeId); ViewBag.ParentStateId = PopulateParentStateSelectList(place.ParentStateId); ViewBag.ParentCityTownId = PopulateParentCityTownSelectList(place.ParentCityTownId); ViewBag.ParentAttractionId = PopulateParentAttractionSelectList(place.ParentAttractionId); return RedirectToAction("Edit"); }