Пример #1
0
        public async Task <CommonResponse <string> > ReturnBorrow([FromBody] ReturnBorrowRequest request)
        {
            request.SerializeToLog("ReturnArchives");
            var response = await _borrowRegisterService.ReturnArchives(request);

            response.SerializeToLog("ReturnArchives");
            return(response);
        }
Пример #2
0
        /// <summary>
        /// 归还
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <CommonResponse <string> > ReturnArchives(ReturnBorrowRequest request)
        {
            var response = new CommonResponse <string>();

            try
            {
                if (request == null)
                {
                    throw new BizException("参数不能为空");
                }

                var borrowRegister = await _db.BorrowRegister.FirstOrDefaultAsync(c => c.Id == request.BorrowRegisterId && !c.Deleted);

                if (borrowRegister == null)
                {
                    throw new BizException("借阅登记不存在");
                }

                if (borrowRegister.Status == BorrowRegisterStatus.Returned)
                {
                    response.Message   = "当前状态已经归还";
                    response.ErrorCode = 1;
                    response.Success   = true;
                    return(response);
                }

                if (borrowRegister.Status != BorrowRegisterStatus.Borrowed && borrowRegister.Status != BorrowRegisterStatus.Overdue && borrowRegister.Status != BorrowRegisterStatus.Renewed)
                {
                    throw new BizException("借阅登记状态为:已借出、延期、逾期 才需要归还");
                }
                borrowRegister.UpdateTime = DateTime.Now;
                borrowRegister.Status     = BorrowRegisterStatus.Returned;
                borrowRegister.UpdateTime = DateTime.Now;

                var archivesList = await _db.ArchivesInfo.Join(_db.BorrowRegisterDetail, a => a.Id, b => b.ArchivesId, (a, b) => new { a, b }).Where(j => j.b.BorrowRegisterId == borrowRegister.Id).Select(c => c.a).ToListAsync();

                archivesList.ForEach(a => a.Status = ArchivesStatus.Normal);
                await _db.SaveChangesAsync();

                response.Success = true;
            }
            catch (BizException ex)
            {
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Message = "提交续借发生异常";
                ApplicationLog.Error("ReturnArchives", ex);
            }
            return(response);
        }