/// <summary>
        /// 退还学生教材
        /// </summary>
        /// <param name="releaseRecordeIds"></param>
        /// <param name="studentId"></param>
        /// <returns></returns>
        public ResponseView DropStudenBookSubmit(IEnumerable <string> releaseRecordeIds, string studentId)
        {
            //数据类型转换
            Guid stID = studentId.ConvertToGuid();
            var  term = new TermAppl().GetCurrentTerm().ToString();
            //根据学生Id,发放记录Id,取该生每本教材的退还数
            var dorpBookCountForStudent = new List <StudentReleaseRecord>();

            foreach (string recordId in releaseRecordeIds)
            {
                var rId        = recordId.ConvertToGuid();
                var studentRel = _studentReleaseRecordRepo.First(s => s.Student_Id == stID && s.ID == rId);
                dorpBookCountForStudent.Add(studentRel);
            }

            //根据发放记录Id,取对应的库存变更记录Id
            var stockRecordIds = new List <StudentReleaseRecord>();

            foreach (string recordId in releaseRecordeIds)
            {
                var rId           = recordId.ConvertToGuid();
                var stockRecordId = _studentReleaseRecordRepo.First(s => s.ID == rId);

                stockRecordIds.Add(stockRecordId);
            }
            //根据库存变更记录Id,取库存Id
            var inventoryIds = new List <Domain.Models.InStockRecord>();

            foreach (StudentReleaseRecord id in stockRecordIds)
            {
                var inventoryId = _inStockRecordRepo.First(i => i.ID == id.StockRecord_Id);

                inventoryIds.Add(inventoryId);
            }

            var result             = new ResponseView();
            var message            = string.Empty;
            var messageForResponse = string.Empty;
            var releaseRecordCount = 0;

            releaseRecordCount += dorpBookCountForStudent.Count();
            var successCount = 0;

            //删除库存变记录
            foreach (StudentReleaseRecord stockRecordId in stockRecordIds)
            {
                if (stockRecordId.StockRecord_Id != null)
                {
                    var stoockRecord = Domain.ReleaseBookService.CreateStockRecord(stockRecordId.StockRecord_Id.Value);
                    _inStockRecordRepo.Remove(stoockRecord);
                    _inStockRecordRepo.Context.Commit();
                }
            }

            //修改库存数量
            foreach (InStockRecord view in inventoryIds)
            {
                var releaseCount = dorpBookCountForStudent.First(d => d.StockRecord_Id == view.ID).ReleaseCount;
                var inventory    = Domain.ReleaseBookService.CreatInventoryAtDrop(view.Inventory_Id,
                                                                                  releaseCount);
                _inventoryRepo.Modify(inventory);
                _inventoryRepo.Context.Commit();
            }

            //删除学生发放记录
            foreach (StudentReleaseRecord view in dorpBookCountForStudent)
            {
                var studentRecord =
                    Domain.ReleaseBookService.CreateStudentDropReleaseRecord(
                        view.ID, stID);
                _studentReleaseRecordRepo.Remove(studentRecord);

                _studentReleaseRecordRepo.Context.Commit();
                successCount++;
            }


            return(result);
        }
Пример #2
0
        /// <summary>
        /// 退还班级教材
        /// </summary>
        /// <param name="classId"></param>
        /// <param name="releaseRecordIds"></param>
        /// <returns></returns>
        public ResponseView DropClassBookSubmit(string classId, IEnumerable <string> releaseRecordIds)
        {
            //数据类型转换
            Guid cId  = classId.ConvertToGuid();
            var  term = new TermAppl().GetCurrentTerm().ToString();
            //根据发放记录Id,当前学期,取该班级每本教材的退还数
            var dorpBookCountForClass = new List <Domain.Models.StudentReleaseRecord>();

            foreach (string recordId in releaseRecordIds)
            {
                var rId      = recordId.ConvertToGuid();
                var classRel = _studentReleaseRecordRepo.Find(s => s.Class_Id == cId && s.ID == rId).GroupBy(s => new
                {
                    s.Textbook_Id,
                    s.ID
                }).Select(d => new StudentReleaseRecord()
                {
                    ID           = d.Key.ID,
                    Textbook_Id  = d.Key.Textbook_Id,
                    ReleaseCount = d.Sum(s => s.ReleaseCount)
                });

                dorpBookCountForClass.AddRange(classRel);
            }

            //根据发放记录Id,取对应的库存变更记录Id
            var stockRecordIds = new List <Domain.Models.StudentReleaseRecord>();

            foreach (string releaseRecordId in releaseRecordIds)
            {
                var recordId      = releaseRecordId.ConvertToGuid();
                var stockRecordId = _studentReleaseRecordRepo.First(s => s.ID == recordId);

                stockRecordIds.Add(stockRecordId);
            }
            //根据库存变更记录Id,取库存Id
            var inventoryIds = new List <Domain.Models.InStockRecord>();

            foreach (StudentReleaseRecord id in stockRecordIds)
            {
                var inventoryId = _inStockRecordRepo.First(i => i.ID == id.StockRecord_Id);

                inventoryIds.Add(inventoryId);
            }

            var result             = new ResponseView();
            var message            = string.Empty;
            var messageForResponse = string.Empty;
            var releaseRecordCount = 0;

            releaseRecordCount += releaseRecordIds.Count();
            var successCount = 0;

            //删除库存变记录
            foreach (Domain.Models.StudentReleaseRecord stockRecordId in stockRecordIds)
            {
                if (stockRecordId.StockRecord_Id != null)
                {
                    var stoockRecord = Domain.ReleaseBookService.CreateStockRecord(stockRecordId.StockRecord_Id.Value);
                    _inStockRecordRepo.Remove(stoockRecord);
                    _inStockRecordRepo.Context.Commit();
                }
            }

            //修改库存数量
            foreach (InStockRecord view in inventoryIds)
            {
                var releaseCount = dorpBookCountForClass.First(d => d.StockRecord_Id == view.ID).ReleaseCount;
                var inventory    = Domain.ReleaseBookService.CreatInventoryAtDrop(view.Inventory_Id,
                                                                                  releaseCount);
                _inventoryRepo.Modify(inventory);
                _inventoryRepo.Context.Commit();
            }

            //删除班级发放记录
            foreach (string releaseRecordId in releaseRecordIds)
            {
                var claID         = classId.ConvertToGuid();
                var studentRecord =
                    Domain.ReleaseBookService.CreateClassDropReleaseRecord(
                        releaseRecordId.ConvertToGuid(), claID);
                _studentReleaseRecordRepo.Remove(studentRecord);

                _studentReleaseRecordRepo.Context.Commit();
                successCount++;
            }


            return(result);
        }