Exemplo n.º 1
0
        /// <summary>
        ///     Сохранение позици ПозицииУказанийИТПрава
        /// </summary>
        /// <param name="grants">Список выбранных прав</param>
        /// <param name="reloadPostions">Перезапросить данные о позициях</param>
        public void SavePositionsAdvancedGrantsByDictionary(Dictionary <string, string> grants, bool reloadPostions)
        {
            foreach (var p in from p in PositionAdvancedGrants
                     let f = grants.Where(x => x.Key == p.GrantId.ToString())
                             .Select(x => (KeyValuePair <string, string>?)x)
                             .FirstOrDefault()
                             where f == null
                             select p)
            {
                p.Delete(false);
            }

            foreach (var p in from f in grants
                     let p = PositionAdvancedGrants.FirstOrDefault(x => x.GrantId.ToString() == f.Key)
                             where p == null
                             select new PositionAdvancedGrant
            {
                DocumentId = int.Parse(Id),
                GrantId = int.Parse(f.Key),
                GrantDescription = f.Value
            })
            {
                var descrs = p.GrantDescription.Split('#');
                p.GrantDescription   = descrs[0];
                p.GrantDescriptionEn = descrs[1];
                p.Save(false);
            }

            if (reloadPostions)
            {
                LoadPositionAdvancedGrants();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Метод, вызываемый вместе с сохранением документа
        /// </summary>
        private void SavePositionsAdvancedGrants(bool reloadPostions, List <DBCommand> cmds = null)
        {
            var positionAG0 = DocumentPosition <PositionAdvancedGrant> .LoadByDocId(int.Parse(Id));

            positionAG0.ForEach(delegate(PositionAdvancedGrant p0)
            {
                var p = PositionAdvancedGrants.FirstOrDefault(x => x.Id == p0.Id);
                if (p == null)
                {
                    p0.Delete(false);
                }
            });

            PositionAdvancedGrants.ForEach(delegate(PositionAdvancedGrant p)
            {
                if (string.IsNullOrEmpty(p.Id))
                {
                    p.DocumentId = int.Parse(Id);
                    p.Save(reloadPostions, cmds);
                    return;
                }

                var p0 = positionAG0.FirstOrDefault(x => x.Id == p.Id && x.ChangedTime != p.ChangedTime);
                if (p0 != null)
                {
                    p.Save(reloadPostions, cmds);
                }
            });
        }