public static PageSection CreatePageVariable(this IGstoreDb db, PageVariableEditViewModel viewModel, StoreFront storeFront, UserProfile userProfile) { Page page = storeFront.Pages.SingleOrDefault(pg => pg.PageId == viewModel.PageId); if (page == null) { throw new ApplicationException("ID Map error. Page Id: " + viewModel.PageId + " not found in storefront pages. Make sure this storefront has a page with the passed PageId or fix the PageId parameter in model."); } PageTemplateSection pageTemplateSection = page.PageTemplate.Sections.SingleOrDefault(pts => pts.PageTemplateSectionId == viewModel.PageTemplateSectionId); if (pageTemplateSection == null) { throw new ApplicationException("ID Map Error. Page Template Section Id: " + viewModel.PageTemplateSectionId + " not found in pages template. Make sure this storefront has the passed PageTemplateSectionId or fix the PageTemplateSectionId in model."); } PageSection record = db.PageSections.Create(); record.SetDefaults(userProfile); record.ClientId = storeFront.ClientId; record.EndDateTimeUtc = viewModel.EndDateTimeUtc; record.UseDefaultFromTemplate = false; record.HasNothing = false; record.HasPlainText = false; record.HasRawHtml = false; record.StringValue = viewModel.StringValue; record.IsPending = viewModel.IsPending; record.Order = pageTemplateSection.Order; record.PageId = viewModel.PageId; record.PageTemplateSectionId = pageTemplateSection.PageTemplateSectionId; record.PlainText = null; record.RawHtml = null; record.StartDateTimeUtc = viewModel.StartDateTimeUtc; record.StoreFrontId = storeFront.StoreFrontId; db.PageSections.Add(record); db.SaveChanges(); return record; }
public static PageSection UpdatePageVariable(this IGstoreDb db, PageVariableEditViewModel viewModel, StoreFront storeFront, UserProfile userProfile) { if (!viewModel.PageSectionId.HasValue) { throw new ApplicationException("viewModel.PageSectionId.HasValue = false. Use CreatePageVariable to create new values."); } Page page = storeFront.Pages.SingleOrDefault(pg => pg.PageId == viewModel.PageId); if (page == null) { throw new ApplicationException("ID Map error. Page Id: " + viewModel.PageId + " not found in storefront pages. Make sure this storefront has a page with the passed PageId or fix the PageId parameter in model."); } PageTemplateSection pageTemplateSection = page.PageTemplate.Sections.SingleOrDefault(pts => pts.PageTemplateSectionId == viewModel.PageTemplateSectionId); if (pageTemplateSection == null) { throw new ApplicationException("ID Map Error. Page Template Section Id: " + viewModel.PageTemplateSectionId + " not found in pages template. Make sure this storefront has the passed PageTemplateSectionId or fix the PageTemplateSectionId in model."); } PageSection record = page.Sections.SingleOrDefault(ps => ps.PageSectionId == viewModel.PageSectionId); record.StringValue = viewModel.StringValue; record.IsPending = viewModel.IsPending; record.EndDateTimeUtc = viewModel.EndDateTimeUtc; record.StartDateTimeUtc = viewModel.StartDateTimeUtc; db.PageSections.Update(record); db.SaveChanges(); return record; }