public void Should_return_page_by_id_with_no_deleted_page_modules() { using (var context = new WeapsyDbContext(_contextOptions)) { var repository = new PageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); var page = repository.GetById(_siteId, _pageId1); Assert.AreEqual(0, page.PageModules.Count(x => x.Status == PageModuleStatus.Deleted)); } }
public void Should_return_null_if_page_is_deleted() { using (var context = new WeapsyDbContext(_contextOptions)) { var repository = new PageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); var page = repository.GetById(_deletedPageId); Assert.Null(page); } }
public void Should_return_page_by_id() { using (var context = new WeapsyDbContext(_contextOptions)) { var repository = new PageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); var page = repository.GetById(_siteId, _pageId1); Assert.NotNull(page); } }
public void Should_save_new_page() { var newPage = PageFactory.Page(_siteId, Guid.NewGuid(), "Name 3"); using (var context = new WeapsyDbContext(_contextOptions)) { var repository = new PageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); repository.Create(newPage); } using (var context = new WeapsyDbContext(_contextOptions)) { var repository = new PageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); var page = repository.GetById(_siteId, newPage.Id); Assert.NotNull(page); } }
public void Should_update_page() { const string newPageName = "New Name 1"; var pageToUpdate = PageFactory.Page(_siteId, _pageId1, newPageName); using (var context = new WeapsyDbContext(_contextOptions)) { var repository = new PageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); repository.Update(pageToUpdate); } using (var context = new WeapsyDbContext(_contextOptions)) { var repository = new PageRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); var updatedPage = repository.GetById(_siteId, _pageId1); Assert.AreEqual(newPageName, updatedPage.Name); } }
/// <summary> /// Gets the user groups. /// </summary> /// <returns></returns> public IEnumerable <SelectListItem> GetFileTemplateSelectList(int?id = null) { var fileTemplates = GetAll(); int?templateId = null; var file = _pageRepository.GetById(id); if (file != null) { templateId = file.FileTemplateId; } var data = fileTemplates.Select(m => new HierarchyModel { Id = m.Id, Name = m.Name, Hierarchy = m.Hierarchy, RecordOrder = m.RecordOrder, Selected = templateId.HasValue && templateId.Value == m.Id }).ToList(); return(_fileTemplateRepository.BuildSelectList(data)); }
/// <summary> /// Save current page to audit /// </summary> /// <param name="model"></param> /// <returns></returns> public ResponseModel SavePageLog(PageLogManageModel model) { var page = _pageRepository.GetById(model.PageId); if (page != null) { /* * Map page log model to log entity * Get last updated version of page log * Create Change Log * If there are nothing change then do not do anything * Otherwise insert log */ Mapper.CreateMap <PageLogManageModel, PageLog>(); var log = Mapper.Map <PageLogManageModel, PageLog>(model); var pageLog = GetAll().Where(a => a.PageId == page.Id).OrderByDescending(a => a.Id).FirstOrDefault(); log.ChangeLog = pageLog != null ? ChangeLog(pageLog, model) : string.Format("** Create Page **"); if (string.IsNullOrEmpty(log.ChangeLog)) { return(new ResponseModel { Success = true }); } log.SessionId = HttpContext.Current.Session.SessionID; return(Insert(log)); } return(new ResponseModel { Success = false, Message = _localizedResourceServices.T("AdminModule:::Pages:::Messages:::ObjectNotFounded:::Page is not founded.") }); }
/// <summary> /// /// </summary> /// <param name="pageId"></param> /// <returns></returns> public ResponseModel SavePageToClientMenu(int pageId) { var page = _pageRepository.GetById(pageId); var clientMenu = FetchFirst(c => c.PageId == pageId); if (clientMenu != null) { clientMenu.Name = page.Title; clientMenu.PageId = page.Id; clientMenu.Url = page.FriendlyUrl; if (page.ParentId.HasValue && page.Page1.ClientMenus.Any()) { clientMenu.ParentId = page.Page1.ClientMenus.First().Id; } else { clientMenu.ParentId = null; } clientMenu.IncludeInSiteNavigation = page.IncludeInSiteNavigation; clientMenu.StartPublishingDate = page.StartPublishingDate; clientMenu.EndPublishingDate = page.EndPublishingDate; if (page.RecordOrder * 10 != clientMenu.RecordOrder) { var relativePages = _pageRepository.Fetch(p => (page.ParentId.HasValue ? p.ParentId == page.ParentId : !p.ParentId.HasValue) && p.Id != page.Id); foreach (var relativePage in relativePages) { var relativeMenu = relativePage.ClientMenus.First(); relativeMenu.RecordOrder = relativePage.RecordOrder * 10; Update(relativeMenu); } clientMenu.RecordOrder = page.RecordOrder * 10; } clientMenu.RecordActive = page.RecordActive; return(HierarchyUpdate(clientMenu)); } clientMenu = new ClientMenu(page); return(HierarchyInsert(clientMenu)); }
public ActionResult PostComment(DetailPageViewModel model, FormCollection collection) { try { int pageId = Convert.ToInt32(collection["IdPagina"]); if (ModelState.IsValid) { using (UnitOfWork uow = new UnitOfWork()) { PageRepository pr = new PageRepository(uow.Current); Page p = pr.GetById(pageId); Comment c = new Comment(model.Comment.UserName, model.Comment.UserMail, model.Comment.TextComment, p); p.AddComment(c); uow.Commit(); } } DetailPageViewModel m = new DetailPageViewModel(); using (UnitOfWork uow = new UnitOfWork()) { //Carica gli ultimi 5 POST PageRepository pr = new PageRepository(uow.Current); IList<Page> pages = pr.GetTopPost(5); if (pages != null && pages.Count > 0) { int k = 0; foreach (var p in pages) { PostViewModel pTemp = new PostViewModel(); pTemp.Id = p.Id; pTemp.Data = p.Date.Value; pTemp.Testo = p.BodyText; pTemp.Titolo = p.Title; pTemp.Autore = String.Format("{0} {1}", p.Author.Name, p.Author.Surname); pTemp.Categoria = p.Category.Name; pTemp.IdCategoria = p.Category.Id; pTemp.ImageName = p.ImageName; pTemp.Visualizzazioni = p.Views; pTemp.NumComments = p.Comments.Count; m.PostPreview.Add(pTemp); k++; } } else { PostViewModel pTemp = new PostViewModel(); pTemp.Id = 0; pTemp.Data = DateTime.Today; pTemp.Titolo = "OOPS..."; pTemp.Testo = "Sembra non siano presenti articoli..."; pTemp.Autore = "Pasquale Garzillo"; m.PostPreview.Add(pTemp); } if (pageId != 0) { Page p = pr.GetById(pageId); PostViewModel pTemp = new PostViewModel(); pTemp.Id = p.Id; pTemp.Data = p.Date.Value; pTemp.Testo = p.BodyText; pTemp.Titolo = p.Title; pTemp.Autore = String.Format("{0} {1}", p.Author.Name, p.Author.Surname); pTemp.Categoria = p.Category.Name; pTemp.IdCategoria = p.Category.Id; pTemp.ImageName = p.ImageName; pTemp.Tags = p.Tags != null && p.Tags.Count > 0 ? p.Tags.Select(x => x.Name).ToList() : null; pTemp.Visualizzazioni = p.Views; pTemp.NumComments = p.Comments.Count; if (pTemp.Tags != null && pTemp.Tags.Count > 0) { var tags = new TagCloudAnalyzer() .ComputeTagCloud(pTemp.Tags); pTemp.TagCloud = tags; } if (p.Comments != null && p.Comments.Count > 0) { pTemp.Comments = (from c in p.Comments select new CommentViewModel() { UserMail = c.UserMail, TextComment = c.TextComment, UserName = c.UserName }).ToList<CommentViewModel>(); } m.DetailedPost = pTemp; } //Carica le ultime 5 categoria con maggiori post CategoryRepository cr = new CategoryRepository(uow.Current); IList<Category> tempCats = cr.GetTopCategoryByPostCount(3); if (tempCats != null && tempCats.Count > 0) { foreach (var c in tempCats) { CategoryViewModel cvTemp = new CategoryViewModel(); cvTemp.Id = c.Id; cvTemp.Nome = c.Name; cvTemp.Descrizione = c.Description; cvTemp.FileName = c.ImageName; m.CategoriesPreview.Add(cvTemp); } } else { CategoryViewModel cvTemp = new CategoryViewModel(); cvTemp.Id = 0; cvTemp.Nome = "OOPS..."; cvTemp.Descrizione = "Sembra non siano presenti categorie..."; m.CategoriesPreview.Add(cvTemp); } } return View(m); } catch (Exception ex) { return Error(ex); } }
public ActionResult PageRemoveImage(int id) { try { using (UnitOfWork uow = new UnitOfWork()) { PageRepository pr = new PageRepository(uow.Current); Page p = pr.GetById(id); if (p != null) { p.SetImagePath(null); pr.SaveOrUpdate(p); uow.Commit(); return RedirectToAction("PageDetail", new { id = p.Id }); } else { return Error("Si è verificato un errore durante la rimozione dell'immagine"); } } } catch (Exception ex) { return Error(ex); } }
public ActionResult PageDetail(PageViewModel model) { try { //Carica tutti gli elementi necessari a video using (UnitOfWork uow = new UnitOfWork()) { AuthorRepository ar = new AuthorRepository(uow.Current); BlogRepository br = new BlogRepository(uow.Current); CategoryRepository cr = new CategoryRepository(uow.Current); //Ricarica la lista autori IList<Author> tmpAuthors = ar.FindAll().ToList(); if (tmpAuthors != null && tmpAuthors.Count > 0) { IEnumerable<SelectListItem> tmpAuthorsItems; tmpAuthorsItems = from s in tmpAuthors select new SelectListItem { Text = s.NameAndSurname, Value = s.Id.ToString() }; model.Authors = tmpAuthorsItems; } IList<Blog.Model.Domain.Entities.Blog> tmpBlogs = br.FindAll().ToList(); if (tmpBlogs != null && tmpBlogs.Count > 0) { IEnumerable<SelectListItem> tmpBlogsItems; tmpBlogsItems = from b in tmpBlogs select new SelectListItem { Text = b.Name, Value = b.Id.ToString() }; model.Blogs = tmpBlogsItems; } IList<Category> tmpCategories = cr.FindAll().ToList(); if (tmpCategories != null && tmpCategories.Count > 0) { IEnumerable<SelectListItem> tmpCategoriesItems; tmpCategoriesItems = from b in tmpCategories select new SelectListItem { Text = b.Name, Value = b.Id.ToString() }; model.Categories = tmpCategoriesItems; } } if (ModelState.IsValid) { using (UnitOfWork uow = new UnitOfWork()) { string fileName = null; if (model.File != null && model.File.ContentLength > 0) { //SALVA IL FILE fileName = Path.GetFileName(model.File.FileName); var path = Path.Combine(Server.MapPath("/Uploads"), fileName); model.File.SaveAs(path); model.FileName = fileName; } model.SelectedAuthor = model.SelectedAuthor; model.SelectedBlog = model.SelectedBlog; model.SelectedCategory = model.SelectedCategory; PageRepository pr = new PageRepository(uow.Current); AuthorRepository ar = new AuthorRepository(uow.Current); BlogRepository br = new BlogRepository(uow.Current); CategoryRepository cr = new CategoryRepository(uow.Current); TagRepository tr = new TagRepository(uow.Current); Page p = pr.GetById(model.Id); if (p != null) { Author au = ar.GetById(Convert.ToInt32(model.SelectedAuthor)); Blog.Model.Domain.Entities.Blog bb = br.GetById(Convert.ToInt32(model.SelectedBlog)); Category cc = cr.GetById(Convert.ToInt32(model.SelectedCategory)); p.Modifypage(model.Titolo, model.Descrizione, model.Data, model.Body, au, bb, cc); if (!String.IsNullOrEmpty(fileName)) p.SetImagePath(fileName); else model.FileName = p.ImageName; if (!String.IsNullOrEmpty(model.Tags)) { foreach (var t in model.Tags.Split(',')) { if (!String.IsNullOrEmpty(t)) { Tag tg = tr.GetTagByName(t.TrimStart().TrimEnd()); if (tg != null) { p.AddTag(tg); } else { Tag tempTag = new Tag(t.TrimStart().TrimEnd()); p.AddTag(tempTag); } } } } pr.SaveOrUpdate(p); uow.Commit(); model.Message = "Modifica eseguita con successo!"; } else model.Message = "Si è verificato un errore durante l'aggiornamento dei dati!"; } } return View(model); } catch (Exception ex) { return Error(ex); } }
public ActionResult PageDetail(int id) { try { PageViewModel pvm = new PageViewModel(); using (UnitOfWork uow = new UnitOfWork()) { PageRepository pr = new PageRepository(uow.Current); AuthorRepository ar = new AuthorRepository(uow.Current); BlogRepository br = new BlogRepository(uow.Current); CategoryRepository cr = new CategoryRepository(uow.Current); Page p = pr.GetById(id); if (p != null) { IList<Author> tmpAuthors = ar.FindAll().ToList(); if (tmpAuthors != null && tmpAuthors.Count > 0) { IEnumerable<SelectListItem> tmpAuthorsItems; tmpAuthorsItems = from s in tmpAuthors select new SelectListItem { Text = s.NameAndSurname, Value = s.Id.ToString() }; pvm.Authors = tmpAuthorsItems; pvm.SelectedAuthor = p.Author.Id.ToString(); } IList<Blog.Model.Domain.Entities.Blog> tmpBlogs = br.FindAll().ToList(); if (tmpBlogs != null && tmpBlogs.Count > 0) { IEnumerable<SelectListItem> tmpBlogsItems; tmpBlogsItems = from b in tmpBlogs select new SelectListItem { Text = b.Name, Value = b.Id.ToString() }; pvm.Blogs = tmpBlogsItems; pvm.SelectedBlog = p.Blog.Id.ToString(); } IList<Category> tmpCategories = cr.FindAll().ToList(); if (tmpCategories != null && tmpCategories.Count > 0) { IEnumerable<SelectListItem> tmpCategoriesItems; tmpCategoriesItems = from b in tmpCategories select new SelectListItem { Text = b.Name, Value = b.Id.ToString() }; pvm.Categories = tmpCategoriesItems; pvm.SelectedCategory = p.Category.Id.ToString(); } pvm.Data = p.Date.Value; pvm.Id = p.Id; pvm.Titolo = p.Title; pvm.Descrizione = p.Description; pvm.FileName = p.ImageName; pvm.Body = p.BodyText; if (p.Tags != null && p.Tags.Count > 0) pvm.Tags = String.Join(", ", p.Tags.Select(x=>x.Name)); } } return View(pvm); } catch (Exception ex) { return Error(ex); } }
public Page GetById(object id) { return(_pageRepository.GetById(id)); }
public ActionResult GetById(int Id) { return(Ok(_mapper.Map <PageViewModel>(_pageRepository.GetById(Id)))); }