コード例 #1
0
        public SaveResult CancelRequest(JObject saveBundle)
        {
            var transactionSettings = new TransactionSettings()
            {
                TransactionType = TransactionType.DbTransaction
            };

            _context.BeforeSaveEntitiesDelegate = (saveMap) =>
            {
                var entityInfos = saveMap.Where(e => e.Key == typeof(Request)).Select(e => e.Value).FirstOrDefault();

                if (entityInfos != null)
                {
                    foreach (EntityInfo entityInfo in entityInfos)
                    {
                        entityInfo.EntityState = EntityState.Modified;

                        Request request = (Request)entityInfo.Entity;
                        request.StatusId = _context.Session.Query <Status>().Where(p => p.Code == (string)_context.SaveOptions.Tag).Select(p => p.Id).First();
                        request.IsFirstAssessmentDone  = null;
                        request.IsSecondAssessmentDone = null;

                        RequestBL requestBL = new RequestBL(_context.Session, _logger);
                        requestBL.CancelRunningWorkflows(request);
                        requestBL.ResetAllVolumes(request);

                        //add modified jobs to savemap
                        IQueryable <Job> sourceMaterialJobs = _context.Session.Query <SourceMaterial>().Where(sm => sm.Request == request).SelectMany(sm => sm.Jobs);
                        foreach (Job job in sourceMaterialJobs)
                        {
                            job.LTSVolume = 0;
                            saveMap.AddCustomEntity(job, _context);
                        }
                    }
                }

                return(saveMap);
            };

            _context.AfterSaveEntitiesDelegate = (saveMap, result) => { };

            return(_context.SaveChanges(saveBundle, transactionSettings));
        }