public ActionResult Details(int id)
        {
            var mediator = new ArticleMediator();
            var service = new ApiService();

            var entityarticles = mediator.Get(id);
            var article = service.GetArticle(entityarticles.Path);

            return View(article);
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Header, Body, CategoryId")] Article article)
        {
            // TODO :
            // Bruger skal ikke kunne trykke submit flere gange

            var categorymediator = new Database.CategoryMediator();
            var articlemediator = new ArticleMediator();

            #region itemsrep
            // skal finde en anden løsning, evt. et repository
            var items = categorymediator.GetAllCategories().Select(cat => new SelectListItem
            {
                Text = cat.Name,
                Value = cat.Id.ToString()
            }).ToList();

            ViewBag.CategoryItems = items;
            #endregion

            var categoryid = article.CategoryId;
            var category = categorymediator.GetAllCategories().First(x => x.Id == categoryid);
            article.CategoryId = category.Id;

            if (ModelState.IsValid)
            {
                var service = new JsonService();

                string path = service.CreateJson(article);
                article.Path = path;

                articlemediator.Save(article);

                return RedirectToAction("List", "Article");
            }

            ViewBag.Error = "Kan ikke oprette";

            return View(article);
        }