public void Create5NewPageSuccessfulTest() { using (UnitOfWork uow = new UnitOfWork()) { PageRepository pr = new PageRepository(uow.Current); BlogRepository br = new BlogRepository(uow.Current); Blog.Model.Domain.Entities.Blog b = new Blog.Model.Domain.Entities.Blog("Nombe blog", "Desc blog"); Category c = new Category("Categoria 1", "Desc 1"); Author a = new Author("Nome autore", "Cognome autore", Convert.ToDateTime("27/12/1987"), "*****@*****.**", true, "pass", b); Page p1 = new Page("Nome pagina 1", "descr pagine", DateTime.Now, "test", a, b, c); Page p2 = new Page("Nome pagina 2", "descr pagine", DateTime.Now, "test", a, b, c); Page p3 = new Page("Nome pagina 3", "descr pagine", DateTime.Now, "test", a, b, c); Page p4 = new Page("Nome pagina 4", "descr pagine", DateTime.Now, "test", a, b, c); Page p5 = new Page("Nome pagina 5", "descr pagine", DateTime.Now, "test", a, b, c); br.Save(b); pr.Save(p1); pr.Save(p2); pr.Save(p3); pr.Save(p4); pr.Save(p5); uow.Commit(); } }
public ActionResult Index() { try { using (UnitOfWork uow = new UnitOfWork()) { BlogRepository br = new BlogRepository(uow.Current); try { if (br.FindAll().Count > 0) { //Vai alla pagina di gestione return RedirectToAction("Index", "Manage"); } else return View(); } catch (Exception ex) { //Il database non esiste, lo inizializzo SessionManager.Instance.BuildSchema(); return View(); } } } catch (Exception ex) { return Error(ex); } }
public ActionResult Login(UserLoginViewModel model) { try { if (ModelState.IsValid) { using (UnitOfWork uow = new UnitOfWork()) { AuthorRepository ar = new AuthorRepository(uow.Current); Author au = ar.GetAuthorByEmail(model.Email); if (au != null && au.ValidatePassword(model.Password) && au.IsAdministrator) { //Login OK if (FormsAuthentication.IsEnabled && FormsAuthentication.CookiesSupported) FormsAuthentication.SetAuthCookie(model.Email, true); return RedirectToAction("Index", "Manage"); } else { model.Message = "Email e/o password errate, oppure non hai i diritti per accedere!"; return View(model); } } } else return View(model); } catch (Exception ex) { return Error(ex); } }
public void CreateNewTagSuccessfulTest() { using (UnitOfWork uow = new UnitOfWork()) { TagRepository tr = new TagRepository(uow.Current); Tag c = new Tag("sql server"); tr.Save(c); uow.Commit(); } }
public void CreateNewCategorySuccessfulTest() { using (UnitOfWork uow = new UnitOfWork()) { CategoryRepository cr = new CategoryRepository(uow.Current); Category c = new Category("Nome categoria di test", "descrizione di test"); cr.Save(c); uow.Commit(); } }
public void CreateNewAuthorSuccessfulTest() { using (UnitOfWork uow = new UnitOfWork()) { AuthorRepository ar = new AuthorRepository(uow.Current); BlogRepository br = new BlogRepository(uow.Current); br.Save(b); Author a = new Author("Pasquale", "Garzillo", Convert.ToDateTime("27/12/1987"), "*****@*****.**", true, "rofox2011", b); ar.Save(a); uow.Commit(); } }
public void CreateSuccessfulBlogTest() { using (UnitOfWork uow = new UnitOfWork()) { BlogRepository br = new BlogRepository(uow.Current); //Creo il blog Devevil.Blog.Model.Domain.Entities.Blog b = new Devevil.Blog.Model.Domain.Entities.Blog(".Net Help", "Un blog dedicato allo sviluppo"); //creo una categoria generica Category c = new Category("Nessuna categoria", "Categoria generica"); //Creo un paio di TAG Tag t1 = new Tag("C#"); Tag t2 = new Tag(".NET"); //Creo un autore, afferente al blog "b" Author a = new Author("Pasquale", "Garzillo", Convert.ToDateTime("27/12/1987"), "*****@*****.**",true,"rofox2011",b); //Creo una pagina afferente al blog "b", che ha per autore "a" ed appartiene alla categoria "c" Page p = new Page("Prima pagina del blog", "Descrizione della prima pagina", DateTime.Today, "testo pagina", a, b, c); //Creo un commento per la pagina "p" Comment co = new Comment("Raowyr", "*****@*****.**", "Testo commento", p); //Aggiunto i tag "t1" e "t2" alla pagina p.AddTag(t1); p.AddTag(t2); //Aggiungo il commento "co" alla pagina p.AddComment(co); //Aggiungo la pagina "p" al blog "b" b.AddPageToBlog(p); //Aggiungo l'autore "a" al blog "b" b.AddAuthorToBlog(a); //La categoria "c" è categoria della pagina "p" c.AddCategoryToPage(p); //L'autore "a" è autore della pagina "p" a.AddAuthoringPage(p); //Tag "t1" e "t2" sono tag delle pagina "p" t1.AddTagToPage(p); t2.AddTagToPage(p); br.Save(b); uow.Commit(); Devevil.Blog.Model.Domain.Entities.Blog bb = br.GetById(b.Id); Assert.IsNotNull(bb); } }
public ActionResult Index(SetupViewModel model) { try { if (ModelState.IsValid) { Model.Domain.Entities.Blog b = new Model.Domain.Entities.Blog(model.Blog, model.Descrizione); Author au = new Author(model.Nome, model.Cognome, model.Nascita, model.Email, true, model.Password, b); Category cc = new Category("Nessuna categoria", "Categoria generica"); using (UnitOfWork uow = new UnitOfWork()) { BlogRepository br = new BlogRepository(uow.Current); AuthorRepository ar = new AuthorRepository(uow.Current); CategoryRepository cr = new CategoryRepository(uow.Current); br.Save(b); ar.Save(au); cr.Save(cc); uow.Commit(); } //Vai alla pagina di gestione return RedirectToAction("Index", "Manage"); } else return View(model); } catch (Exception ex) { return Error(ex); } }
public ActionResult AccountManagment(UserViewModel model) { try { if (ModelState.IsValid) { if (FormsAuthentication.IsEnabled && FormsAuthentication.CookiesSupported) { string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name; if (!String.IsNullOrEmpty(username)) { using (UnitOfWork uow = new UnitOfWork()) { AuthorRepository ar = new AuthorRepository(uow.Current); Author au = ar.GetAuthorByEmail(username); au.ModifyAuthor(model.Nome, model.Cognome, model.Nascita, model.Email); ar.SaveOrUpdate(au); uow.Commit(); model.Message = "Modifica dei dati eseguita con successo!"; } } else model.Message = "Si è verificato un problema durante il recupero dei dati. Non è stato possibile apportare le modifiche richieste!"; } return View(model); } else return View(model); } catch (Exception ex) { return Error(ex); } }
public ActionResult Categories() { try { IList<CategoryViewModel> categoryList = null; using (UnitOfWork uow = new UnitOfWork()) { CategoryRepository cr = new CategoryRepository(uow.Current); IList<Category> tmpList = cr.FindAll().ToList(); if (tmpList != null) { categoryList = new List<CategoryViewModel>(); foreach (var c in tmpList) { CategoryViewModel cvm = new CategoryViewModel(); cvm.Descrizione = c.Description; cvm.Nome = c.Name; cvm.Id = c.Id; categoryList.Add(cvm); } } } return View(categoryList); } catch (Exception ex) { return Error(ex); } }
public ActionResult CategoryDetail(int id) { try { CategoryViewModel cvm = new CategoryViewModel(); using (UnitOfWork uow = new UnitOfWork()) { CategoryRepository cr = new CategoryRepository(uow.Current); Category c = cr.GetById(id); if (c != null) { cvm.Nome = c.Name; cvm.Descrizione = c.Description; cvm.Id = c.Id; cvm.FileName = c.ImageName; } } return View(cvm); } 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 PageNew() { try { PageViewModel pvm = new PageViewModel(); 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() }; pvm.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() }; pvm.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() }; pvm.Categories = tmpCategoriesItems; } pvm.Data = DateTime.Today.Date; } return View(pvm); } catch (Exception ex) { return Error(ex); } }
public ActionResult AccountManagment() { try { UserViewModel uvm = new UserViewModel(); if (FormsAuthentication.IsEnabled && FormsAuthentication.CookiesSupported && Request.Cookies[FormsAuthentication.FormsCookieName] != null) { string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name; if (!String.IsNullOrEmpty(username)) { using (UnitOfWork uow = new UnitOfWork()) { AuthorRepository ar = new AuthorRepository(uow.Current); Author au = ar.GetAuthorByEmail(username); if (au != null) { uvm.Cognome = au.Surname; uvm.Email = au.Email; uvm.Nascita = au.BirthDate.Value; uvm.Nome = au.Name; uvm.Password = au.Password; } else uvm.Message = "Si è verificato un problema durante il caricamento dati."; } } else uvm.Message = "Si è verificato un problema durante il caricamento dati."; return View(uvm); } else { uvm.Message = "Sessione utente probabilmente scaduta! Riprova a fare il login e assicurati di avere i cookie abilitati!"; return View(uvm); } } catch (Exception ex) { return Error(ex); } }
public ActionResult Tags() { try { IList<TagViewModel> tagList = null; using (UnitOfWork uow = new UnitOfWork()) { TagRepository tr = new TagRepository(uow.Current); IList<Tag> tmpList = tr.FindAll().ToList(); if (tmpList != null) { tagList = new List<TagViewModel>(); foreach (var c in tmpList) { TagViewModel cvm = new TagViewModel(); cvm.Nome = c.Name; cvm.Id = c.Id; tagList.Add(cvm); } } } return View(tagList); } catch (Exception ex) { return Error(ex); } }
public ActionResult LookupTags(string term) { try { IList<string> retValue = null; using (UnitOfWork uow = new UnitOfWork()) { TagRepository tr = new TagRepository(uow.Current); retValue = tr.FindAll().Where(x => x.Name.StartsWith(term)) .OrderBy(x => x) //.Take(limit) .Select(r => r.Name).ToList(); } // Return the result set as JSON return Json(retValue, JsonRequestBehavior.AllowGet); } catch (Exception ex) { return Error(ex); } }
public ActionResult Find(string query) { try { ListPageViewModel m = new ListPageViewModel(); 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); } //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); } pages = pr.GetPostByQueryFind(query); if (pages != null && pages.Count > 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.Posts.Add(pTemp); } } } return View(m); } catch (Exception ex) { return Error(ex); } }
public ActionResult CategoryDetail(CategoryViewModel model) { try { 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; } CategoryRepository cr = new CategoryRepository(uow.Current); Category c = cr.GetById(model.Id); if (c != null) { c.ModifyCategory(model.Nome, model.Descrizione); if (!String.IsNullOrEmpty(fileName)) c.SetImagePath(fileName); else model.FileName = c.ImageName; cr.SaveOrUpdate(c); uow.Commit(); model.Message = "Modifica eseguita con successo!"; } else model.Message = "Si è verificato un errore durante l'aggiornamento dei dati! Recupero dell'entità da modificare non avvenuto!"; } } return View(model); } catch (Exception ex) { return Error(ex); } }
public ActionResult TagDetail(TagViewModel model) { try { if (ModelState.IsValid) { using (UnitOfWork uow = new UnitOfWork()) { TagRepository tr = new TagRepository(uow.Current); Tag t = tr.GetById(model.Id); if (t != null) { t.ModifyName(model.Nome); tr.SaveOrUpdate(t); uow.Commit(); model.Message = "Modifica eseguita con successo!"; } else model.Message = "Si è verificato un errore durante l'aggiornamento dei dati! Recupero entità da modifica non avvenuto con successo!"; } } return View(model); } catch (Exception ex) { return Error(ex); } }
public ActionResult TagDetail(int id) { try { TagViewModel cvm = new TagViewModel(); using (UnitOfWork uow = new UnitOfWork()) { TagRepository tr = new TagRepository(uow.Current); Tag t = tr.GetById(id); if (t != null) { cvm.Nome = t.Name; cvm.Id = t.Id; } } return View(cvm); } catch (Exception ex) { return Error(ex); } }
public ActionResult CategoryNew(CategoryViewModel model) { try { 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; } CategoryRepository cr = new CategoryRepository(uow.Current); Category c = new Category(model.Nome, model.Descrizione); c.SetImagePath(fileName); cr.SaveOrUpdate(c); uow.Commit(); model.Message = "Salvataggio eseguito correttamente!"; } } return View(model); } catch (Exception ex) { return Error(ex); } }
public ActionResult PageNew(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); 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)); Page p = new Page(model.Titolo, model.Descrizione, model.Data, model.Body, au, bb, cc); 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); } } } } if (!String.IsNullOrEmpty(fileName)) p.SetImagePath(fileName); else model.FileName = p.ImageName; pr.SaveOrUpdate(p); uow.Commit(); model.Message = "Salvataggio eseguito con successo!"; } } return View(model); } catch (Exception ex) { return Error(ex); } }
public ActionResult TagNew(TagViewModel model) { try { if (ModelState.IsValid) { using (UnitOfWork uow = new UnitOfWork()) { TagRepository tr = new TagRepository(uow.Current); Tag t = new Tag(model.Nome); tr.SaveOrUpdate(t); uow.Commit(); model.Message = "Salvataggio eseguito correttamente!"; } } return View(model); } catch (Exception ex) { return Error(ex); } }
public ActionResult CategoryRemoveImage(int id) { try { CategoryViewModel cvm = new CategoryViewModel(); using (UnitOfWork uow = new UnitOfWork()) { CategoryRepository cr = new CategoryRepository(uow.Current); Category c = cr.GetById(id); if (c != null) { c.SetImagePath(null); cr.SaveOrUpdate(c); uow.Commit(); return RedirectToAction("CategoryDetail", new { id = c.Id }); } else { return Error("Si è verificato un errore durante la rimozione dell'immagine"); } } } catch (Exception ex) { return Error(ex); } }
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 Pages() { try { IList<PageViewModel> postList = null; using (UnitOfWork uow = new UnitOfWork()) { PageRepository pr = new PageRepository(uow.Current); IList<Page> tmpList = pr.FindAll().ToList(); if (tmpList != null) { postList = new List<PageViewModel>(); foreach (var p in tmpList) { PageViewModel pvm = new PageViewModel(); pvm.Id = p.Id; pvm.Data = p.Date.Value; pvm.Titolo = p.Title; pvm.Autore = p.Author.NameAndSurname; pvm.Categoria = p.Category.Name; postList.Add(pvm); } } } return View(postList); } 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 ActionResult Index() { try { HomePageViewModel m = new HomePageViewModel(); using (UnitOfWork uow = new UnitOfWork()) { //Carica gli ultimi 10 POST PageRepository pr = new PageRepository(uow.Current); IList<Page> pages = pr.GetTopPost(10); 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.Visualizzazioni = p.Views; pTemp.NumComments = p.Comments.Count; if (k < 5) m.PostDetail.Add(pTemp); else 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.PostDetail.Add(pTemp); m.PostPreview.Add(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) { //Errore durante recupero dei dati //Errore gestibile, non è necessario reindirizzare alla pagine di errore //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.PostDetail.Add(pTemp); //CategoryViewModel cvTemp = new CategoryViewModel(); //cvTemp.Id = 0; //cvTemp.Nome = "OOPS..."; //cvTemp.Descrizione = "Sembra non siano presenti categorie..."; //m.CategoriesPreview.Add(cvTemp); return Error(ex); } }