public async Task <JObject> GetByServiceIdAndPaginationAsync(string orderBy, int skip, int take, int serviceId, string user, string fromDateTime, string toDateTime)
        {
            var serviceByPermission = await _contentManagementContext.MasterDataKeyValues
                                      .Where(md => (md.TypeId == (int)EntityIdentity.Service && md.Id == serviceId) ||
                                             (md.TypeId == (int)EntityIdentity.Permission && md.ForeignKey1 == (int)ActionKey.ViewServiceLog && md.ForeignKey3 == serviceId))
                                      .ToListAsync();

            var validService = (from service in serviceByPermission
                                from permission in serviceByPermission
                                where service.Id == permission.ForeignKey3
                                where AuthorizeManager.IsAuthorize(permission.ForeignKey2)
                                select new KeyValue()
            {
                Key = service.Id.ToString(),
                Value = service.PathOrUrl
            }).ToList();

            if (validService.Count == 0)
            {
                throw new UnauthorizedAccessException(LanguageManager.ToAsErrorMessage(ExceptionKey.InvalidGrant));
            }

            var count = 0;


            return(JObject.Parse(JsonConvert.SerializeObject
                                     (new
            {
                rows = _actionLogManager.GetByServiceUrlAndPagination(orderBy,
                                                                      skip,
                                                                      take,
                                                                      validService.First().Value,
                                                                      user,
                                                                      fromDateTime.Replace("-", Helper.RootUrl).Replace("_", ":"),
                                                                      toDateTime.Replace("-", Helper.RootUrl).Replace("_", ":"),
                                                                      out count)
                       .Select(lg => new {
                    Id = lg.Id.ToString().Trim(),
                    lg.LocalDateTime,
                    lg.Name,
                    lg.ServiceUrl,
                    lg.Url,
                    lg.Type,
                    lg.User,
                    lg.ExecutionTimeInMilliseconds
                }),
                total = count
            }, Formatting.None)));
        }
Example #2
0
        public async Task <JArray> Execute(JObject data)
        {
            dynamic dataDto = data;
            bool    isQuery = dataDto.IsQuery;
            string  query   = dataDto.Code;

            if (string.IsNullOrEmpty(query.Trim()))
            {
                return(new JArray());
            }
            int connectionId = dataDto.ConnectionId;

            var connectionByPermission = await ContentManagementContext.MasterDataKeyValues
                                         .Where(md => (md.Id == connectionId && md.TypeId == (int)EntityIdentity.SqlServerConnections) ||
                                                (md.ForeignKey3 == connectionId && md.TypeId == (int)EntityIdentity.Permission)).ToListAsync();

            var connection = connectionByPermission.FirstOrDefault(con => con.Id == connectionId);

            if (connection == null)
            {
                throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.NotFound, " Connection "));
            }

            var permission = connectionByPermission.FirstOrDefault(prm => prm.ForeignKey3 == connectionId &&
                                                                   prm.TypeId == (int)EntityIdentity.Permission);

            if (permission == null)
            {
                throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.NotFound, " Permission "));
            }


            if (!AuthorizeManager.IsAuthorize(permission.ForeignKey2))
            {
                throw new UnauthorizedAccessException(LanguageManager.ToAsErrorMessage(ExceptionKey.InvalidGrant));
            }
            if (isQuery)
            {
                return(_dataBaseManager.ExecuteQuery(connection.SecondCode, query));
            }
            else
            {
                return(_dataBaseManager.ExecuteNonQuery(connection.SecondCode, query));
            }
        }
Example #3
0
        public async Task <List <KeyValue> > GetConnections(string lang = "")
        {
            var connectionByPermission = await ContentManagementContext.MasterDataKeyValues
                                         .Include(md => md.LocalValues)
                                         .Where(md => (md.TypeId == (int)EntityIdentity.SqlServerConnections && md.IsLeaf) ||
                                                (md.TypeId == (int)EntityIdentity.Permission && md.ForeignKey1 == (int)ActionKey.ConnectToConnection))

                                         .ToListAsync();

            return((from connection in connectionByPermission
                    from permission in connectionByPermission
                    where connection.Id == permission.ForeignKey3
                    where AuthorizeManager.IsAuthorize(permission.ForeignKey2)
                    select new KeyValue()
            {
                Key = connection.Id.ToString(), Value = lang == ""? connection.Name
                    : (connection.LocalValues.FirstOrDefault(lc => lc.Language == lang) == null ? "No Name": connection.LocalValues.FirstOrDefault(lc => lc.Language == lang)?.Name)
            }).ToList());
        }
        public async Task <MasterDataKeyValue> Delete(JObject data)
        {
            dynamic masterDataKeyValueData = data;
            int     id;

            try
            {
                id = masterDataKeyValueData.Id;
            }
            catch (Exception)
            {
                throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.FieldMustBeNumeric, "MasterDataKeyValue Id"));
            }
            var masterDatakeyValue = await _contentManagementContext.MasterDataKeyValues.SingleOrDefaultAsync(md => md.Id == id)
            ;

            if (masterDatakeyValue == null)
            {
                throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.MasterDataKeyValuesNotFound));
            }
            if (masterDatakeyValue.IsLeaf)
            {
                var entity = await _contentManagementContext.MasterDataKeyValues.SingleOrDefaultAsync(md => md.Id == masterDatakeyValue.ForeignKey3)
                ;

                if (!AuthorizeManager.IsAuthorize(entity.AccessRoleId))
                {
                    throw new UnauthorizedAccessException(LanguageManager.ToAsErrorMessage(ExceptionKey.InvalidGrant));
                }
            }

            var service = await _contentManagementContext.MasterDataKeyValues.SingleOrDefaultAsync(md => md.Id == masterDatakeyValue.ForeignKey3);

            if (service != null)
            {
                var key = CacheManager.GetAspectKey(CacheKey.Aspect.ToString(), ((int)ActionKey.RequestService).ToString(), service.PathOrUrl);
                CacheManager.Remove(key);
            }

            return(await _masterDataKeyValueBiz.Delete(data, true));
        }
        public async Task <MasterDataKeyValue> Save(JObject data)
        {
            dynamic masterDataDto = data;
            int     entityId;
            var     masterDatakeyValue = new MasterDataKeyValue();
            bool    isLeaf             = masterDataDto.IsLeaf;

            if (isLeaf)
            {
                try
                {
                    entityId = masterDataDto.ForeignKey3;
                }
                catch (Exception)
                {
                    throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.FieldMustBeNumeric, "MasterDataKeyValue Id"));
                }
                int entityTypeId;
                try
                {
                    entityTypeId = masterDataDto.Key;
                }
                catch (Exception)
                {
                    throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.FieldMustBeNumeric, "MasterDataKeyValue Key"));
                }
                int actionTypeId;
                try
                {
                    actionTypeId = masterDataDto.ForeignKey1;
                }
                catch (Exception)
                {
                    throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.FieldMustBeNumeric, "MasterDataKeyValue ForeignKey1"));
                }
                if (entityTypeId != (int)EntityIdentity.Link)
                {
                    masterDatakeyValue = await _contentManagementContext.MasterDataKeyValues.SingleOrDefaultAsync(md => md.Id == entityId);

                    if (masterDatakeyValue == null)
                    {
                        throw new KhodkarInvalidException(LanguageManager.ToAsErrorMessage(ExceptionKey.MasterDataKeyValuesNotFound));
                    }

                    if (!AuthorizeManager.IsAuthorize(masterDatakeyValue.AccessRoleId))
                    {
                        throw new UnauthorizedAccessException(LanguageManager.ToAsErrorMessage(ExceptionKey.InvalidGrant));
                    }
                }
                else if (actionTypeId == (int)ActionKey.ViewSourceCode)
                {
                    var link = await _contentManagementContext.Links.SingleOrDefaultAsync(ln => ln.Id == entityId);

                    var webPages = await _contentManagementContext.WebPages
                                   .Where(wp => wp.Url.ToLower() == link.Url).ToListAsync();

                    foreach (var webPage in webPages)
                    {
                        if (!AuthorizeManager.IsAuthorize(webPage.AccessRoleId))
                        {
                            throw new UnauthorizedAccessException(LanguageManager.ToAsErrorMessage(ExceptionKey.InvalidGrant));
                        }
                    }
                }
            }
            var updatedMd = await _masterDataKeyValueBiz.Save(data, true);

            if (!isLeaf || (updatedMd.Key == (int)EntityIdentity.Link))
            {
                return(updatedMd);
            }

            var key = CacheManager.GetAspectKey(CacheKey.Aspect.ToString(), ((int)ActionKey.RequestService).ToString(), masterDatakeyValue.PathOrUrl);

            CacheManager.Remove(key);
            return(updatedMd);
        }