Ejemplo n.º 1
0
        public static AddEditContentViewModel Populate(this AddEditContentViewModel model, string path,
                                                       UserContext.UserContextName contextName, int version, ProviderPortalEntities db, UserContext.UserContextInfo userContext)
        {
            var content = new ContentViewModel();

            model = content.Populate(path, contextName, version, db, userContext).Content;
            var availableContexts = GetAvailableContexts(path, db);

            model.ContextsInUse = UserContext.UserContextName.All ^ availableContexts;
            return(model);
        }
Ejemplo n.º 2
0
        public static AddEditContentViewModel PopulateAsNew(this AddEditContentViewModel model, string path,
                                                            ProviderPortalEntities db)
        {
            path = ContentManager.TrimPath(path);
            var availableContexts = GetAvailableContexts(path, db);

            model.Path          = path;
            model.Title         = (path ?? String.Empty).Replace('/', ' ');
            model.Embed         = db.Contents.Any(x => x.Embed && x.Path.Equals(model.Path, StringComparison.CurrentCultureIgnoreCase));
            model.ContextsInUse = UserContext.UserContextName.All ^ availableContexts;
            model.UserContext   = availableContexts;

            return(model);
        }
Ejemplo n.º 3
0
        public static Content ToEntity(this AddEditContentViewModel model, ProviderPortalEntities db)
        {
            var currentInDb =
                db.Contents.FirstOrDefault(x => x.ContentId == model.ContentId);

            // Create if this doesn't already exist or it's not pending
            if (currentInDb == null || currentInDb.RecordStatusId != (int)Constants.RecordStatus.Pending)
            {
                var stats = db.Contents.Where(x => x.Path.Equals(model.Path, StringComparison.CurrentCultureIgnoreCase))
                            .Select(x => new { ContentId = x.ContentId, Version = x.Version, Embed = x.Embed });

                return(new Content
                {
                    Version = stats.Any() ? stats.Max(x => x.Version) + 1 : 1,
                    Path = Uri.UnescapeDataString(model.Path),
                    Title = model.Title,
                    Body = model.Body,
                    Scripts = model.Scripts,
                    Styles = model.Styles,
                    Summary = model.Summary,
                    UserContext = (int)model.UserContext,
                    Embed = stats.Any(x => x.Embed),
                    RecordStatusId = (int)Constants.RecordStatus.Pending,
                    LanguageId = AppGlobal.Language.GetLanguageIdForThisRequest(),
                    CreatedByUserId = Permission.GetCurrentUserId(),
                    CreatedDateTimeUtc = DateTime.UtcNow,
                    ModifiedByUserId = Permission.GetCurrentUserId(),
                    ModifiedDateTimeUtc = DateTime.UtcNow,
                });
            }

            // It's pending so just return the existing
            currentInDb.Path        = Uri.UnescapeDataString(model.Path);
            currentInDb.Title       = model.Title;
            currentInDb.Body        = model.Body;
            currentInDb.Scripts     = model.Scripts;
            currentInDb.Styles      = model.Styles;
            currentInDb.Summary     = model.Summary;
            currentInDb.UserContext = (int)model.UserContext;
            //currentInDb.RecordStatusId = (int)Constants.RecordStatus.Pending;
            currentInDb.LanguageId          = AppGlobal.Language.GetLanguageIdForThisRequest();
            currentInDb.CreatedByUserId     = Permission.GetCurrentUserId();
            currentInDb.CreatedDateTimeUtc  = DateTime.UtcNow;
            currentInDb.ModifiedByUserId    = Permission.GetCurrentUserId();
            currentInDb.ModifiedDateTimeUtc = DateTime.UtcNow;

            return(currentInDb);
        }
Ejemplo n.º 4
0
 public static void Validate(this AddEditContentViewModel model, ProviderPortalEntities db,
                             System.Web.Mvc.ModelStateDictionary modelState)
 {
     if (model.ContentId == 0)
     {
         if (!ContentManager.IsPathValid(model.Path))
         {
             modelState.AddModelError("Path",
                                      AppGlobal.Language.GetText("SiteContent_Error_InvalidPath",
                                                                 "Please specify a valid path."));
         }
     }
     if (model.UserContext == UserContext.UserContextName.None)
     {
         modelState.AddModelError("UserContext",
                                  AppGlobal.Language.GetText("SiteContent_Error_SelectAContext",
                                                             "Select one or more user contexts to make this content available in."));
     }
 }
Ejemplo n.º 5
0
 public static bool ContextInUse(this AddEditContentViewModel model, UserContext.UserContextName context)
 {
     return((model.ContextsInUse & context) != 0);
 }