Example #1
0
        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);
            }
        }
Example #2
0
        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);
            }
        }
Example #3
0
        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);
            }
        }
Example #4
0
        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);
            }
        }
Example #5
0
        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);
            }
        }
Example #6
0
 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);
     }
 }
Example #7
0
        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);
            }
        }
Example #8
0
        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);
            }
        }