private void RecalculateFatherSize(Boolean add, liteRepositoryItem child, IEnumerable <liteRepositoryItem> allItems, Int32 idPerson, DateTime date)
        {
            liteRepositoryItem father = allItems.Where(i => i.Id == child.IdFolder && i.Deleted == BaseStatusDeleted.None).FirstOrDefault();

            if (child != null && father != null)
            {
                father.Size         = (add ? father.Size + child.Size :father.Size - child.Size);
                father.VersionsSize = (add ? father.VersionsSize + child.VersionsSize : father.VersionsSize - child.VersionsSize);
                father.DeletedSize  = (add ? father.DeletedSize + child.DeletedSize : father.DeletedSize - child.DeletedSize);
                father.UpdateMetaInfo(idPerson, UC.IpAddress, UC.ProxyIpAddress, date);
                Manager.SaveOrUpdate(father);
                if (father.IdFolder > 0)
                {
                    RecalculateUpperSize(add, father, child.Size, child.VersionsSize, child.DeletedSize, allItems, idPerson, date);
                }
            }
        }
        public liteRepositoryItem ItemMoveTo(long idItem, long idSource, long idDestination, RepositoryType type, Int32 idCommunity)
        {
            liteRepositoryItem item = null;

            try
            {
                List <liteRepositoryItem> items = GetQuery(type, idCommunity).ToList();

                item = items.Where(i => i.Id == idItem).FirstOrDefault();
                litePerson person = GetValidPerson(UC.CurrentUserID);
                if (person != null && item != null && item.Deleted == BaseStatusDeleted.None && item.IdFolder == idSource)
                {
                    DateTime           modifiedOn = DateTime.Now;
                    liteRepositoryItem sFolder    = items.Where(i => i.Id == item.IdFolder && i.Deleted == BaseStatusDeleted.None).FirstOrDefault();

                    Manager.BeginTransaction();
                    if (idDestination == 0 && sFolder != null)
                    {
                        RecalculateFatherSize(false, item, items, person.Id, modifiedOn);
                        item.IdFolder = 0;
                        if (ItemHasDuplicate(item, 0, items))
                        {
                            item.Name = ItemGetSuggestedName(item, items);
                        }
                        item.DisplayOrder = long.MaxValue - 1;
                        RecalculateDisplayOrderForFolder(idDestination, items, person.Id, modifiedOn);
                        item.UpdateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, modifiedOn);
                        Manager.SaveOrUpdate(item);
                    }
                    else if (idDestination > 0)
                    {
                        liteRepositoryItem dFolder = items.Where(i => i.Id == idDestination && i.Deleted == BaseStatusDeleted.None).FirstOrDefault();
                        if (dFolder != null)
                        {
                            if (sFolder != null)
                            {
                                RecalculateFatherSize(false, item, items, person.Id, modifiedOn);
                            }
                            item.IdFolder = idDestination;
                            if (ItemHasDuplicate(item, idDestination, items))
                            {
                                item.Name = ItemGetSuggestedName(item, items);
                            }
                            RecalculateFatherSize(true, item, items, person.Id, modifiedOn);
                            item.DisplayOrder = long.MaxValue - 1;
                            RecalculateDisplayOrderForFolder(idDestination, items, person.Id, modifiedOn);
                            item.UpdateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, modifiedOn);
                            Manager.SaveOrUpdate(item);
                        }
                    }

                    Manager.Commit();
                    lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(CacheKeys.Repository(type, idCommunity));
                    lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(CacheKeys.UsersViewOfRepository(type, idCommunity));
                    lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(CacheKeys.UsersSizeViewOfRepository(type, idCommunity));
                }
            }
            catch (Exception ex)
            {
                Manager.RollBack();
            }
            return(item);
        }