public void DeleteAircraftPurchaseReception(AircraftPurchaseReceptionDTO dto)
 {
     if (dto == null)
     {
         throw new ArgumentException("参数为空!");
     }
     Reception delAircraftPurchaseReception = _receptionRepository.Get(dto.AircraftPurchaseReceptionId);
     //获取需要删除的对象。
     if (delAircraftPurchaseReception != null)
     {
         _receptionRepository.DeleteReception(delAircraftPurchaseReception); //删除租赁飞机接收项目。
     }
 }
        public void InsertAircraftPurchaseReception(AircraftPurchaseReceptionDTO dto)
        {
            //获取供应商
            Supplier supplier = _supplierRepository.Get(dto.SupplierId);

            //创建接机项目
            AircraftPurchaseReception newReception = ReceptionFactory.CreateAircraftPurchaseReception(dto.StartDate,
                dto.EndDate, dto.SourceId,
                dto.Description);

            // TODO:设置接机编号,如果当天的记录被删除过,流水号seq可能会重复
            DateTime date = DateTime.Now.Date;
            int seq = _receptionRepository.GetFiltered(t => t.CreateDate > date).Count() + 1;
            newReception.SetReceptionNumber(seq);

            //设置供应商
            newReception.SetSupplier(supplier);

            //设置接机的状态
            newReception.SetStatus(ReceptionStatus.开始);

            //添加接机行
            dto.ReceptionLines.ToList().ForEach(line => InsertReceptionLine(newReception, line));
            //添加相关的接机日程
            dto.ReceptionSchedules.ToList().ForEach(scheduel => InsertReceptionSchedule(newReception, scheduel));

            _receptionRepository.Add(newReception);
        }
        public void ModifyAircraftPurchaseReception(AircraftPurchaseReceptionDTO dto)
        {
            //获取供应商
            Supplier supplier = _supplierRepository.Get(dto.SupplierId);

            //获取需要更新的对象
            var updateReception = _receptionRepository.Get(dto.AircraftPurchaseReceptionId) as AircraftPurchaseReception;

            if (updateReception != null)
            {
                //更新主表:
                updateReception.SetReceptionNumber(dto.ReceptionNumber);
                updateReception.Description = dto.Description;
                updateReception.StartDate = dto.StartDate;
                updateReception.EndDate = dto.EndDate;
                updateReception.SetSupplier(supplier);
                updateReception.SetStatus((ReceptionStatus) dto.Status);
                updateReception.SourceId = dto.SourceId;

                //更新接机行:
                List<AircraftPurchaseReceptionLineDTO> dtoReceptionLines = dto.ReceptionLines;
                ICollection<ReceptionLine> receptionLines = updateReception.ReceptionLines;
                DataHelper.DetailHandle(dtoReceptionLines.ToArray(),
                    receptionLines.OfType<AircraftPurchaseReceptionLine>().ToArray(),
                    c => c.AircraftPurchaseReceptionLineId, p => p.Id,
                    i => InsertReceptionLine(updateReception, i),
                    UpdateReceptionLine,
                    d => _receptionRepository.RemoveReceptionLine(d));
                //更新交付日程:
                List<ReceptionScheduleDTO> dtoReceptionSchedules = dto.ReceptionSchedules;
                ICollection<ReceptionSchedule> receptionSchedules = updateReception.ReceptionSchedules;
                DataHelper.DetailHandle(dtoReceptionSchedules.ToArray(),
                    receptionSchedules.ToArray(),
                    c => c.ReceptionScheduleId, p => p.Id,
                    i => InsertReceptionSchedule(updateReception, i),
                    UpdateReceptionSchedule,
                    d => _receptionRepository.RemoveReceptionSchedule(d));
            }
            _receptionRepository.Modify(updateReception);
        }