public PageTranslation CreatePageTranslation(long languageID, string name, string seoName, string seoKeyword, string seoDescription, string text, string picture) { DateTime date = DateTime.Now; Page page = new Page { CreatedDate = date, UpdatedDate = date }; context.Page.Add(page); PageTranslation pageTranslation = new PageTranslation { LanguageID = languageID, Name = name, PageID = page.ID, Picture = picture, SeoDescription = seoDescription, SeoKeyword = seoKeyword, SeoName = seoName, Text = text, CreatedDate = date, UpdatedDate = date }; context.PageTranslation.Add(pageTranslation); using (TransactionScope scope = new TransactionScope()) { try { context.SaveChanges(); scope.Complete(); } catch (Exception ex) { throw ex; } } return pageTranslation; }
public PageEditModel LoadEdit(long pageID, long? languageID) { PageBusiness pageBusiness = new PageBusiness(); LanguageBusiness languageBusiness = new LanguageBusiness(); PageEditModel pageEditModel = new PageEditModel(); Page page = pageBusiness.GetPage(pageID); PageTranslation pageTranslation = null; if (languageID.HasValue) { pageTranslation = page.PageTranslation.FirstOrDefault(z => z.LanguageID == languageID); } else { pageTranslation = page.PageTranslation.FirstOrDefault(); } if (pageTranslation == null) pageTranslation = new PageTranslation(); IEnumerable<Language> languageList = languageBusiness.LanguageList(); pageEditModel.LanguageList = new SelectList(languageList, "ID", "Name", languageID); pageEditModel.LanguageID = pageTranslation.LanguageID; pageEditModel.Name = pageTranslation.Name; pageEditModel.PageID = page.ID; pageEditModel.Picture = pageTranslation.Picture; pageEditModel.SeoDescription = pageTranslation.SeoDescription; pageEditModel.SeoKeyword = pageTranslation.SeoKeyword; pageEditModel.SeoName = pageTranslation.SeoName; pageEditModel.Text = pageTranslation.Text; return pageEditModel; }