public IActionResult Andra(VMSida vmSida, string btn) { if (btn == "LaddaUppFil" && vmSida.Fil != null) { FilService service = new FilService(); if (!service.ValideraFil(vmSida.Fil)) { ModelState.Clear(); ModelState.TryAddModelError("Fil", "Fel fil"); return(View()); } var fil = service.SparaFil(vmSida.Fil); _context.SparaBild(fil); ModelState.Clear(); vmSida.Innehall += service.GetHtmlString(fil); return(View(vmSida)); } if (ModelState.IsValid) { SidaTransform st = new SidaTransform(); var sida = st.Transform(vmSida); _context.Andra(sida); return(RedirectToRoute("sidor", new { Id = sida.Id })); } else { return(View()); } }
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()); } }