ConsolidatedInventoryServerFunctions.cs 1.83 KB
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using DirRX.Storage.ConsolidatedInventory;

namespace DirRX.Storage.Server
{
  partial class ConsolidatedInventoryFunctions
  {
    /// <summary>
    /// Получить список дел описи.
    /// </summary>
    /// <returns>Список дел.</returns>
    [Public, Remote(IsPure=true)]
    public virtual IQueryable<DirRX.LongTermArchive.ICaseFile> GetCaseFiles()
    {
      return DirRX.LongTermArchive.CaseFiles.GetAll(x => x.LTAConsInventoryDirRX != null && x.LTAConsInventoryDirRX.Equals(_obj));
    }
    
    /// <summary>
    /// Получить список годовых разделов описи.
    /// </summary>
    /// <returns>Список годовых разделов.</returns>
    [Public, Remote(IsPure=true)]
    public virtual IQueryable<Storage.IAnnualSection> GetAnnualSections()
    {
      return Storage.AnnualSections.GetAll(x => x.ConsolidatedInventory != null && x.ConsolidatedInventory.Equals(_obj));
    }    
    
    /// <summary>
    /// Получить следующий по порядку номер сводной описи.
    /// </summary>
    /// <returns>Номер описи.</returns>
    public virtual int GetNextInventoryNumber()
    {
      var result = 1;
      AccessRights.AllowRead(
        () =>
        {
          // Предполагается, что все ключевые свойства заполнены (необходимо проверить до вызова).
          var lastDocument = ConsolidatedInventories.GetAll(x => x.Id != _obj.Id && x.Number.HasValue).OrderByDescending(x => x.Id).FirstOrDefault();
          if (lastDocument != null)
            result += lastDocument.Number.Value;
        });
            
      return result;      
    }
  }
}