Example #1
0
        List <MenuItem> IMenuManager.GetMenuBytenant(Guid tenantId)
        {
            var cacheKey   = _IMenuCacheManager.GetCacheKey(tenantId);
            var entityName = "";

            if (VPCCache.GetInstance().Contains <List <MenuItem> >(cacheKey))
            {
                return(VPCCache.GetInstance().Get <List <MenuItem> >(cacheKey));
            }

            IMetadataManager _IMetadataManager = new VPC.Framework.Business.MetadataManager.Contracts.MetadataManager();

            List <MenuItem> allmenus = new List <MenuItem>();

            allmenus = _review.GetMenuBytenant(tenantId).OrderBy(x => x.Name).ToList();

            foreach (var menuItem in allmenus)
            {
                if (menuItem.ReferenceEntityId != null && menuItem.ReferenceEntityId != "")
                {
                    if (menuItem != null && menuItem.MenuTypeId == 1)
                    {
                        entityName = _IMetadataManager.GetEntityNameByEntityContext(menuItem.ReferenceEntityId, false);
                    }
                    else if (menuItem != null && menuItem.MenuTypeId == 2)
                    {
                        entityName = _IMetadataManager.GetEntityNameByEntityContext(menuItem.ReferenceEntityId, true);
                    }
                    menuItem.ReferenceEntityId = entityName;
                }
            }
            VPCCache.GetInstance().Set(cacheKey, allmenus);

            return(allmenus);
        }
        private void GetValueAfterCloning(FieldModel field, Guid rootTenantId, Guid intialisedTenantId, Validator validator, string typeId)
        {
            if (field != null)
            {
                IMetadataManager _imetadataManager = new VPC.Framework.Business.MetadataManager.Contracts.MetadataManager();
                var fieldContext = _imetadataManager.GetEntityContextByEntityName(field.TypeOf, field.DataType.ToLower() == "picklist"?true:false);
                // if (!string.IsNullOrEmpty(fieldContext))
                // {
                //     var newId = (field.DataType.ToString().ToLower().Equals(VPC.Metadata.Business.DataAnnotations.DataType.PickList.ToString().ToLower())) ? GetPickListValue(field, rootTenantId, intialisedTenantId, validator.DefaultValue, fieldContext) : GetEntityValue(field, rootTenantId, intialisedTenantId, validator.DefaultValue, fieldContext);
                //     validator.DefaultValue = newId;
                // }

                dynamic newlyCreatedId = null;
                if (field.DataType.ToString().ToLower().Equals(VPC.Metadata.Business.DataAnnotations.DataType.PickList.ToString().ToLower()))
                {
                    newlyCreatedId = GetPickListValue(field, rootTenantId, intialisedTenantId, validator.DefaultValue, fieldContext);
                    if (newlyCreatedId != Guid.Empty)
                    {
                        validator.DefaultValue = newlyCreatedId;
                    }
                }
                else if (field.DataType.ToString().ToLower().Equals(VPC.Metadata.Business.DataAnnotations.DataType.Lookup.ToString().ToLower()))
                {
                    newlyCreatedId = GetEntityValue(field, rootTenantId, intialisedTenantId, validator.DefaultValue, fieldContext);
                    if (newlyCreatedId != Guid.Empty)
                    {
                        validator.DefaultValue = newlyCreatedId;
                    }
                }
            }
        }
Example #3
0
        CounterInfo IManagerCounter.GetCounters(Guid tenantId, string entityName)
        {
            IMetadataManager _iMetadataManager = new VPC.Framework.Business.MetadataManager.Contracts.MetadataManager();
            string           entityId          = _iMetadataManager.GetEntityContextByEntityName(entityName);

            return(_reviewCounter.GetCounters(tenantId, entityId));
        }
Example #4
0
        bool IManagerCounter.Update(Guid tenantId, CounterInfo info)
        {
            IMetadataManager _iMetadataManager = new VPC.Framework.Business.MetadataManager.Contracts.MetadataManager();
            string           entityId          = _iMetadataManager.GetEntityContextByEntityName(info.EntityName);

            return(_adminCounter.Update(tenantId, info, entityId));
        }
Example #5
0
        public static Guid SaveEmail(Guid tenantId, Guid userId, EmailTemplate template, string emailRecipient, string name, string referenceEntity)
        {
            IManagerScheduler _schedulerManager = new ManagerScheduler();

            if (template.Body != null && !string.IsNullOrEmpty(template.Body.Value))
            {
                ISettingManager        _iSettingManager        = new SettingManager();
                IEntityResourceManager _iEntityResourceManager = new VPC.Framework.Business.EntityResourceManager.Contracts.EntityResourceManager();
                IMetadataManager       _iMetadataManager       = new VPC.Framework.Business.MetadataManager.Contracts.MetadataManager();
                IManagerBatchItem      _managerBatchItem       = new ManagerBatchItem();
                IManagerBatchType      _managerBatchType       = new ManagerBatchType();
                var emailSubType = _iMetadataManager.GetSubTypes("email");
                var sendername   = _iSettingManager.GetSenderNameByContext(tenantId, SettingContextTypeEnum.EMAIL);

                dynamic jsonObject = new JObject();
                jsonObject.Body      = template.Body.Value.Replace("'", "''");
                jsonObject.Sender    = sendername;
                jsonObject.Recipient = emailRecipient;
                jsonObject.Date      = HelperUtility.GetCurrentUTCDate();
                jsonObject.Subject   = template.Title.Value;
                var batchType = _managerBatchType.GetBatchTypeByContext(tenantId, BatchTypeContextEnum.Email);
                if (batchType != null)
                {
                    var myObj = new JObject();
                    myObj.Add("email", jsonObject);
                    //Save Email
                    var returnId = _iEntityResourceManager.SaveResult(tenantId, userId, "email", myObj, emailSubType[0].Name.ToString());
                    //Save Batch item
                    var batchItemId = Guid.NewGuid();
                    _managerBatchItem.BatchItemCreate(tenantId, (!string.IsNullOrEmpty(batchType.ItemTimeout.Value) ? Convert.ToInt32(batchType.ItemTimeout.Value) : (int?)null)
                                                      , new BatchItem
                    {
                        BatchItemId = batchItemId,
                        BatchTypeId = Guid.Parse(batchType.InternalId.Value),
                        Name        = string.Format("{0}-{1}{2}{3}", name, DateTime.UtcNow.Year, DateTime.UtcNow.Month, DateTime.UtcNow.Day),
                        Priority    = (!string.IsNullOrEmpty(batchType.Priority.Value) ? Convert.ToInt32(batchType.Priority.Value) : (int?)null),
                        RetryCount  = 0,
                        EntityId    = referenceEntity,
                        ReferenceId = returnId,
                        Status      = EmailEnum.ReadyToSend,
                        NextRunTime = Convert.ToInt32(batchType.Type.Value) == (int)BatchTypeEnum.Scheduled ? _schedulerManager.GetNextRunDateTime(tenantId, new Guid(batchType.Scheduler.InternalId.Value)) : DateTime.MinValue,
                        // NextRunTime=   CalCulateNextRunTime(tenantId,new Guid("57AAB7B8-326E-431B-890A-56D099CB429F")),
                        AuditDetails = new AuditDetail
                        {
                            CreatedBy = userId
                        }
                    });
                    return(batchItemId);
                }
            }
            return(Guid.Empty);
        }
Example #6
0
        public bool AddRelations(Guid tenantId, string relationEntityName, string parentEntityName, Guid parentId, string childEntityName, List <Guid> childIds)
        {
            IMetadataManager _metadaManager = new VPC.Framework.Business.MetadataManager.Contracts.MetadataManager();

            var tableName  = _metadaManager.GetTableNameByEntityname(relationEntityName);
            var primaryKey = _metadaManager.GetPrimaryKeyByEntityname(relationEntityName);

            var fields = _metadaManager.GetColumnNameByEntityName(relationEntityName, null);

            if (fields.Any())
            {
                var parentTableName = _metadaManager.GetTableNameByEntityname(parentEntityName);
                var parentField     = fields.FirstOrDefault(t => t.ReferenceTableName.Equals(parentTableName));

                var childTableName = _metadaManager.GetTableNameByEntityname(childEntityName);
                var childField     = fields.FirstOrDefault(t => t.ReferenceTableName.Equals(childTableName));

                //delete and create....
                var queryBuilder = new DeleteQueryBuilder();
                queryBuilder.SelectFromTable(tableName);
                queryBuilder.AddWhere(parentField.ColumnName, Comparison.Equals, parentId.ToString(), 1);
                var deleteQuery = queryBuilder.BuildQuery();
                //----------------------------------------------------------------------------------------
                IRelationQueryAdmin deleteAdmin = new RelationQueryAdmin();
                var res = deleteAdmin.DeleteResult(tenantId, relationEntityName, deleteQuery);

                //need to change this logic....
                foreach (var childId in childIds)
                {
                    var insertQueryBuilder = new InsertQueryBuilder();
                    var insertColumns      = GetNecessaryColumns(tenantId, parentId, fields, parentField);
                    insertColumns.Add(childField.ColumnName, childId.ToString());
                    insertQueryBuilder.InsertIntoTable(tableName, insertColumns, false);
                    var insertQuery = insertQueryBuilder.BuildQuery();
                    IRelationQueryAdmin saveAdmin = new RelationQueryAdmin();
                    saveAdmin.SaveResult(tenantId, relationEntityName, insertQuery);
                }
            }
            return(true);
        }
Example #7
0
        private static CounterInfo ReadInfo(SqlDataReader reader)
        {
            IMetadataManager _iMetadataManager = new VPC.Framework.Business.MetadataManager.Contracts.MetadataManager();
            var entityId   = reader.IsDBNull(11) ? string.Empty : reader.GetString(11);
            var entityName = _iMetadataManager.GetEntityNameByEntityContext(entityId.ToString());
            var info       = new CounterInfo
            {
                CounterId     = reader.IsDBNull(0) ? Guid.Empty : reader.GetGuid(0),
                Text          = reader.IsDBNull(1) ? string.Empty : reader.GetString(1),
                Description   = reader.IsDBNull(2) ? string.Empty : reader.GetString(2),
                CounterN      = reader.IsDBNull(3) ? (int?)null : reader.GetInt32(3),
                CounterO      = reader.IsDBNull(4) ? (int?)null : reader.GetInt32(4),
                CounterP      = reader.IsDBNull(5) ? (int?)null : reader.GetInt32(5),
                ResetCounterN = reader.IsDBNull(6) ? (int?)null : reader.GetInt32(6),
                ResetCounterO = reader.IsDBNull(7) ? (int?)null : reader.GetInt32(7),
                ResetCounterP = reader.IsDBNull(8) ? (int?)null : reader.GetInt32(8),
                UpdatedOn     = reader.IsDBNull(9) ? DateTime.MinValue : reader.GetDateTime(9),
                UpdatedBy     = reader.IsDBNull(10) ? Guid.Empty : reader.GetGuid(10),
                EntityName    = entityName,
            };

            return(info);
        }
Example #8
0
        List <MenuItem> IMenuManager.GetMenu(Guid tenantId, string groupName, int pageIndex, int pageSize)
        {
            var entityName = "";
            IMetadataManager _IMetadataManager = new VPC.Framework.Business.MetadataManager.Contracts.MetadataManager();
            List <MenuItem>  allmenus          = new List <MenuItem>();

            allmenus = _review.GetMenu(tenantId, groupName, pageIndex, pageSize).OrderBy(x => x.Name).ToList();
            foreach (var menuItem in allmenus)
            {
                if (menuItem.ReferenceEntityId != null && menuItem.ReferenceEntityId != "")
                {
                    if (menuItem != null && menuItem.MenuTypeId == 1)
                    {
                        entityName = _IMetadataManager.GetEntityNameByEntityContext(menuItem.ReferenceEntityId, false);
                    }
                    else if (menuItem != null && menuItem.MenuTypeId == 2)
                    {
                        entityName = _IMetadataManager.GetEntityNameByEntityContext(menuItem.ReferenceEntityId, true);
                    }
                    menuItem.ReferenceEntityId = entityName;
                }
            }
            return(allmenus);
        }
Example #9
0
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, CustomFunctionAuth requirement)
        {
            if (!context.User.Identity.IsAuthenticated)
            {
                return(Task.CompletedTask);
            }

            bool isSuperAdmin  = bool.Parse(context.User.Claims.FirstOrDefault(c => c.Type == "IsSuperAdmin").Value);
            bool isSystemAdmin = bool.Parse(context.User.Claims.FirstOrDefault(c => c.Type == "IsSystemAdmin").Value);

            if (isSuperAdmin || isSystemAdmin)
            {
                context.Succeed(requirement);
                return(Task.CompletedTask);
            }

            var userId   = new Guid(context.User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
            var tenantId = new Guid(context.User.Claims.FirstOrDefault(c => c.Type == "TenantId").Value);

            ISecurityCacheManager securityManager  = new SecurityCacheManager();
            IMetadataManager      iMetadataManager = new VPC.Framework.Business.MetadataManager.Contracts.MetadataManager();
            var functionSecurities = securityManager.SecurityCache(tenantId, userId, false).FunctionSecurity;

            if (functionSecurities.Count == 0)
            {
                return(Task.CompletedTask);
            }
            int[] codes      = null;
            var   methodType = string.Empty;
            var   mvcContext = context.Resource as AuthorizationFilterContext;
            var   descriptor = mvcContext?.ActionDescriptor as ControllerActionDescriptor;

            if (descriptor != null)
            {
                methodType = mvcContext.HttpContext.Request.Method;

                var controllerTypeInfo = descriptor.ControllerTypeInfo;
                var headerAttr         = controllerTypeInfo.GetCustomAttribute <AddHeaderFunction>();
                if (headerAttr == null)
                {
                    return(Task.CompletedTask);
                }
                var functionContext = headerAttr.GetHeaderFunction();
                if (string.IsNullOrEmpty(functionContext))
                {
                    return(Task.CompletedTask);
                }

                var itsSecurity = (from entitySecurity in functionSecurities where entitySecurity.FunctionContext == new Guid(functionContext) select entitySecurity).ToList();
                if (itsSecurity.Count > 0)
                {
                    codes = itsSecurity[0].SecurityCode.ToString().Select(t => int.Parse(t.ToString())).ToArray();
                }
            }

            if (codes == null)
            {
                return(Task.CompletedTask);
            }

            if (methodType.ToUpper().Equals("GET"))
            {
                if (codes[0] > 1)
                {
                    context.Succeed(requirement);
                }
            }

            else if (methodType.ToUpper().Equals("POST"))
            {
                if (codes[3] > 1)
                {
                    context.Succeed(requirement);
                }
            }
            else if (methodType.ToUpper().Equals("PUT") || methodType.ToUpper().Equals("PATCH"))
            {
                if (codes[4] > 1)
                {
                    context.Succeed(requirement);
                }
            }
            else if (methodType.ToUpper().Equals("DELETE"))
            {
                if (codes[5] > 1)
                {
                    context.Succeed(requirement);
                }
            }

            return(Task.CompletedTask);
        }
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, CustomRoleAuth requirement)
        {
            if (!context.User.Identity.IsAuthenticated)
            {
                return(Task.CompletedTask);
            }

            bool isSuperAdmin  = bool.Parse(context.User.Claims.FirstOrDefault(c => c.Type == "IsSuperAdmin").Value);
            bool isSystemAdmin = bool.Parse(context.User.Claims.FirstOrDefault(c => c.Type == "IsSystemAdmin").Value);

            if (isSuperAdmin || isSystemAdmin)
            {
                context.Succeed(requirement);
                return(Task.CompletedTask);
            }

            var userId   = new Guid(context.User.Claims.FirstOrDefault(c => c.Type == "UserId").Value);
            var tenantId = new Guid(context.User.Claims.FirstOrDefault(c => c.Type == "TenantId").Value);

            ISecurityCacheManager securityManager  = new SecurityCacheManager();
            IMetadataManager      iMetadataManager = new VPC.Framework.Business.MetadataManager.Contracts.MetadataManager();
            var entitySecurities = securityManager.SecurityCache(tenantId, userId, false).EntitySecurity;

            if (entitySecurities.Count == 0)
            {
                return(Task.CompletedTask);
            }
            int[] codes      = null;
            var   methodType = string.Empty;
            var   mvcContext = context.Resource as AuthorizationFilterContext;
            var   descriptor = mvcContext?.ActionDescriptor as ControllerActionDescriptor;

            if (descriptor != null)
            {
                methodType = mvcContext.HttpContext.Request.Method;
                var routeValueOfX = (string)mvcContext.HttpContext.GetRouteValue("entityName");
                if (routeValueOfX == null)
                {
                    // mvcContext.Result = new JsonResult("Entity name not matching.") { StatusCode = 418 };
                    return(Task.CompletedTask);
                }
                var entityId    = iMetadataManager.GetEntityContextByEntityName(routeValueOfX);
                var itsSecurity = (from entitySecurity in entitySecurities where entitySecurity.EntityId == entityId select entitySecurity).ToList();
                if (itsSecurity.Count > 0)
                {
                    codes = itsSecurity[0].SecurityCode.ToString().Select(t => int.Parse(t.ToString())).ToArray();
                }
            }

            if (codes == null)
            {
                return(Task.CompletedTask);
            }

            if (methodType.ToUpper().Equals("GET"))
            {
                if (codes[0] > 1)
                {
                    context.Succeed(requirement);
                }
            }

            else if (methodType.ToUpper().Equals("POST"))
            {
                if (codes[3] > 1)
                {
                    context.Succeed(requirement);
                }
            }
            else if (methodType.ToUpper().Equals("PUT") || methodType.ToUpper().Equals("PATCH"))
            {
                if (codes[4] > 1)
                {
                    context.Succeed(requirement);
                }
            }
            else if (methodType.ToUpper().Equals("DELETE"))
            {
                if (codes[5] > 1)
                {
                    context.Succeed(requirement);
                }
            }
            // if(!context.HasSucceeded)
            //         mvcContext.Result = new JsonResult("Need a custom message") { StatusCode = 418 };
            return(Task.CompletedTask);
        }
Example #11
0
        public DataTable GetRelations(Guid tenantId, string entityName, Guid id, string relationEntityName, string intersectFieldName, string intersectClassName)
        {
            IMetadataManager _metadaManager = new VPC.Framework.Business.MetadataManager.Contracts.MetadataManager();

            var tableName  = _metadaManager.GetTableNameByEntityname(relationEntityName);
            var primaryKey = _metadaManager.GetPrimaryKeyByEntityname(relationEntityName);

            var fields = _metadaManager.GetColumnNameByEntityName(relationEntityName, null);

            if (fields.Any())
            {
                IRelationQueryAdmin admin = new RelationQueryAdmin();

                var parentTableName = _metadaManager.GetTableNameByEntityname(entityName);
                var parentField     = fields.FirstOrDefault(t => t.ReferenceTableName.Equals(parentTableName));
                if (parentField == null)
                {
                    return(null);
                }

                //
                var childField = fields.FirstOrDefault(t => t.FieldName.Equals(intersectFieldName));
                if (childField == null)
                {
                    return(null);
                }
                var childTableName       = childField.ReferenceTableName;
                var childTablePrimaryKey = childField.ReferenceColumnName;

                var intersectContext = _metadaManager.GetEntityContextByEntityName(intersectClassName, false);
                var itemTableColumns = ItemHelper.GetItemSelectDetails(tenantId, intersectContext, 0);


                var selectQueryBuilder = new SelectQueryBuilder();
                selectQueryBuilder.SelectFromTable(tableName, fields[0].EntityPrefix);

                selectQueryBuilder.AddJoin(JoinType.InnerJoin, childTableName, "_tt", childTablePrimaryKey, Comparison.Equals, tableName, fields[0].EntityPrefix, childField.ColumnName);

                selectQueryBuilder.AddJoin(JoinType.InnerJoin, itemTableColumns[0].TableName, itemTableColumns[0].EntityPrefix, childTablePrimaryKey, Comparison.Equals, tableName, fields[0].EntityPrefix, childField.ColumnName);

                var queryColumns = new List <string> ();
                var toDict       = new Dictionary <string, string> ();
                foreach (var item in itemTableColumns)
                {
                    //  if(!item.IsIntersectProperties)continue;
                    // var columnName = !string.IsNullOrEmpty (item.ClientName) ? item.ClientName + "." + item.FieldName : item.FieldName;
                    if (item.ColumnName.Equals(item.PrimaryKey) || item.ColumnName.Equals("[Name]"))
                    {
                        queryColumns.Add(item.EntityPrefix + "." + item.ColumnName);
                        toDict.Add(item.EntityPrefix + "." + item.ColumnName, item.FieldName);
                    }
                }
                selectQueryBuilder.SelectColumns(queryColumns.ToArray());
                selectQueryBuilder.SelectColumnsAndAliases(toDict);

                selectQueryBuilder.AddWhere(parentField.ColumnName, Comparison.Equals, id.ToString(), 1);
                var selectQuery = selectQueryBuilder.BuildQuery();

                IRelationReview review = new RelationReview();
                return(review.GetResult(tenantId, tableName, selectQuery));
            }
            return(null);
            //return status;
        }