Ejemplo n.º 1
0
        public ActionResult CreatePoll(string question)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();

            if (!String.IsNullOrEmpty(question))
            {
                try
                {
                    Poll poll = new Poll
                    {
                        QuestionText = question,
                        Path = question.ToUrlFormat(),
                        AddedBy = User.Identity.Name,
                        AddedDate = DateTime.Now
                    };

                    dc.Polls.InsertOnSubmit(poll);
                    dc.SubmitChanges();

                    TempData["SuccessMessage"] = "Your poll has been created.";
                    return RedirectToAction("EditPoll", new { pollId = poll.PollID });
                }
                catch (Exception exc)
                {
                    TempData["ErrorMessage"] = exc.Message;
                }
            }

            ViewData["question"] = question;

            ViewData["PageTitle"] = "Create Poll";

            return View("CreatePoll");
        }
        public ActionResult CreateNewsletter(string subject, string body)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();

            if (!String.IsNullOrEmpty(subject) && !String.IsNullOrEmpty(body))
            {
                Newsletter newsletter = new Newsletter()
                {
                    AddedDate = DateTime.Now,
                    AddedBy = User.Identity.Name,
                    Status = "Queued",
                    Subject = subject,
                    HtmlBody = body,
                    PlainTextBody = body
                };

                dc.Newsletters.InsertOnSubmit(newsletter);
                dc.SubmitChanges();

                Thread thread = new Thread(new ParameterizedThreadStart(SendNewsletter));
                thread.Priority = ThreadPriority.BelowNormal;
                thread.Start(new object[] { newsletter, dc });

                return RedirectToAction("ManageNewsletters");
            }

            ViewData["PageTitle"] = "Create Newsletter";
            return View(new Newsletter());
        }
        public ActionResult EditNewsletter(int? newsletterId, string subject, string body)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var newsletter = dc.Newsletters.FirstOrDefault(n => n.NewsletterID == newsletterId);

            if (newsletter == null)
                throw new HttpException(404, "The newsletter could not be found.");

            if (!String.IsNullOrEmpty(subject) && !String.IsNullOrEmpty(body))
            {
                newsletter.Subject = subject;
                newsletter.HtmlBody = body;
                newsletter.PlainTextBody = body;

                dc.SubmitChanges();

                Thread thread = new Thread(new ParameterizedThreadStart(SendNewsletter));
                thread.Priority = ThreadPriority.BelowNormal;
                thread.Start(new object[] { newsletter, dc });

                return RedirectToAction("ManageNewsletters", "Newsletter");
            }

            ViewData["PageTitle"] = "Edit Newsletter";
            return View("CreateNewsletter", newsletter);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Categories the index.
        /// </summary>
        /// <returns></returns>
        public ActionResult CategoryIndex()
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var viewData = dc.Categories.GetCategories();

            ViewData["PageTitle"] = "All Categories";

            return View(viewData);
        }
Ejemplo n.º 5
0
        public ActionResult AddOption(int pollId, string text)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var poll = dc.Polls.GetPoll(pollId);

            if (poll == null)
                throw new HttpException(404, "The poll could not be found.");

            var option = new PollOption
            {
                AddedBy = User.Identity.Name,
                AddedDate = DateTime.Now,
                OptionText = text,
                Votes = 0
            };
            poll.PollOptions.Add(option);
            dc.SubmitChanges();

            return View(new { optionId = option.OptionID, text = text });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Rates the article.
        /// </summary>
        /// <param name="articleId">The article id.</param>
        /// <param name="rating">The rating.</param>
        /// <returns></returns>
        //[ServiceOnly, HttpPostOnly]
        public ActionResult RateArticle(int articleId, int rating)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            Article viewData = dc.Articles.GetArticle(articleId);

            try
            {
                viewData.Rate(rating);
                dc.SubmitChanges();
            }
            catch { /* ignore all conflicts because this action isn't critical */ }

            return View(new { articleId = articleId, averageRating = viewData.AverageRating });
        }
Ejemplo n.º 7
0
        public ActionResult ManageComments(int page)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var viewData = dc.Comments.GetCommentsForModeration(page);

            ViewData["PageTitle"] = "Manage Comments";

            return View(viewData);
        }
Ejemplo n.º 8
0
        public ActionResult ManageArticles(int page)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var viewData = dc.Articles.GetArticles(null, page);

            ViewData["PageTitle"] = "Manage Articles";

            return View(viewData);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Indexes the specified category.
        /// </summary>
        /// <param name="category">The category.</param>
        /// <param name="page">The page.</param>
        /// <returns></returns>
        public ActionResult Index(string category, int page)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var viewData = dc.Articles.GetPublishedArticles(category, page);
            var viewCategory = dc.Categories.GetCategory(category);

            ViewData["Categories"] = dc.Categories.GetCategories();
            ViewData["PageTitle"] = (viewCategory != null ? viewCategory.Title : "All") + " Articles";

            return View(viewData);
        }
Ejemplo n.º 10
0
        public ActionResult Vote(int optionId)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var option = dc.PollOptions.GetPollOption(optionId);

            if (option == null)
                throw new HttpException(404, "The poll option could not be found.");

            var poll = option.Poll;
            var options = new List<object>();

            if (poll.IsArchived || Request.Cookies["poll_" + poll.PollID] == null)
            {
                option.Votes++;
                dc.SubmitChanges();
            }

            foreach (var o in poll.PollOptions)
                options.Add(new
                {
                    optionId = o.OptionID,
                    text = o.OptionText,
                    votes = o.Votes
                });

            return View(new
            {
                pollId = poll.PollID,
                total = poll.PollOptions.Sum(o => o.Votes),
                question = poll.QuestionText,
                options = options
            });
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Views the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public ActionResult ViewArticle(int id, string path)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            Article viewData = dc.Articles.GetArticle(id);

            // throw a 404 Not Found if the requested article is not in the database
            if (viewData == null)
                throw new HttpException(404, "The article could not be found.");

            // SEO: redirect to the correct location if the path is not
            if (!String.Equals(path, viewData.Path, StringComparison.OrdinalIgnoreCase))
                return this.RedirectToAction(301, "View", new { id = viewData.ArticleID, path = viewData.Path });

            // make sure the article is only viewed by members with permissions
            if (viewData.OnlyForMembers
                && HttpContext.User != null
                && HttpContext.User.Identity != null
                && !HttpContext.User.Identity.IsAuthenticated)
                throw new HttpException(401, "The articles is only viewable for members.");

            // update the view count
            try
            {
                viewData.ViewCount++;
                dc.SubmitChanges();
            }
            catch { /* ignore all conflicts because this action isn't critical */ }

            ViewData["PageTitle"] = viewData.Title;

            return View(viewData);
        }
Ejemplo n.º 12
0
        public ActionResult CreateArticle(int? categoryId, string title, string summary, string body, string country, string state, string city, DateTime? releaseDate, DateTime? expireDate, bool? approved, bool? listed, bool? commentsEnabled, bool? onlyForMembers)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var categories = dc.Categories.GetCategories();

            if (categoryId.HasValue
                && !String.IsNullOrEmpty(title)
                && !String.IsNullOrEmpty(body))
            {
                try
                {
                    Article article = new Article
                    {
                        CategoryID = categoryId.Value,
                        Title = title,
                        Path = title.ToUrlFormat(),
                        Abstract = summary,
                        Body = body,
                        Country = country,
                        State = state,
                        City = city,
                        ReleaseDate = releaseDate ?? DateTime.Today,
                        ExpireDate = expireDate,
                        Approved = approved ?? false,
                        Listed = listed ?? false,
                        CommentsEnabled = commentsEnabled ?? false,
                        OnlyForMembers = onlyForMembers ?? false,
                        AddedBy = User.Identity.Name,
                        AddedDate = DateTime.Now
                    };

                    dc.Articles.InsertOnSubmit(article);
                    dc.SubmitChanges();

                    TempData["SuccessMessage"] = "Your article has been posted.";
                    return RedirectToAction("ViewArticle", new { id = article.ArticleID, path = article.Path });
                }
                catch (Exception exc)
                {
                    TempData["ErrorMessage"] = exc.Message;
                }
            }

            ViewData["categoryId"] = new SelectList(categories, "CategoryID", "Title", categoryId);
            ViewData["title"] = title;
            ViewData["summary"] = summary;
            ViewData["body"] = body;
            ViewData["country"] = new SelectList(Iso3166CountryCodes.CountryDictonary, "Key", "Value", country ?? "US");
            ViewData["state"] = state;
            ViewData["city"] = city;
            ViewData["releaseDate"] = releaseDate;
            ViewData["expireDate"] = expireDate;
            ViewData["approved"] = approved;
            ViewData["listed"] = listed;
            ViewData["commentsEnabled"] = commentsEnabled;
            ViewData["onlyForMembers"] = onlyForMembers;

            ViewData["PageTitle"] = "Create Article";

            return View("CreateArticle");
        }
Ejemplo n.º 13
0
        public ActionResult EditArticle(int articleId, int? categoryId, string title, string summary, string body, string country, string state, string city, DateTime? releaseDate, DateTime? expireDate, bool? approved, bool? listed, bool? commentsEnabled, bool? onlyForMembers)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var categories = dc.Categories.GetCategories();

            if (IsPostBack)
            {
                approved = approved ?? false;
                listed = listed ?? false;
                commentsEnabled = commentsEnabled ?? false;
                onlyForMembers = onlyForMembers ?? false;
            }

            Article article = dc.Articles.GetArticle(articleId);

            // throw a 404 Not Found if the requested article is not in the database
            if (article == null)
                throw new HttpException(404, "The article could not be found.");

            if (categoryId.HasValue
                && !String.IsNullOrEmpty(title)
                && !String.IsNullOrEmpty(body))
            {
                try
                {
                    article.CategoryID = categoryId.Value;
                    article.Title = title;
                    article.Abstract = summary;
                    article.Body = body;
                    article.Country = country;
                    article.State = state;
                    article.City = city;
                    article.ReleaseDate = releaseDate ?? article.ReleaseDate;
                    article.ExpireDate = expireDate;
                    article.Approved = approved ?? false;
                    article.Listed = listed ?? false;
                    article.CommentsEnabled = commentsEnabled ?? false;
                    article.OnlyForMembers = onlyForMembers ?? false;

                    dc.SubmitChanges();

                    TempData["SuccessMessage"] = "Your article has been updated.";
                }
                catch (Exception exc)
                {
                    TempData["ErrorMessage"] = exc.Message;
                }
            }

            ViewData["categoryId"] = new SelectList(categories, "CategoryID", "Title", categoryId ?? article.CategoryID);
            ViewData["title"] = title ?? article.Title;
            ViewData["summary"] = summary ?? article.Abstract;
            ViewData["body"] = body ?? article.Body;
            ViewData["country"] = new SelectList(Iso3166CountryCodes.CountryDictonary, "Key", "Value", country ?? article.Country ?? "US");
            ViewData["state"] = state ?? article.State;
            ViewData["city"] = city ?? article.City;
            ViewData["releaseDate"] = releaseDate ?? article.ReleaseDate;
            ViewData["expireDate"] = expireDate ?? article.ExpireDate;
            ViewData["approved"] = approved ?? article.Approved;
            ViewData["listed"] = listed ?? article.Listed;
            ViewData["commentsEnabled"] = commentsEnabled ?? article.CommentsEnabled;
            ViewData["onlyForMembers"] = onlyForMembers ?? article.OnlyForMembers;

            ViewData["PageTitle"] = "Edit Article";

            return View("CreateArticle");
        }
Ejemplo n.º 14
0
        public ActionResult CreateComment(int articleId, string name, string email, string body)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            Article article = dc.Articles.GetArticle(articleId);

            // throw a 404 Not Found if the requested article is not in the database
            if (article == null)
                throw new HttpException(404, "The article could not be found.");

            Comment comment = new Comment
            {
                AddedBy = name,
                AddedByEmail = email,
                AddedByIP = Request.UserHostAddress,
                AddedDate = DateTime.Now,
                Body = body
            };
            article.Comments.Add(comment);

            // save changes to database
            dc.SubmitChanges();

            return View(new
            {
                commentId = comment.CommentID,
                name = comment.AddedBy,
                body = comment.Body
            });
        }
Ejemplo n.º 15
0
        public ActionResult CreateCategory(string title, int? importance, string imageUrl, string description)
        {
            if (!String.IsNullOrEmpty(title)
                && !String.IsNullOrEmpty(imageUrl)
                && !String.IsNullOrEmpty(description))
            {
                try
                {
                    TheBeerHouseDataContext dc = new TheBeerHouseDataContext();

                    Category category = new Category
                    {
                        Title = title,
                        Importance = importance ?? -1,
                        ImageUrl = imageUrl,
                        Description = description,
                        AddedBy = User.Identity.Name,
                        AddedDate = DateTime.Now,
                        Path = title.ToUrlFormat()
                    };
                    dc.Categories.InsertOnSubmit(category);

                    // save changes to database
                    dc.SubmitChanges();

                    TempData["SuccessMessage"] = "Your category has been created.";
                    return RedirectToAction("ManageArticles");
                }
                catch (Exception exc)
                {
                    TempData["ErrorMessage"] = exc.Message;
                }
            }

            ViewData["categorytitle"] = title;
            ViewData["importance"] = importance;
            ViewData["imageUrl"] = imageUrl;
            ViewData["description"] = description;

            ViewBag.Title = "Create Category";

            return View("CreateCategory");
        }
Ejemplo n.º 16
0
 public static SelectList GetLanguageList(String language)
 {
     TheBeerHouseDataContext dataContext = new TheBeerHouseDataContext();
     var Languages = from languageList in dataContext.Languages
                     orderby languageList.LanguageName
                     select languageList;
     return new SelectList(Languages, "LanguageName", "LanguageName", language ?? "English");
 }
Ejemplo n.º 17
0
 public static SelectList GetOccupationList(String occupation)
 {
     TheBeerHouseDataContext dataContext = new TheBeerHouseDataContext();
     var Occupations = from occupationList in dataContext.Occupations
                       orderby occupationList.OccupationName
                       select occupationList;
     return new SelectList(Occupations, "OccupationName", "OccupationName", occupation ?? "Business Owner");
 }
Ejemplo n.º 18
0
        public ActionResult EditOption(int optionId, string text)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var option = dc.PollOptions.GetPollOption(optionId);

            if (option == null)
                throw new HttpException(404, "The poll option could not be found.");

            option.OptionText = text;
            dc.SubmitChanges();

            return View(new { optionId = option.OptionID, text = text });
        }
Ejemplo n.º 19
0
        public ActionResult RemoveArticle(int articleId, string remove)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            Article article = dc.Articles.GetArticle(articleId);

            // throw a 404 Not Found if the requested article is not in the database
            if (article == null)
                throw new HttpException(404, "The article could not be found.");

            if (String.Equals(remove, "yes", StringComparison.OrdinalIgnoreCase))
            {
                dc.Articles.DeleteOnSubmit(article);
                dc.SubmitChanges();

                TempData["SuccessMessage"] = "The article, " + article.Title + ", has been deleted.";

                article = null;
            }
            else if (String.Equals(remove, "no", StringComparison.OrdinalIgnoreCase))
            {
                TempData["InformationMessage"] = "The article, " + article.Title + ", has NOT been deleted.";
            }
            else
            {
                TempData["WarningMessage"] = "Are you sure you want to delete " + article.Title + ".  You will not be able to recover this article if you select YES.";
            }

            ViewData["PageTitle"] = "Remove Article";

            return View(article);
        }
Ejemplo n.º 20
0
        public ActionResult RemoveNewsletter(int? newsletterId)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var newsletter = dc.Newsletters.FirstOrDefault(n => n.NewsletterID == newsletterId);

            if (newsletter == null)
                throw new HttpException(404, "The newsletter could not be found.");

            dc.Newsletters.DeleteOnSubmit(newsletter);
            dc.SubmitChanges();

            return RedirectToAction("ManageNewsletters");
        }
Ejemplo n.º 21
0
        public ActionResult RemoveCategory(int categoryId, int? newCategoryId, string remove)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var categories = dc.Categories.GetCategories();
            Category category = dc.Categories.GetCategory(categoryId);
            bool newCategoryExists = categoryId != newCategoryId && dc.Categories.Exists(newCategoryId ?? -1);

            // throw a 404 Not Found if the requested category is not in the database
            if (category == null)
                throw new HttpException(404, "The category could not be found.");

            if (String.Equals(remove, "yes", StringComparison.OrdinalIgnoreCase) && newCategoryExists)
            {
                foreach (Article article in category.Articles)
                    article.CategoryID = newCategoryId.Value;

                dc.Categories.DeleteOnSubmit(category);
                dc.SubmitChanges();

                TempData["SuccessMessage"] = "The category, " + category.Title + ", has been deleted.";

                category = null;
            }
            else if (String.Equals(remove, "no", StringComparison.OrdinalIgnoreCase))
            {
                TempData["InformationMessage"] = "The category, " + category.Title + ", has NOT been deleted.";
            }
            else
            {
                ViewData["newCategoryId"] = new SelectList(categories, "CategoryID", "Title", newCategoryId);
                TempData["WarningMessage"] = "Are you sure you want to delete " + category.Title + ".  If you are sure please select a new category to move all the articles to and then select YES.";
            }

            ViewData["PageTitle"] = "Remove Category";

            return View(category);
        }
Ejemplo n.º 22
0
        public ActionResult SetArchived(int pollId, bool archive)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var poll = dc.Polls.GetPoll(pollId);

            if (poll == null)
                throw new HttpException(404, "The poll could not be found.");

            poll.IsArchived = archive;
            poll.ArchivedDate = archive ? DateTime.Now : (DateTime?)null;
            dc.SubmitChanges();

            return View(new { pollId = pollId, isArchived = poll.IsArchived });
        }
Ejemplo n.º 23
0
        public ActionResult RemoveComment(int commentId)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            Comment comment = dc.Comments.GetComment(commentId);

            // throw a 404 Not Found if the requested article is not in the database
            if (comment == null)
                throw new HttpException(404, "The comment could not be found.");

            dc.Comments.DeleteOnSubmit(comment);
            dc.SubmitChanges();

            return View(new { commentId = commentId });
        }
Ejemplo n.º 24
0
        public ActionResult RemovePoll(int pollId, string remove)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            Poll poll = dc.Polls.GetPoll(pollId);

            // throw a 404 Not Found if the requested poll is not in the database
            if (poll == null)
                throw new HttpException(404, "The poll could not be found.");

            if (String.Equals(remove, "yes", StringComparison.OrdinalIgnoreCase))
            {
                dc.Polls.DeleteOnSubmit(poll);
                dc.SubmitChanges();

                TempData["SuccessMessage"] = "The poll, " + poll.QuestionText + ", has been deleted.";

                poll = null;
            }
            else if (String.Equals(remove, "no", StringComparison.OrdinalIgnoreCase))
            {
                TempData["InformationMessage"] = "The poll, " + poll.QuestionText + ", has NOT been deleted.";
            }
            else
            {
                TempData["WarningMessage"] = "Are you sure you want to delete " + poll.QuestionText + ".  You will not be able to recover this poll if you select YES.";
            }

            ViewData["PageTitle"] = "Remove Poll";

            return View(poll);
        }
Ejemplo n.º 25
0
        public ActionResult ManageNewsletters()
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var viewData = dc.Newsletters.OrderByDescending(n => n.AddedDate);

            ViewData["PageTitle"] = "Manage Newsletters";
            return View(viewData);
        }
Ejemplo n.º 26
0
        public ActionResult SetCurrent(int pollId)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var poll = dc.Polls.GetPoll(pollId);

            if (poll == null)
                throw new HttpException(404, "The poll could not be found.");

            // reset all polls to not current
            dc.ExecuteCommand("update TheBeerHouse.Polls set IsCurrent = 0;", new object[0]);

            poll.IsCurrent = true;
            dc.SubmitChanges();

            return View(new { pollId = pollId });
        }
Ejemplo n.º 27
0
        public ActionResult UpdateStatus()
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var viewData = dc.Newsletters.OrderByDescending(n => n.AddedDate);

            return PartialView("Newsletter/NewsletterStatus", viewData);
        }
Ejemplo n.º 28
0
        public ActionResult EditCategory(int categoryId, string title, int? importance, string imageUrl, string description)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            Category category = dc.Categories.GetCategory(categoryId);

            // throw a 404 Not Found if the requested category is not in the database
            if (category == null)
                throw new HttpException(404, "The category could not be found.");

            if (!String.IsNullOrEmpty(title)
                && !String.IsNullOrEmpty(imageUrl)
                && !String.IsNullOrEmpty(description))
            {
                try
                {
                    category.Title = title;
                    category.Importance = importance ?? -1;
                    category.ImageUrl = imageUrl;
                    category.Description = description;

                    // save changes to database
                    dc.SubmitChanges();

                    TempData["SuccessMessage"] = "Your category has been updated.";
                }
                catch (Exception exc)
                {
                    TempData["ErrorMessage"] = exc.Message;
                }
            }

            ViewData["categorytitle"] = title ?? category.Title;
            ViewData["importance"] = importance ?? category.Importance;
            ViewData["imageUrl"] = imageUrl ?? category.ImageUrl;
            ViewData["description"] = description ?? category.Description;

            ViewBag.Title = "Edit Category";

            return View("CreateCategory");
        }
Ejemplo n.º 29
0
        public ActionResult EditComment(int commentId, string name, string body)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            Comment comment = dc.Comments.GetComment(commentId);

            // throw a 404 Not Found if the requested article is not in the database
            if (comment == null)
                throw new HttpException(404, "The comment could not be found.");

            comment.AddedBy = name;
            comment.Body = body;

            // save changes to database
            dc.SubmitChanges();

            return View(new
            {
                commentId = comment.CommentID,
                name = comment.AddedBy,
                body = comment.Body
            });
        }
Ejemplo n.º 30
0
        public ActionResult RemoveOption(int optionId)
        {
            TheBeerHouseDataContext dc = new TheBeerHouseDataContext();
            var option = dc.PollOptions.GetPollOption(optionId);

            if (option == null)
                throw new HttpException(404, "The poll option could not be found.");

            dc.PollOptions.DeleteOnSubmit(option);
            dc.SubmitChanges();

            return View(new { optionId = optionId });
        }