Beispiel #1
0
 public IActionResult Skapa(VMPost vmPost, string btn)
 {
     if (btn == "LaddaUppBild" && vmPost.Fil != null)
     {
         FilService service = new FilService();
         if (!service.ValideraFil(vmPost.Fil))
         {
             ModelState.Clear();
             ModelState.TryAddModelError("Fil", "Fel fil");
             return(View());
         }
         var fil = service.SparaFil(vmPost.Fil);
         _context.SparaBild(fil);
         ModelState.Clear();
         vmPost.Innehall += service.GetHtmlString(fil);
         return(View(vmPost));
     }
     if (ModelState.IsValid)
     {
         vmPost.Datum = DateTime.Now;
         PostTransform pt   = new PostTransform();
         Post          post = pt.Transform(vmPost);
         _context.Skapa(post);
         return(RedirectToAction("index", "home"));
     }
     else
     {
         return(View());
     }
 }
Beispiel #2
0
        public IActionResult Andra(int id)
        {
            var post = _context.Get(id);

            if (post != null)
            {
                PostTransform pt     = new PostTransform();
                var           vmPost = pt.Transform(post);
                return(View(vmPost));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
        public IActionResult Index()
        {
            PostTransform pt      = new PostTransform();
            VMIndex       vmIndex = new VMIndex();

            foreach (var post in _context.GetOrderdTop10())
            {
                vmIndex.Poster.Add(pt.Transform(post));
            }
            foreach (var rubrik in _context.Get().OrderByDescending(p => p.Datum))
            {
                vmIndex.Rubriker.Add(new VMPostlistaItem()
                {
                    Id = rubrik.Id, Rubrik = rubrik.Rubrik
                });
            }

            return(View(vmIndex));
        }