private static string CheckLockedPropertySnippet(LockPropertyInfo info)
        {
            string propertyName = info.Source.Name;
            if (info.Source is ReferencePropertyInfo)
                propertyName += "ID";

            return string.Format(
            @"if (updatedNew.Count() > 0 || deletedIds.Count() > 0)
            {{
                {0}[] changedItems = updated.Zip(updatedNew, (i, j) => ({4})
                    ? i : null).Where(x => x != null).ToArray();

                if (changedItems != null && changedItems.Length > 0)
                {{
                    var lockedItems = _domRepository.{0}.Filter(this.Query(changedItems.Select(item => item.ID)), new {1}());
                    if (lockedItems.Count() > 0)
                        throw new Rhetos.UserException({2}, ""DataStructure:{0},ID:"" + lockedItems.First().ID.ToString() + "",Property:{3}"");
                }}
            }}
            ",
                info.Source.DataStructure.GetKeyProperties(),
                info.FilterType,
                CsUtility.QuotedString(info.Title),
                propertyName,
                CompareValuePropertySnippet(propertyName));
        }
示例#2
0
        private static string CheckLockedPropertySnippet(LockPropertyInfo info)
        {
            string propertyName = info.Source.Name;
            if (info.Source is ReferencePropertyInfo)
                propertyName += "ID";

            return string.Format(
            @"            if (updated.Length > 0 || deleted.Length > 0)
            {{
                {0}[] changedItems = updated.Zip(updatedNew, (i, j) => ({4})
                    ? i : null).Where(x => x != null).ToArray();

                if (changedItems != null && changedItems.Length > 0)
                {{
                    var lockedItems = _domRepository.{0}.Filter(changedItems.AsQueryable(), new {1}());
                    if (lockedItems.Count() > 0)
                        throw new Rhetos.UserException({2}, ""DataStructure:{0},ID:"" + lockedItems.First().ID.ToString() + "",Property:{3}"");

                    // Workaround to restore NH proxies if NHSession.Clear() is called inside filter.
                    for (int i=0; i<updated.Length; i++) updated[i] = _executionContext.NHibernateSession.Load<{0}>(updated[i].ID);
                    for (int i=0; i<deleted.Length; i++) deleted[i] = _executionContext.NHibernateSession.Load<{0}>(deleted[i].ID);
                }}
            }}
            ",
                info.Source.DataStructure.GetKeyProperties(),
                info.FilterType,
                CsUtility.QuotedString(info.Title),
                propertyName,
                CompareValuePropertySnippet(propertyName));
        }