Ejemplo n.º 1
0
        /// <summary>
        /// 入库
        /// </summary>
        /// <param name="file">文件对象</param>
        /// <param name="storeContainer">存放容器对象</param>
        /// <returns></returns>
        public async Task StockIn(FileBase file, StoreContainer storeContainer)
        {
            string errMessage    = string.Empty;
            var    fileStoreInfo = await _fileStoreInfoRepository.FirstOrDefaultAsync(p => p.FileId == file.Id);

            if (fileStoreInfo != null)
            {
                switch (fileStoreInfo.StoreState)
                {
                case StoreState.已出库:
                    fileStoreInfo.StoreState      = StoreState.在库;
                    fileStoreInfo.FileContainerId = storeContainer.Id;
                    break;

                case StoreState.在库:
                    errMessage = $"档案编号[{file.DocumentSerialNumber}]状态为:[已入库],请检查";
                    break;

                case StoreState.已报废:
                    errMessage = $"档案编号{file.DocumentSerialNumber}状态为:已报废,不可入库";
                    break;
                }
            }
            else
            {
                fileStoreInfo = new FileStoreInfo
                {
                    FileId          = file.Id,
                    FileType        = file.GetType().FullName,
                    FileContainerId = storeContainer.Id,
                    StoreState      = StoreState.在库
                };
                await _fileStoreInfoRepository.InsertAsync(fileStoreInfo);
            }

            if (!string.IsNullOrEmpty(errMessage))
            {
                throw new UserFriendlyException(errMessage);
            }
        }