Exemple #1
0
        private VersionCompareViewModel GetStoreCompareModel(ApiCall call, Sites.Repository.SiteDb sitedb, long id1, long id2)
        {
            VersionCompareViewModel model = new VersionCompareViewModel()
            {
                Id1 = id1, Id2 = id2
            };

            LogEntry prelog = sitedb.Log.Get(id1);

            if (prelog != null)
            {
                var      repo = sitedb.GetRepository(prelog.StoreName);
                LogEntry nextlog;
                if (id2 == -1)
                {
                    nextlog   = sitedb.Log.Store.Where(o => o.KeyHash == prelog.KeyHash && o.StoreNameHash == prelog.StoreNameHash).OrderByDescending().FirstOrDefault();
                    model.Id2 = nextlog.Id;
                }
                else
                {
                    nextlog = sitedb.Log.Get(id2);
                }

                ISiteObject itemone = repo.GetByLog(prelog);
                ISiteObject itemtwo = null;
                if (nextlog.EditType != EditType.Delete)
                {
                    itemtwo = repo.GetByLog(nextlog);
                }

                model.Title1 = itemone.Name;
                model.Title2 = itemtwo != null ? itemtwo.Name : string.Empty;
                if (itemone is Image)
                {
                    string baseurl = call.WebSite.BaseUrl();

                    string url1 = (Sites.Systems.Routes.SystemRouteTemplate.Replace("{objecttype}", repo.ModelType.Name).Replace("{nameorid}", prelog.Id.ToString()));
                    string url2 = Sites.Systems.Routes.SystemRouteTemplate.Replace("{objecttype}", repo.ModelType.Name).Replace("{nameorid}", nextlog.Id.ToString());

                    model.DataType = VersionDataType.Image;
                    model.Source1  = Kooboo.Lib.Helper.UrlHelper.Combine(baseurl, url1);

                    model.Source2 = Kooboo.Lib.Helper.UrlHelper.Combine(baseurl, url2);
                }
                else
                {
                    model.Source1  = Sites.Service.ObjectService.GetSummaryText(itemone);
                    model.Source2  = Sites.Service.ObjectService.GetSummaryText(itemtwo);
                    model.DataType = VersionDataType.String;
                }
            }
            return(model);
        }
Exemple #2
0
        private VersionCompareViewModel GetTableCompareModel(ApiCall call, Sites.Repository.SiteDb sitedb, long id1, long id2)
        {
            VersionCompareViewModel model = new VersionCompareViewModel()
            {
                Id1 = id1, Id2 = id2
            };

            LogEntry prelog = sitedb.Log.Get(id1);

            if (prelog != null)
            {
                var db    = Kooboo.Data.DB.GetKDatabase(call.Context.WebSite);
                var table = Data.DB.GetTable(db, prelog.TableName);

                LogEntry nextlog;
                if (id2 == -1)
                {
                    nextlog   = sitedb.Log.Store.Where(o => o.KeyHash == prelog.KeyHash && o.TableNameHash == prelog.TableNameHash).OrderByDescending().FirstOrDefault();
                    model.Id2 = nextlog.Id;
                }
                else
                {
                    nextlog = sitedb.Log.Get(id2);
                }
                var itemone = table.GetLogData(prelog);
                Dictionary <string, object> itemtwo = null;

                if (nextlog.EditType != EditType.Delete)
                {
                    itemtwo = table.GetLogData(nextlog);
                }

                model.Title1 = Data.Language.Hardcoded.GetValue("Table", call.Context) + ":" + prelog.TableName;
                model.Title2 = model.Title1;

                if (itemone != null)
                {
                    model.Source1 = Sites.Service.ObjectService.GetSummaryText(itemone);
                }
                if (itemtwo != null)
                {
                    model.Source2 = Sites.Service.ObjectService.GetSummaryText(itemtwo);
                }
                model.DataType = VersionDataType.String;
            }
            return(model);
        }