public void Add(ProjectMasterDto dto) { Check(dto); if (dto.CreateFileId <= 0) { throw new LogicException("立项目文件为空"); } if (dto.CompanyId <= 0) { throw new LogicException("公司爲空"); } Supplier supplier = repository.GetSupplier(dto.CompanyId); if (supplier == null) { throw new LogicException("選擇的公司無效"); } if (!supplier.IsCompany || string.IsNullOrEmpty(supplier.Code)) { throw new LogicException("選擇的公司無效"); } ProjectMaster entity = dto.ProjectedAs <ProjectMaster>(); if (entity.BeginDate.HasValue && entity.EndDate.HasValue && entity.EndDate < entity.BeginDate) { throw new LogicException("實際開始日期不能大於實際結束日期"); } if (entity.EstimatedBeginDate.HasValue && entity.EstimatedEndDate.HasValue && entity.EstimatedEndDate < entity.EstimatedBeginDate) { throw new LogicException("評估開始日期不能大於評估結束日期"); } ProjectAboutFile savefile = repository.GetFile(dto.CreateFileId); if (savefile == null) { throw new LogicException("立项目文件不存在"); } entity.Code = serialNumberProvider.Dequeue(supplier); if (string.IsNullOrEmpty(entity.Code)) { throw new LogicException("生成項目編號失敗"); } var path = Path.Combine("project", entity.Code, savefile.FileType.GetHashCode().ToString(), Bounded.Generator.New() + savefile.FileName); fileStorageServie.Move(savefile.StoragePath, path); savefile.StoragePath = path; savefile.ProjectId = entity.ID; savefile.FileType = ProjectFileType.Create; entity.State = CommonState.Enabled; entity.Created(this); var standingbook = new ProjectStandingbook(); standingbook.ProjectId = entity.ID; standingbook.Created(this); var targetCost = new ProjectTargetCost(); targetCost.ProjectId = entity.ID; targetCost.Created(this); var calculation = new ProjectCalculation(); calculation.ProjectId = entity.ID; calculation.Created(this); repository.AddMaster(entity); repository.AddCalculation(calculation); repository.AddStandingbook(standingbook); repository.AddTargetCost(targetCost); repository.Update(savefile); repository.UnitOfWork.Commit(); }