示例#1
0
        public ActionResult AddArticle()
        {
            var model = new HelpAndAdviceDetailModel();

            using (var context = new ApplicationDbContext())
            {
                var categories = context.HelpAndAdviceCategories.Select(x => new CategoryDropDown {
                    Key = x.Id.ToString(), Value = x.Category
                }).ToList();
                ViewBag.Categories = categories;
            }
            return(View(model));
        }
示例#2
0
 public ActionResult EditArticle(int Id)
 {
     using (var context = new ApplicationDbContext())
     {
         var articleInfo  = context.HelpAndAdviceDetails.Where(y => y.Id == Id).FirstOrDefault();
         var articleModel = new HelpAndAdviceDetailModel
         {
             CategoryId = articleInfo.CategoryId,
             Content    = articleInfo.Content,
             Heading    = articleInfo.Heading,
             Id         = articleInfo.Id,
             SubHeading = articleInfo.SubHeading
         };
         var categories = context.HelpAndAdviceCategories.Select(x => new CategoryDropDown {
             Key = x.Id.ToString(), Value = x.Category
         }).ToList();
         ViewBag.Categories = categories;
         return(View(articleModel));
     }
 }
示例#3
0
        public ActionResult AddArticle(HelpAndAdviceDetailModel model)
        {
            if (ModelState.IsValid)
            {
                using (var context = new ApplicationDbContext())
                {
                    if ((model.Id == 0) || (model.Id == null))
                    {
                        var detailContext = new HelpAndAdviceDetail
                        {
                            Content     = model.Content,
                            CategoryId  = model.CategoryId,
                            Heading     = model.Heading,
                            SubHeading  = model.SubHeading,
                            LastUpdated = DateTime.Now
                        };

                        context.HelpAndAdviceDetails.Add(detailContext);
                    }
                    else
                    {
                        var detailContext = context.HelpAndAdviceDetails.Where(y => y.Id == model.Id).FirstOrDefault();
                        detailContext.Content     = model.Content;
                        detailContext.CategoryId  = model.CategoryId;
                        detailContext.Heading     = model.Heading;
                        detailContext.SubHeading  = model.SubHeading;
                        detailContext.LastUpdated = DateTime.Now;
                    }

                    context.SaveChanges();
                }

                return(RedirectToAction("ViewArticle"));
            }
            else
            {
                return(View());
            }
        }
示例#4
0
        public ActionResult ViewArticle()
        {
            using (var context = new ApplicationDbContext())
            {
                var articles = new List <HelpAndAdviceDetailModel>();

                var articlesContext = context.HelpAndAdviceDetails.ToList();
                foreach (var item in articlesContext)
                {
                    var article = new HelpAndAdviceDetailModel
                    {
                        Id         = item.Id,
                        Heading    = item.Heading,
                        SubHeading = item.SubHeading,
                        Content    = item.Content,
                        CategoryId = item.CategoryId
                    };

                    articles.Add(article);
                }

                return(View(articles));
            }
        }