public ActionResult Edit(EditPageViewModel model) { try { var tagsRepository = new TagsRepository(); var pagesRepository = new PagesRepository(); var originalPage = pagesRepository.GetById(model.Id); if (model.SelectedTags != null) { var tags = tagsRepository.GetByStringIds(model.SelectedTags); originalPage.Tags = new List<Tag>(tags); } else { originalPage.Tags = null; } originalPage.Name = model.Name; originalPage.Description = model.Description; originalPage.Content = model.Content; originalPage.ExternalId = model.ExternalId; pagesRepository.Update(originalPage); return RedirectToAction("Index"); } catch (Exception ex) { return View(); } }
public ActionResult Add(PageViewModel model) { try { var tagsRepository = new TagsRepository(); var pointsRepository = new PointsRepository(); var pagesRepository = new PagesRepository(); var page = new Page() { Name = model.Name, Description = model.Description, Content = model.Content, ExternalId = model.ExternalId }; if (model.SelectedTags != null) { var tags = tagsRepository.GetByStringIds(model.SelectedTags); page.Tags = new List<Tag>(tags); } else { page.Tags = null; } var pageId = pagesRepository.Add(page); if (!string.IsNullOrEmpty(model.Point?.Name)) { model.Point.PageId = pageId; pointsRepository.Add(model.Point); } if (model.RegionId != null) { var regionsRepository = new RegionsRepository(); var region = regionsRepository.GetById(model.RegionId.Value); region.Page = null; region.PageId = pageId; regionsRepository.Update(region); } return RedirectToAction("Index"); } catch (Exception ex) { return View(); } }