public ActionResult Create(Content model) { _repository.LangId = CurrentLangId; try { model.Id = 0; var content = new Content { Name = string.IsNullOrEmpty(model.Name) ? SiteHelper.UpdatePageWebName(model.Name, model.Title) : SiteHelper.UpdatePageWebName(model.Name), Title = model.Title, SeoDescription = model.SeoDescription, ContentType = model.ContentType, SeoKeywords = model.SeoKeywords, SeoText = model.SeoText, SortOrder = model.SortOrder }; var file = Request.Files[0]; if (file != null && !string.IsNullOrEmpty(file.FileName)) { string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); //GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500); file.SaveAs(filePath); content.ImageSource = fileName; } content.Text = model.Text == null ? "" : HttpUtility.HtmlDecode(model.Text); _repository.AddContent(content); } catch (Exception ex) { TempData["errorMessage"] = ex.Message + (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message) ? ex.InnerException.Message : ""); return View(model); } return RedirectToAction("Index"); }
public int AddContent(Content content) { if (_store.Contents.Any(c => c.Name == content.Name)) { throw new Exception(string.Format("Content {0} already exists", content.Name)); } _store.Contents.Add(content); CreateOrChangeEntityLanguage(content); _store.SaveChanges(); return content.Id; }
public void SaveContent(Content content) { var cache = _store.Contents.Single(c => c.Id == content.Id); CreateOrChangeEntityLanguage(cache); _store.SaveChanges(); }
private void CreateOrChangeEntityLanguage(Content cache) { var categoryLang = _store.ContentLangs.FirstOrDefault(r => r.ContentId == cache.Id && r.LanguageId == LangId); if (categoryLang == null) { var entityLang = new ContentLang { ContentId = cache.Id, LanguageId = LangId, Title = cache.Title, Text = cache.Text, SeoDescription = cache.SeoDescription, SeoKeywords = cache.SeoKeywords, SeoText = cache.SeoText }; _store.ContentLangs.Add(entityLang); } else { categoryLang.Title = cache.Title; categoryLang.SeoDescription = cache.SeoDescription; categoryLang.SeoKeywords = cache.SeoKeywords; categoryLang.SeoText = cache.SeoText; categoryLang.Text = cache.Text; } }
public ActionResult Edit(Content model) { _repository.LangId = CurrentLangId; try { var content = _repository.GetContent(model.Id); content.Name = SiteHelper.UpdatePageWebName(model.Name); TryUpdateModel(content, new[] { "Name", "Title", "SeoDescription", "ContentType", "SeoKeywords", "Seotext", "SortOrder" }); content.Text = model.Text == null ? "" : HttpUtility.HtmlDecode(model.Text); var file = Request.Files[0]; if (file != null && !string.IsNullOrEmpty(file.FileName)) { if (!string.IsNullOrEmpty(content.ImageSource)) { ImageHelper.DeleteImage(content.ImageSource); } string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName); string filePath = Server.MapPath("~/Content/Images"); filePath = Path.Combine(filePath, fileName); //GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500); file.SaveAs(filePath); content.ImageSource = fileName; } _repository.SaveContent(content); } catch (Exception ex) { TempData["errorMessage"] = ex.Message; return View(model); } return RedirectToAction("Index"); }