Exemplo n.º 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());
            }
        }