Ejemplo n.º 1
0
        public ActionResult Add(SuggestionModel model)
        {
            var suggestion = Mapper.Map<SuggestionModel, Suggestion>(model);
            suggestion.Date = DateTime.Now;
            suggestion.Status = (int)SuggestionStatus.Active;

            using (var container = new SuggestionBoxContainer())
            {
                container.Suggestions.AddObject(suggestion);
                container.SaveChanges();
                container.AcceptAllChanges();

                SuggestionEmailer.SendEmail(suggestion);

                var suggestions = container.Suggestions
                    .Where(s => s.Status != (int)SuggestionStatus.Deleted || UserIsAdmin)
                    .OrderByDescending(s => s.Id).Select(ConvertSuggestionToModel).ToList();

                return PartialView("Partials/_SuggestionList", suggestions);
            }
        }
Ejemplo n.º 2
0
        public ActionResult Approve(SuggestionModel model, string commentText)
        {
            using (var container = new SuggestionBoxContainer())
            {
                var suggestion = container.Suggestions.FirstOrDefault(s => s.Id == model.Id);

                if (UserIsAdmin)
                {
                    var comment = new Comment
                                    {
                                        Body = commentText,
                                        Date = DateTime.Now,
                                        Status = (int)CommentStatus.Active
                                    };
                    suggestion.Comments.Add(comment);
                    suggestion.Status = (int)SuggestionStatus.Approved;

                    container.SaveChanges();
                    container.AcceptAllChanges();
                }

                return PartialView("Partials/_View", ConvertSuggestionToModel(suggestion));
            }
        }