public RIFileModel CreateFileInfo(RIFileModel cplnRI, out string docId)
 {
     if (string.IsNullOrEmpty(cplnRI.Path))
     {
         throw new RequestErrorException("RlFile File is null");
     }
     if (string.IsNullOrEmpty(cplnRI.Title))
     {
         throw new RequestErrorException("RlFile title cannot be empty");
     }
     if (string.IsNullOrEmpty(cplnRI.Content))
     {
         cplnRI.Content = "";
     }
     if (string.IsNullOrEmpty(cplnRI.DocumentID))
     {
         throw new RequestErrorException("RlFile DocumentID is null");
     }
     return(_iRlFileDataProvider.CreateFileInfo(cplnRI, out docId));
 }
Esempio n. 2
0
        public RIRecordModel CreateRecord(RIRecordModel _model)
        {
            if (_model == null)
            {
                throw new RequestErrorException("-1001");//create record failed
            }
            if (_model.PackageID == null || _model.Topic == null || _model.SubTopic == null)
            {
                throw new RequestErrorException("-1000");//please select catagory
            }
            if (string.IsNullOrEmpty(_model.Author))
            {
                throw new RequestErrorException("Please fill the author");//Please fill the author
            }
            if (_model.Author.Length > 50)
            {
                throw new RequestErrorException("Author is too long");//Please fill the author
            }
            if (_lnRIRecordDataProvider.ExistsRecordTitle(_model.Title))
            {
                throw new RequestErrorException("Please use another title");//already exist title
            }
            _model.DocID         = this.GetMaxId().ToString();
            _model.EntityID      = (Convert.ToInt64(_model.DocID) - 1).ToString();
            _model.Version       = 1;
            _model.IsLatest      = true;
            _model.CREATETIME    = DateTime.Now;
            _model.UPDATETIME    = DateTime.Now;
            _model.EffectiveDate = DateTime.Now;
            _model.Path          = _xmlDBSavePath + "crcd" + "/" + (Convert.ToInt64(_model.DocID) - 1).ToString() + "_1.XML";
            _model.MetaPath      = _xmlDBSavePath + "crcd" + "/" + (Convert.ToInt64(_model.DocID) - 1).ToString() + "_1_META.XML";

            lnRIRecord.repo.BeginTransaction();

            try
            {
                //var saveResult = _recordService.AddRecord(model);
                var _saveResult = AddRecord(_model, new LnRIRecordEntityModel()
                {
                    EntityID = _model.EntityID, CreateTime = DateTime.Now, LatestDocID = _model.DocID, Title = _model.Title, Updatetime = DateTime.Now
                });
                if (_saveResult == null)
                {
                    throw new RequestErrorException("-1001");//create record failed
                }

                List <RICheckItemModel> _rr1 = new List <RICheckItemModel>();
                if (_model.CheckItem != null && _model.CheckItem.Count > 0)
                {
                    _model.CheckItem.ForEach(o =>
                    {
                        o.ParentRecordId = _saveResult.DocID;
                    });

                    _rr1 = CreateCheckItem(_model.CheckItem, new List <RICheckItemModel>()
                    {
                    }, _model.DocID);
                    _model.CheckItem = _rr1;
                }

                MaintainRIRelRecordCheckItem(_rr1, _model.DocID);
                lnRIRecord.repo.CompleteTransaction();
                try
                {
                    if (_model.CheckFiles != null && _model.CheckFiles.Count > 0)
                    {
                        foreach (var fileDoc in _model.CheckFiles)
                        {
                            RIFileModel _newFile = new RIFileModel();
                            string      _docid   = "";
                            var         _OldFile = _fileService.GetFileBydocId(fileDoc);
                            _newFile            = _OldFile;
                            _newFile.DocID      = System.Guid.NewGuid().ToString("N");
                            _newFile.DocumentID = _model.DocID;
                            _newFile.CreateUser = new HttpContextWrapper(HttpContext.Current).User.Identity.Name;
                            var retFile = _iRlFileDataProvider.CreateFileInfo(_newFile, out _docid);
                        }
                        //_fileService.UpdateFilesByDocumentId(_r1new.CheckFiles, _r1new.DocID);
                    }
                }
                catch (Exception ex)
                {
                    throw new RequestErrorException(ex.Message + "__db for error");
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error <lnRIRecordService>("CreateRecord Failed! \n", ex);
                lnRIRecord.repo.AbortTransaction();
                throw new RequestErrorException("CreateRecord Failed! No XML generated " + ex.Message);//create record failed
            }
            var _r = _mapperService.MapModel <RIRecordModel>(_model);

            //生成XML
            ToXml(_r);

            return(_model);
        }