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