Beispiel #1
0
        private static IEnumerable <WidgetContainer> GetContainers(int tenant)
        {
            var containers = Cache.Get(GetKey(tenant)) as List <WidgetContainer>;

            if (containers == null)
            {
                var dic = new Dictionary <Guid, WidgetContainer>();
                var q   = new SqlQuery()
                          .From("webstudio_widgetcontainer c")
                          .LeftOuterJoin("webstudio_widgetstate s", Exp.EqColumns("c.ID", "s.WidgetContainerID"))
                          .Select("c.ID", "c.ContainerID", "c.UserID", "c.TenantID", "c.SchemaID", "s.WidgetID", "s.ColumnID", "s.SortOrderInColumn")
                          .Where("c.tenantid", tenant)
                          .OrderBy("c.ID", true);

                using (var db = GetDb())
                {
                    foreach (var r in db.ExecuteList(q))
                    {
                        var id = new Guid((string)r[0]);
                        if (!dic.ContainsKey(id))
                        {
                            dic[id] = new WidgetContainer(id, new Guid((string)r[1]))
                            {
                                UserID           = new Guid((string)r[2]),
                                TenantID         = Convert.ToInt32(r[3]),
                                ColumnSchemaType = (ColumnSchemaType)Convert.ToInt32(r[4]),
                            };
                        }
                        if (r[5] != null)
                        {
                            dic[id].States.Add(new WidgetState(new Guid((string)r[5]), id)
                            {
                                X = Convert.ToInt32(r[6]), Y = Convert.ToInt32(r[7])
                            });
                        }
                    }
                }

                containers = dic.Values.ToList();
                Cache.Insert(GetKey(tenant), containers, CacheExpiration);
            }
            return(containers);
        }
Beispiel #2
0
        public static bool SaveWidgetContainer(WidgetContainer container)
        {
            try
            {
                ResetContainers(container.TenantID);

                using (var db = GetDb())
                    using (var tr = db.BeginTransaction())
                    {
                        db.ExecuteNonQuery(new SqlInsert("webstudio_widgetcontainer", true)
                                           .InColumnValue("ID", container.ID.ToString())
                                           .InColumnValue("ContainerID", container.ContainerID.ToString())
                                           .InColumnValue("UserID", container.UserID.ToString())
                                           .InColumnValue("TenantID", container.TenantID)
                                           .InColumnValue("SchemaID", (int)container.ColumnSchemaType));

                        var columnsCount = GetColumnSchemaPercents(container.ColumnSchemaType).Length;
                        db.ExecuteNonQuery(new SqlDelete("webstudio_widgetstate").Where("WidgetContainerID", container.ID.ToString()));
                        foreach (var s in container.States)
                        {
                            db.ExecuteNonQuery(new SqlInsert("webstudio_widgetstate")
                                               .InColumnValue("WidgetID", s.ID.ToString())
                                               .InColumnValue("WidgetContainerID", s.ContainerID.ToString())
                                               .InColumnValue("ColumnID", s.X < columnsCount ? s.X : 0)
                                               .InColumnValue("SortOrderInColumn", s.Y));
                        }
                        tr.Commit();
                    }
                return(true);
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(typeof(WidgetManager)).Error(ex);
                return(false);
            }
        }