/// <summary> /// Edit values /// </summary> /// <param name="model">Model values to change</param> /// <returns>view with updated info and success/failure message</returns> public ActionResult EditDisqus(DbTables.Disqus model) { if (ModelState.IsValid) { try { var Disqus = new DbTables.Disqus(); var DisqusList = _context.Disqus.ToList(); if (DisqusList.Any()) { Disqus = DisqusList.First(); Disqus.DisqusUrl = model.DisqusUrl; } else { Disqus.DisqusUrl = model.DisqusUrl; Disqus.Enabeled = true; _context.Disqus.Add(Disqus); } _context.SaveChanges(); ViewBag.Success = "Disqus variabler ble sukessfult oppdatert"; return(PartialView("_DisqusPartial", _context.Disqus.First())); } catch (EntityException ex) { ViewBag.Error = "Error:" + ex.Message; return(PartialView("_DisqusPartial", _context.Disqus.First())); } } var DisqusError = new DbTables.Disqus(); var DisqusListError = _context.Disqus.ToList(); if (DisqusListError.Any()) { DisqusError = DisqusListError.First(); } var messages = string.Join("\r\n\r\n", ModelState.Values //validation failed .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); ViewBag.Error = "Ugyldige verdier: " + messages; return(PartialView("_DisqusPartial", DisqusError)); }
public ActionResult Article(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var article = _context.Articles.Find(id); if ((article == null) || !article.Published) { return(HttpNotFound()); } var background = new DbTables.BackgroundImage(); var backgroundList = _context.BackgroundImage.ToList(); if (backgroundList.Any()) { background = backgroundList.First(); if (background.Enabeled) { ViewBag.Style = "background:url('/File/Background?id=" + background.Image.FileId + "') no-repeat center center fixed;-webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover;background-size: cove;overflow-x: hidden;"; ViewBag.BackGround = "background-color:transparent;"; } } var disqus = new DbTables.Disqus(); var disqusList = _context.Disqus.ToList(); if (disqusList.Any()) { disqus = disqusList.First(); if (disqus.Enabeled && !string.IsNullOrEmpty(disqus.DisqusUrl)) //check if we should load in disqus { ViewBag.Disqus = disqus.DisqusUrl; } } return(View(article)); }
// GET: Admin/Various /// <summary> /// Index view of various, check if various database elements are actually added and then add these to the model if /// they exist /// </summary> /// <returns>Various index view</returns> public ActionResult Index() { var carouselObj = new DbTables.Carousel(); var GoogleCap = new DbTables.GoogleCaptchaAPI(); var GoogleCapList = _context.GoogleCaptchaAPI.ToList(); if (GoogleCapList.Any()) { GoogleCap = GoogleCapList.First(); } var SendG = new DbTables.SendGridAPI(); var SendgridList = _context.SendGridAPI.ToList(); if (SendgridList.Any()) { SendG = SendgridList.First(); } var Stripe = new DbTables.StripeAPI(); var StripeList = _context.StripeAPI.ToList(); if (StripeList.Any()) { Stripe = StripeList.First(); } var Facebook = new DbTables.Facebook(); var FacebookList = _context.Facebook.ToList(); if (FacebookList.Any()) { Facebook = FacebookList.First(); } var Twitter = new DbTables.Twitter(); var TwitterList = _context.Twitter.ToList(); if (TwitterList.Any()) { Twitter = TwitterList.First(); } var Disqus = new DbTables.Disqus(); var DisqusList = _context.Disqus.ToList(); if (DisqusList.Any()) { Disqus = DisqusList.First(); } var About = new DbTables.Info(); var AboutList = _context.About.ToList(); if (AboutList.Any()) { About = AboutList.First(); } var carousel = _context.Carousel.ToList(); if (carousel.Any()) { carouselObj = carousel.First(); } var Terms = new DbTables.TermsOfUse(); var TermsList = _context.TermsOfUse.ToList(); if (TermsList.Any()) { Terms = TermsList.First(); } var Background = new DbTables.BackgroundImage(); var BackgroundList = _context.BackgroundImage.ToList(); if (BackgroundList.Any()) { Background = BackgroundList.First(); } var model = new VariousModel { GoogleCaptchaAPI = GoogleCap, SendGridAPI = SendG, Terms = Terms, Carousel = carouselObj, About = About, StripeAPI = Stripe, Twitter = Twitter, Facebook = Facebook, Background = Background, Disqus = Disqus }; return(View(model)); }