Пример #1
0
        public static string RestoreFromHistory(
            Context context, SiteSettings ss, long wikiId)
        {
            if (!Parameters.History.Restore)
            {
                return(Error.Types.InvalidRequest.MessageJson());
            }
            var wikiModel = new WikiModel(context, ss, wikiId);
            var invalid   = WikiValidators.OnUpdating(
                context: context, ss: ss, wikiModel: wikiModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            var ver = Forms.Data("GridCheckedItems")
                      .Split(',')
                      .Where(o => !o.IsNullOrEmpty())
                      .ToList();

            if (ver.Count() != 1)
            {
                return(Error.Types.SelectOne.MessageJson());
            }
            wikiModel.SetByModel(new WikiModel().Get(
                                     context: context,
                                     ss: ss,
                                     tableType: Sqls.TableTypes.History,
                                     where : Rds.WikisWhere()
                                     .SiteId(ss.SiteId)
                                     .WikiId(wikiId)
                                     .Ver(ver.First())));
            wikiModel.VerUp = true;
            var error = wikiModel.Update(
                context: context,
                ss: ss,
                otherInitValue: true);

            switch (error)
            {
            case Error.Types.None:
                Sessions.Set("Message", Messages.RestoredFromHistory(ver.First().ToString()));
                return(new ResponseCollection()
                       .SetMemory("formChanged", false)
                       .Href(Locations.ItemEdit(wikiId))
                       .ToJson());

            default:
                return(error.MessageJson());
            }
        }
Пример #2
0
        public static string Update(IContext context, SiteSettings ss, long wikiId)
        {
            var wikiModel = new WikiModel(
                context: context, ss: ss, wikiId: wikiId, setByForm: true);
            var invalid = WikiValidators.OnUpdating(
                context: context,
                ss: ss,
                wikiModel: wikiModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson(context: context));
            }
            if (wikiModel.AccessStatus != Databases.AccessStatuses.Selected)
            {
                return(Messages.ResponseDeleteConflicts(context: context).ToJson());
            }
            var error = wikiModel.Update(
                context: context,
                ss: ss,
                notice: true,
                permissions: context.Forms.List("CurrentPermissionsAll"),
                permissionChanged: context.Forms.Exists("CurrentPermissionsAll"));

            switch (error)
            {
            case Error.Types.None:
                var res = new WikisResponseCollection(wikiModel);
                res.ReplaceAll("#Breadcrumb", new HtmlBuilder()
                               .Breadcrumb(context: context, ss: ss));
                return(ResponseByUpdate(res, context, ss, wikiModel)
                       .PrependComment(
                           context: context,
                           ss: ss,
                           column: ss.GetColumn(context: context, columnName: "Comments"),
                           comments: wikiModel.Comments,
                           verType: wikiModel.VerType)
                       .ToJson());

            case Error.Types.UpdateConflicts:
                return(Messages.ResponseUpdateConflicts(
                           context: context,
                           data: wikiModel.Updator.Name)
                       .ToJson());

            default:
                return(error.MessageJson(context: context));
            }
        }
        public static string Update(SiteSettings ss, long wikiId)
        {
            var wikiModel = new WikiModel(ss, wikiId, setByForm: true);
            var invalid   = WikiValidators.OnUpdating(ss, wikiModel);

            switch (invalid)
            {
            case Error.Types.None: break;

            default: return(invalid.MessageJson());
            }
            if (wikiModel.AccessStatus != Databases.AccessStatuses.Selected)
            {
                return(Messages.ResponseDeleteConflicts().ToJson());
            }
            var error = wikiModel.Update(
                ss: ss,
                notice: true,
                permissions: Forms.List("CurrentPermissionsAll"),
                permissionChanged: Forms.Exists("CurrentPermissionsAll"));

            if (error.Has())
            {
                return(error == Error.Types.UpdateConflicts
                    ? Messages.ResponseUpdateConflicts(wikiModel.Updator.Name).ToJson()
                    : new ResponseCollection().Message(error.Message()).ToJson());
            }
            else
            {
                var res = new WikisResponseCollection(wikiModel);
                res.ReplaceAll("#Breadcrumb", new HtmlBuilder().Breadcrumb(ss.SiteId));
                return(ResponseByUpdate(res, ss, wikiModel)
                       .PrependComment(
                           ss,
                           ss.GetColumn("Comments"),
                           wikiModel.Comments,
                           wikiModel.VerType)
                       .ToJson());
            }
        }