// GET: BaseLayers/Edit/5 public ActionResult Edit(long id) { var pagesRepository = new PagesRepository(); var model = pagesRepository.GetById(id); var tagIds = model.Tags != null ? model.Tags.Select(x => x.Id) : new List<long>(); var tagsRepository = new TagsRepository(); IDisposable context = null; ViewBag.ListOfTags = tagsRepository.GetAll(out context).ToList().Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Name, Selected = tagIds.Contains(x.Id) }); context?.Dispose(); if (model != null) return View(new EditPageViewModel(model)); return HttpNotFound(); }
public ActionResult Index() { var tagsRepository = new TagsRepository(); IDisposable context; var tags = tagsRepository.GetAll(out context).ToList().Select(x => new TagViewModel(x)).ToList(); using (context) { return View(tags); } }
// GET: BaseLayers/Create public ActionResult Add() { var regionsRepository = new RegionsRepository(); IDisposable context = null; ViewBag.ListOfRegions = regionsRepository.GetAll(out context).ToList().Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Name }); context?.Dispose(); var tagsRepository = new TagsRepository(); IDisposable context1 = null; ViewBag.ListOfTags = tagsRepository.GetAll(out context).ToList().Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.Name }); context1?.Dispose(); return View(new PageViewModel(new Page())); }