Exemplo n.º 1
0
        public ActionResult Index()
        {
            //<if:Northwind>
            var cachedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5),
                                                              OrderRow.Fields.GenerationKey, () =>
            {
                var model = new DashboardPageModel();
                var o     = OrderRow.Fields;
                using (var connection = SqlConnections.NewFor <OrderRow>())
                {
                    model.OpenOrders         = connection.Count <OrderRow>(o.ShippingState == (int)OrderShippingState.NotShipped);
                    var closedOrders         = connection.Count <OrderRow>(o.ShippingState == (int)OrderShippingState.Shipped);
                    var totalOrders          = model.OpenOrders + closedOrders;
                    model.ClosedOrderPercent = (int)Math.Round(totalOrders == 0 ? 100 :
                                                               ((double)closedOrders / (double)totalOrders * 100));
                    model.CustomerCount = connection.Count <CustomerRow>();
                    model.ProductCount  = connection.Count <ProductRow>();
                }
                return(model);
            });

            return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel));
            //<else>
            //return View(MVC.Views.Common.Dashboard.DashboardIndex, new DashboardPageModel());
            //</if:Northwind>
        }
Exemplo n.º 2
0
        private Dictionary <string, bool> GetUserPermissions(int userId)
        {
            var fld = UserPermissionRow.Fields;

            return(TwoLevelCache.GetLocalStoreOnly("UserPermissions:" + userId, TimeSpan.Zero, fld.GenerationKey, () =>
            {
                using (var connection = SqlConnections.NewByKey("Default"))
                {
                    var result = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase);

                    connection.List <UserPermissionRow>(q => q
                                                        .Select(fld.PermissionKey)
                                                        .Select(fld.Granted)
                                                        .Where(new Criteria(fld.UserId) == userId))
                    .ForEach(x => result[x.PermissionKey] = x.Granted ?? true);

                    var implicitPermissions = new Repositories.UserPermissionRepository().ImplicitPermissions;
                    foreach (var pair in result.ToArray())
                    {
                        HashSet <string> list;
                        if (pair.Value && implicitPermissions.TryGetValue(pair.Key, out list))
                        {
                            foreach (var x in list)
                            {
                                result[x] = true;
                            }
                        }
                    }

                    return result;
                }
            }));
        }
        public override void Decorate()
        {
            var idList = this.Value as IEnumerable <int>;

            if (idList == null || !idList.Any())
            {
                this.Value = "";
                return;
            }

            var byId = TwoLevelCache.GetLocalStoreOnly("CityIDListDecorator:CityIDById",
                                                       TimeSpan.Zero, TerritoryRow.Fields.GenerationKey, () =>
            {
                using (var connection = SqlConnections.NewFor <TerritoryRow>())
                {
                    var fld = TerritoryRow.Fields;
                    return(connection.List <TerritoryRow>(q => q
                                                          .Select(fld.ID)
                                                          .Select(fld.TerritoryDescription))
                           .ToDictionary(x => x.ID.Value));
                }
            });

            this.Value = String.Join(", ", idList.Select(x =>
            {
                TerritoryRow e;
                return(byId.TryGetValue(x, out e) ? e.TerritoryDescription : x.ToString());
            }));
        }
Exemplo n.º 4
0
        private HashSet <string> GetRolePermissions(int roleId)
        {
            var fld = RolePermissionRow.Fields;

            return(TwoLevelCache.GetLocalStoreOnly("RolePermissions:" + roleId, TimeSpan.Zero, fld.GenerationKey, () =>
            {
                using (var connection = SqlConnections.NewByKey("Default"))
                {
                    var result = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

                    connection.List <RolePermissionRow>(q => q
                                                        .Select(fld.PermissionKey)
                                                        .Where(new Criteria(fld.RoleId) == roleId))
                    .ForEach(x => result.Add(x.PermissionKey));

                    var implicitPermissions = new Repositories.UserPermissionRepository().ImplicitPermissions;
                    foreach (var key in result.ToArray())
                    {
                        HashSet <string> list;
                        if (implicitPermissions.TryGetValue(key, out list))
                        {
                            foreach (var x in list)
                            {
                                result.Add(x);
                            }
                        }
                    }

                    return result;
                }
            }));
        }
Exemplo n.º 5
0
        public ActionResult Index()
        {
            #region MyRegion

            var allRows = typeof(Row).Assembly.GetTypes().Where(type => type.IsSubclassOf(typeof(Row))).ToList();

            #endregion

            var cachedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5),
                                                              OrderRow.Fields.GenerationKey, () =>
            {
                var model = new DashboardPageModel();
                var o     = OrderRow.Fields;
                using (var connection = SqlConnections.NewFor <OrderRow>())
                {
                    model.OpenOrders         = connection.Count <OrderRow>(o.ShippingState == (int)OrderShippingState.NotShipped);
                    var closedOrders         = connection.Count <OrderRow>(o.ShippingState == (int)OrderShippingState.Shipped);
                    var totalOrders          = model.OpenOrders + closedOrders;
                    model.ClosedOrderPercent = (int)Math.Round(totalOrders == 0 ? 100 :
                                                               ((double)closedOrders / (double)totalOrders * 100));
                    model.CustomerCount = connection.Count <CustomerRow>();
                    model.ProductCount  = connection.Count <ProductRow>();
                }
                return(model);
            });
            return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel));
        }
Exemplo n.º 6
0
        public override void Decorate()
        {
            var idList = this.Value as IEnumerable <int>;

            if (idList == null || !idList.Any())
            {
                this.Value = "";
                return;
            }

            var byId = TwoLevelCache.GetLocalStoreOnly("EmployeeListDecorator:EmployeeById",
                                                       TimeSpan.Zero, EmployeeRow.Fields.GenerationKey, () =>
            {
                using (var connection = SqlConnections.NewFor <EmployeeRow>())
                {
                    var fld = EmployeeRow.Fields;
                    return(connection.List <EmployeeRow>(q => q
                                                         .Select(fld.EmployeeID)
                                                         .Select(fld.FullName))
                           .ToDictionary(x => x.EmployeeID.Value));
                }
            });

            this.Value = String.Join(", ", idList.Select(x =>
            {
                EmployeeRow e;
                return(byId.TryGetValue(x, out e) ? e.FullName : x.ToString());
            }));
        }
Exemplo n.º 7
0
            private Script GenerateContent()
            {
                byte[] ub = null;
                byte[] cb = null;

                string scriptText = Generator.GetScript();

                using (var ms = new MemoryStream(scriptText.Length))
                {
                    using (var sw = new StreamWriter(ms, new UTF8Encoding(true)))
                    {
                        sw.Write(scriptText);
                        sw.Flush();

                        ub = ms.ToArray();
                        ms.Seek(0, SeekOrigin.Begin);

                        if (ms.Length > 4096)
                        {
                            using (var cs = new MemoryStream((int)ms.Length))
                            {
                                using (var gz = new GZipStream(cs, CompressionMode.Compress))
                                {
                                    ms.CopyTo(gz);
                                    gz.Flush();
                                }

                                cb = cs.ToArray();
                            }
                        }
                    }

                    var script = new Script
                    {
                        Hash              = GetMD5HashString(ub),
                        Time              = DateTime.UtcNow,
                        ScriptText        = scriptText,
                        CompressedBytes   = cb,
                        UncompressedBytes = ub,
                        Expiration        = Generator.Expiration == TimeSpan.Zero ? DateTime.MaxValue :
                                            DateTime.Now.Add(Generator.Expiration)
                    };

                    this.content = script;

                    if (Generator.GroupKey == null)
                    {
                        return(script);
                    }

                    TwoLevelCache.GetLocalStoreOnly("DynamicScriptCheck:" + this.Name, Generator.Expiration,
                                                    Generator.GroupKey, () =>
                    {
                        return(new object());
                    });

                    return(script);
                }
            }
Exemplo n.º 8
0
        public NavigationModel()
        {
            Items = TwoLevelCache.GetLocalStoreOnly("LeftNavigationModel:NavigationItems:" + (Authorization.UserId ?? "-1"), TimeSpan.Zero,
                                                    UserPermissionRow.Fields.GenerationKey, () =>
                                                    NavigationHelper.GetNavigationItems(System.Web.VirtualPathUtility.ToAbsolute));

            SetActivePath();
        }
Exemplo n.º 9
0
        public ScriptUserDefinition GetUserData()
        {
            var result = new ScriptUserDefinition();
            var user   = Authorization.UserDefinition as UserDefinition;

            if (user == null)
            {
                result.Permissions = new Dictionary <string, bool>();
                return(result);
            }
            result.UserId               = user.UserId;
            result.Username             = user.Username;
            result.DisplayName          = user.DisplayName;
            result.IsAdmin              = user.Username == "admin";
            result.TenantId             = user.TenantId;
            result.RestrictedToCabinets = user.RestrictedToCabinets;
            //TODO: Major speed issue when using in the Frond End
            //result.PaidPeriod = UserSubscriptionHelper.GetTenantPaidDays(user.TenantId);
            result.TenantCurrencyId = user.TenantCurrencyId;

            result.Permissions = TwoLevelCache.GetLocalStoreOnly("ScriptUserPermissions:" + user.Id, TimeSpan.Zero,
                                                                 UserPermissionRow.Fields.GenerationKey, () =>
            {
                //TODO: Major speed issue when using in the Frond End
                //var connection = SqlConnections.NewFor<UserRoleRow>();
                //var rolesFld = RoleRow.Fields;
                //var roleIdList = UserSubscriptionHelper.GetUserRolesIdBasedOnSubscription(user.UserId, user.TenantId);
                //if (roleIdList.Any())
                //    result.RolesList = connection.List<RoleRow>(rolesFld.RoleId.In(roleIdList)).Select(r => r.RoleName).ToList();


                var permissions = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase);

                if (permissionsUsedFromScript == null)
                {
                    permissionsUsedFromScript = new UserPermissionRepository().ListPermissionKeys().Entities
                                                .Where(permissionKey =>
                    {
                        // this sends permission information for all permission keys to client side.
                        // if you don't need all of them to be available from script, filter them here.
                        // this is recommended for security / performance reasons...
                        return(true);
                    }).ToArray();
                }

                foreach (var permissionKey in permissionsUsedFromScript)
                {
                    if (Authorization.HasPermission(permissionKey))
                    {
                        permissions[permissionKey] = true;
                    }
                }

                return(permissions);
            });

            return(result);
        }
        public NavigationModel()
        {
            Items = TwoLevelCache.GetLocalStoreOnly("LeftNavigationModel:NavigationItems:" + (Authorization.UserId ?? "-1"), TimeSpan.Zero,
                                                    UserPermissionRow.Fields.GenerationKey, () =>
                                                    NavigationHelper.GetNavigationItems(x =>
                                                                                        x != null && x.StartsWith("~/") ? VirtualPathUtility.ToAbsolute(x) : x));

            SetActivePath();
        }
 public override string GetScript()
 {
     return(TwoLevelCache.GetLocalStoreOnly("MultiTenantLookup:" + this.ScriptName + ":" +
                                            ((UserDefinition)Authorization.UserDefinition).TenantId, TimeSpan.FromHours(1),
                                            new TRow().GetFields().GenerationKey, () =>
     {
         return base.GetScript();
     }));
 }
Exemplo n.º 12
0
        public ActionResult Index()
        {
            var cachedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5),
                                                              UserRow.Fields.GenerationKey, () =>
            {
                return(new DashboardPageModel());
            });

            return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel));
        }
Exemplo n.º 13
0
        public ActionResult Index()
        {
            var cachedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5),
                                                              OrderRow.Fields.GenerationKey, () =>
            {
                var model = new DashboardPageModel();
                var o     = OrderRow.Fields;
                var r     = CustomerRow.Fields;

                var e = EmployeesRow.Fields;

                SqlQuery orderquery = new SqlQuery();
                orderquery.Select("SUM(" + OrderRow.Fields.HowMany.Name + ")")
                .From(OrderRow.Fields).Where(OrderRow.Fields.HowMany.IsNotNull());

                SqlQuery cancelledorderquery = new SqlQuery();
                cancelledorderquery.Select("SUM(" + OrderRow.Fields.HowManyInt.Name + ")")
                .From(OrderRow.Fields).Where(OrderRow.Fields.Cancelled == 1);


                using (var connection = SqlConnections.NewFor <OrderRow>())
                {
                    model.OpenOrders         = connection.Count <OrderRow>(o.ShippingState == (int)OrderShippingState.NotShipped);
                    var closedOrders         = connection.Count <OrderRow>(o.ShippingState == (int)OrderShippingState.Shipped);
                    var totalOrders          = model.OpenOrders + closedOrders;
                    model.ClosedOrderPercent = (int)Math.Round(totalOrders == 0 ? 100 :
                                                               ((double)closedOrders / (double)totalOrders * 100));
                    model.CustomerCount       = connection.Count <CustomerRow>();
                    model.ProductCount        = connection.Count <ProductRow>();
                    model.EmployeeCount       = connection.Count <EmployeeRow>();
                    model.ActiveEmployeeCount = connection.Count <EmployeesRow>(e.Inactive == 0);
                    model.ActiveCustomerCount = connection.Count <CustomerRow>(r.Active == 0);
                    //model.OrderCount = connection.Count<OrderRow>();
                    model.OrderCount          = connection.Query <int>(orderquery).FirstOrDefault() - connection.Query <int>(cancelledorderquery).FirstOrDefault() /*- connection.Count<OrderRow>(o.Cancelled == 1)*/;
                    model.CancelledOrderCount = connection.Query <int>(cancelledorderquery).FirstOrDefault();


                    model.ClientsByCity              = ClientsByCity(connection);
                    model.ClientsByAge               = ClientsByAgeRange(connection);
                    model.ClientsByStatusType        = ClientsByStatusType(connection);
                    model.ClientsByStatusOption      = ClientsByStatusOption(connection);
                    model.ClientsByReferralSource    = ClientsByReferralSource(connection);
                    model.VolunteersByReferralSource = VolunteersByReferralSource(connection);
                }

                using (var connection = SqlConnections.NewFor <CustomerRow>())
                {
                    model.ContraCostaRiders = connection.Count <CustomerRow>(r.County == (int)RiderByCounty.ContraCosta);
                    model.AlamedaRiders     = connection.Count <CustomerRow>(r.County == (int)RiderByCounty.Alameda);
                }
                return(model);
            });

            return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel));
        }
Exemplo n.º 14
0
        private HashSet <int> GetUserRoles(int userId)
        {
            var fld = UserRoleRow.Fields;

            return(TwoLevelCache.GetLocalStoreOnly("UserRoles:" + userId, TimeSpan.Zero, fld.GenerationKey, () => {
                using (var connection = SqlConnections.NewByKey("Default")) {
                    var result = new HashSet <int>();

                    connection.List <UserRoleRow>(q => q
                                                  .Select(fld.RoleId)
                                                  .Where(new Criteria(fld.UserId) == userId))
                    .ForEach(x => result.Add(x.RoleId.Value));

                    return result;
                }
            }));
        }
Exemplo n.º 15
0
        public ScriptUserDefinition GetUserData()
        {
            var result = new ScriptUserDefinition();
            var user   = Authorization.UserDefinition as UserDefinition;

            if (user == null)
            {
                result.Permissions = new Dictionary <string, bool>();
                return(result);
            }

            result.UserId      = user.UserId;
            result.Username    = user.Username;
            result.DisplayName = user.DisplayName;
            result.IsAdmin     = user.Username == "admin";

            result.Permissions = TwoLevelCache.GetLocalStoreOnly("ScriptUserPermissions:" + user.Id, TimeSpan.Zero,
                                                                 UserPermissionRow.Fields.GenerationKey, () =>
            {
                var permissions = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase);

                if (permissionsUsedFromScript == null)
                {
                    permissionsUsedFromScript = new UserPermissionRepository().ListPermissionKeys().Entities
                                                .Where(permissionKey =>
                    {
                        // this sends permission information for all permission keys to client side.
                        // if you don't need all of them to be available from script, filter them here.
                        // this is recommended for security / performance reasons...
                        return(true);
                    }).ToArray();
                }

                foreach (var permissionKey in permissionsUsedFromScript)
                {
                    if (Authorization.HasPermission(permissionKey))
                    {
                        permissions[permissionKey] = true;
                    }
                }

                return(permissions);
            });

            return(result);
        }
Exemplo n.º 16
0
        public NavigationModel()
        {
            Items = TwoLevelCache.GetLocalStoreOnly("LeftNavigationModel:NavigationItems:" + (Authorization.UserId ?? "-1"), TimeSpan.Zero,
                                                    UserPermissionRow.Fields.GenerationKey, () =>
                                                    NavigationHelper.GetNavigationItems(x =>
                                                                                        x != null && x.StartsWith("~/") ? VirtualPathUtility.ToAbsolute(x) : x));

            SetActivePath();
            try
            {
                var user = Serenity.Authorization.UserDefinition;
                if (user != null)
                {
                    DirtyObjects.FillUserData(user.Username);
                }
            }
            catch { }
        }
Exemplo n.º 17
0
        private HashSet <string> GetRolePermissions(int userId)
        {
            var fld = RolePermissionRow.Fields;

            return(TwoLevelCache.GetLocalStoreOnly("RolePermissions:" + userId, TimeSpan.Zero, fld.GenerationKey, () =>
            {
                using (var connection = SqlConnections.NewByKey("Default"))
                {
                    var result = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

                    connection.List <RolePermissionRow>(q => q
                                                        .Select(fld.PermissionKey)
                                                        .Where(new Criteria(fld.RoleId) == userId))
                    .ForEach(x => result.Add(x.PermissionKey));

                    return result;
                }
            }));
        }
Exemplo n.º 18
0
        public ActionResult Index()
        {
            var cachedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5),
                                                              Default.Entities.CustomerRow.Fields.GenerationKey, () =>
            {
                var model = new DashboardPageModel();
                var o     = Default.Entities.CustomerRow.Fields;
                using (var connection = SqlConnections.NewFor <Default.Entities.CustomerRow>())
                {
                    model.KhongNgheMay  = connection.Count <Default.Entities.CustomerRow>(o.StatusId == 1 && o.SaleUserUsername == User.Identity.Name);
                    model.KhongCoNhuCau = connection.Count <Default.Entities.CustomerRow>(o.StatusId == 2 && o.SaleUserUsername == User.Identity.Name);
                    model.DongYMuaHang  = connection.Count <Default.Entities.CustomerRow>(o.StatusId == 3 && o.SaleUserUsername == User.Identity.Name);
                    model.HenGoiLai     = connection.Count <Default.Entities.CustomerRow>(o.StatusId == 4 && o.SaleUserUsername == User.Identity.Name);
                }
                return(model);
            });

            return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel));
        }
Exemplo n.º 19
0
        private Dictionary <string, bool> GetUserPermissions(int userId)
        {
            var fld = UserPermissionRow.Fields;

            return(TwoLevelCache.GetLocalStoreOnly("UserPermissions:" + userId, TimeSpan.Zero, fld.GenerationKey, () =>
            {
                using (var connection = SqlConnections.NewByKey("Default"))
                {
                    var result = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase);

                    connection.List <UserPermissionRow>(q => q
                                                        .Select(fld.PermissionKey)
                                                        .Select(fld.Granted)
                                                        .Where(new Criteria(fld.UserId) == userId))
                    .ForEach(x => result[x.PermissionKey] = x.Granted ?? true);

                    return result;
                }
            }));
        }
Exemplo n.º 20
0
        public ActionResult Index()
        {
            var cachedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5),
                                                              OsnovnoSredstvoRow.Fields.GenerationKey, () =>
            {
                var model = new DashboardPageModel();
                var o     = OsnovnoSredstvoRow.Fields;
                using (var connection = SqlConnections.NewFor <OsnovnoSredstvoRow>())
                {
                    model.OpenOrders         = connection.Count <OsnovnoSredstvoRow>(o.OsnovnoId == OsnovnoSredstvoRow.Fields.OsnovnoId);
                    var closedOrders         = connection.Count <AktivacijaSredstvaRow>(o.OsnovnoId == AktivacijaSredstvaRow.Fields.OsnovnoId);
                    var totalOrders          = model.OpenOrders + closedOrders;
                    model.ClosedOrderPercent = (int)Math.Round(totalOrders == 0 ? 100 :
                                                               ((double)closedOrders / (double)totalOrders * 100));
                    model.CustomerCount = connection.Count <PartneriRow>();
                    model.ProductCount  = connection.Count <AktivacijaSredstvaRow>();
                }
                return(model);
            });

            return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel));
        }
Exemplo n.º 21
0
        public ActionResult Index()
        {
            var cachedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5),
                                                              BuildingRow.Fields.GenerationKey, () =>
            {
                var model      = new DashboardPageModel();
                var connection = SqlConnections.NewByKey("Default");

                #region Zoning
                model.TotalBuildings  = connection.Count <BuildingRow>();
                model.TotalApartments = connection.Count <ApartmentRow>();
                #endregion

                #region Parameter
                model.ParametersList = connection.List <ParameterRow>();
                #endregion

                #region Meter
                model.MetersList  = connection.List <MeterRow>();
                model.TotalMeters = connection.Count <MeterRow>();
                #endregion

                #region EMSDevice
                model.TotalEMSDevices = connection.Count <EmsDeviceRow>();
                #endregion

                #region Charts
                model.BarLstModel = new List <SimpleReportViewModel>();
                model.BarLstModel = Bar();

                model.PieLstModel = new List <SimpleReportViewModel>();
                model.PieLstModel = Pie();
                #endregion

                return(model);
            });

            return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel));
        }
        public ActionResult Index()
        {
            /*
             * var cahcedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromMinutes(5), OrderRow.Fields.GenerationKey, () =>
             * {
             *  var model = new DashboardPageModel();
             *  var o = OrderRow.Fields;
             *  using (var connection = SqlConnections.NewFor<OrderRow>())
             *  {
             *      model.OpenOrders = connection.Count<OrderRow>(o.ShippingState == (int)OrderShippingState.NotShipped);
             *      var closedOrders = connection.Count<OrderRow>(o.ShippingState == (int)OrderShippingState.Shipped);
             *      var totalOrders = model.OpenOrders + closedOrders;
             *      model.ClosedOrderPercent = (int).Math.Round(totalOrder == 0 ? 100 : ((double)closedOrders / (double)totalOrders * 100);
             *      model.CustomerCount = connection.Count<CustomerRow>();
             *      model.ProductCount = connection.Count<ProductRow>();
             *  }
             *  return model;
             * });
             */
            var cachedModel = TwoLevelCache.GetLocalStoreOnly("DashboardPageModel", TimeSpan.FromSeconds(1), OrdersRow.Fields.GenerationKey, () =>
            {
                var model = new DashboardPageModel();
                var o     = OrdersRow.Fields;
                var p     = ProductsRow.Fields;
                using (var connection = SqlConnections.NewByKey("Default"))
                {
                    model.OrderCount           = connection.Count <OrdersRow>(o.DatetimeOrder == DateTime.Today);
                    model.CustomerCount        = connection.Count <CustomersRow>();
                    model.ProductCount         = connection.Count <ProductsRow>();
                    model.RunsOutProductCount  = connection.Count <ProductsRow>(p.StockQuantityProduct < 20);
                    model.LowStockProductCount = connection.Count <ProductsRow>(p.StockQuantityProduct >= 20 && p.StockQuantityProduct <= 50);
                }
                return(model);
            });

            //return View(MVC.Views.Common.Dashboard.DashboardIndex, new DashboardPageModel());
            return(View(MVC.Views.Common.Dashboard.DashboardIndex, cachedModel));
        }
Exemplo n.º 23
0
        public ScriptUserDefinition GetUserData()
        {
            var result = new ScriptUserDefinition();
            var user   = Authorization.UserDefinition as UserDefinition;

            if (user == null)
            {
                result.Permissions = new Dictionary <string, bool>();
                return(result);
            }

            result.Username    = user.Username;
            result.DisplayName = user.DisplayName;
            result.IsAdmin     = user.Username == "admin";
            result.UserRoles   = user.UserRoles;
            result.Ktp         = user.Ktp;
            result.UserRoles   = user.UserRoles;

            //using (var connection = SqlConnections.NewFor<UserRoleRow>())
            //{
            //    UserRoleListRequest request = new UserRoleListRequest();
            //    request.UserID = user.UserId;
            //    List<int> userRoleList = new UserRoleRepository().List(connection, request).Entities;
            //    List<string> arrRole = new List<string>();
            //    foreach (var roleId in userRoleList)
            //    {
            //        RetrieveRequest roleRequest = new RetrieveRequest();
            //        roleRequest.EntityId = roleId;
            //        var roleName = new RoleRepository().GetRoleName(connection, roleId);
            //        arrRole.Add(roleName);
            //    }
            //    user.UserRoles = string.Join(",", arrRole.ToArray());
            //    result.Roles = user.UserRoles;
            //}

            result.Permissions = TwoLevelCache.GetLocalStoreOnly("ScriptUserPermissions:" + user.Id, TimeSpan.Zero,
                                                                 UserPermissionRow.Fields.GenerationKey, () =>
            {
                var permissions = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase);

                if (permissionsUsedFromScript == null)
                {
                    permissionsUsedFromScript = new UserPermissionRepository().ListPermissionKeys().Entities
                                                .Where(permissionKey =>
                    {
                        // this sends permission information for all permission keys to client side.
                        // if you don't need all of them to be available from script, filter them here.
                        // this is recommended for security / performance reasons...
                        return(true);
                    }).ToArray();
                }

                foreach (var permissionKey in permissionsUsedFromScript)
                {
                    if (Authorization.HasPermission(permissionKey))
                    {
                        permissions[permissionKey] = true;
                    }
                }

                return(permissions);
            });

            return(result);
        }