示例#1
0
        public Task <Result> ExecuteAsync(ReloadRulesJob job)
        {
            _jobs.Start(job);

            var path = GetFolder();

            //находим версию Устава
            var version = _dbContext.GetTypiconVersion(job.TypiconId, job.TypiconVersionStatus);

            Result result = Result.Ok();

            Result.Combine(path, version)
            .OnSuccess(() =>
            {
                DoTheJob(path.Value, version.Value);
            })
            .OnSuccess(async() =>
            {
                await _dbContext.UpdateTypiconVersionAsync(version.Value);

                await _dbContext.ClearModifiedYearsAsync(version.Value.Id);

                await _dbContext.ClearOutputFormsAsync(version.Value.TypiconId, true);

                _jobs.Finish(job, string.Empty);
            })
            .OnFailure(err =>
            {
                _jobs.Fail(job, err);

                result = Result.Fail(err);
            });

            return(Task.FromResult(result));
        }
        protected override async Task <Result> DoTheJob(ApproveTypiconClaimJob job)
        {
            var r = _dbContext.GetTypiconClaim(job.TypiconId);

            if (r.Value is TypiconClaim claim)
            {
                if (!claim.TemplateId.HasValue)
                {
                    var err = $"Шаблон Устава не указан. Копирование Версии Устава не возможно.";

                    //SendMessage to Owner and sender

                    return(Fail(job, err));
                }
                else if (claim.Status == TypiconClaimStatus.WatingForReview)
                {
                    try
                    {
                        //TypiconClaim
                        claim.Status = TypiconClaimStatus.InProcess;

                        await _dbContext.UpdateTypiconClaimAsync(claim);

                        int templateId = claim.TemplateId.Value;

                        var version = _dbContext.GetPublishedVersion(templateId);

                        if (version.Success)
                        {
                            //TypiconVersion
                            var clone = version.Value.Clone();

                            clone.Name        = new ItemText(claim.Name);
                            clone.Description = new ItemText(claim.Description);

                            //Ставим статус "черновик"
                            clone.BDate         = null;
                            clone.VersionNumber = 1;
                            clone.TypiconId     = job.TypiconId;
                            //ставим true для возможности сразу опубликовать Устав
                            clone.IsModified = true;

                            //new TypiconEntity
                            var entity = new TypiconEntity()
                            {
                                SystemName      = claim.SystemName,
                                DefaultLanguage = claim.DefaultLanguage,
                                OwnerId         = claim.OwnerId,
                                Status          = TypiconStatus.Approving,
                                TemplateId      = claim.TemplateId
                            };
                            entity.Versions.Add(clone);
                            //добавляем Устав и его первую пустую версию
                            await _dbContext.AddTypiconEntityAsync(entity);

                            //добавляем вложенные коллекции в версию
                            version.Value.CopyChildrenTo(clone);
                            await _dbContext.UpdateTypiconVersionAsync(clone);

                            //TypiconEntity
                            entity.Status = TypiconStatus.Draft;
                            await _dbContext.UpdateTypiconEntityAsync(entity);

                            //remove claim
                            await _dbContext.RemoveTypiconClaimAsync(claim);

                            //SendMessage to Owner and sender
                            //nothing yet...

                            return(Finish(job));
                        }
                        else
                        {
                            var err = $"Указанный Устав Id={templateId} либо не существует, либо не существует его опубликованная версия.";

                            //SendMessage to Owner and sender

                            await FailClaimAsync(claim, err);

                            return(Fail(job, err));
                        }
                    }
                    catch (DbUpdateException ex)
                    {
                        await FailClaimAsync(claim, "при сохранении в БД");

                        return(Fail(job, ex.Message));
                    }
                }
                else
                {
                    var err = $"Статус Устава Id={job.TypiconId} не находится в состоянии ожидания на утверждение.";

                    await FailClaimAsync(claim, err);

                    //SendMessage to Owner and sender

                    return(Fail(job, err));
                }
            }
            else
            {
                //SendMessage to Owner and sender

                return(Fail(job, r.Error));
            };
        }
示例#3
0
        protected override async Task <Result> DoTheJob(PublishTypiconJob job)
        {
            //находим черновик
            var found = _dbContext.GetTypiconVersion(job.TypiconId, TypiconVersionStatus.Draft);

            if (found.Failure)
            {
                //TODO: SendMessage to Owner and sender

                return(Fail(job, found.Error));
            }

            var version = found.Value;

            var errMsg = version.Validate();

            if (errMsg.Count() > 0)
            {
                return(Fail(job, string.Join("", "Ошибка: ", errMsg)));
            }

            var prevStatus = version.Typicon.Status;

            //TypiconEntity
            version.Typicon.Status = TypiconStatus.Publishing;
            await _dbContext.UpdateTypiconEntityAsync(version.Typicon);

            using (var transaction = _dbContext.Database.BeginTransaction())
            {
                try
                {
                    version.IsModified = false;
                    version.ModifiedYears.Clear();

                    //new draft
                    var clone = version.Clone();
                    //задаем доп значения
                    clone.TypiconId     = job.TypiconId;
                    clone.VersionNumber = version.VersionNumber + 1;
                    clone.BDate         = null;
                    //Сохраняем, чтобы не было конфликта цикличных зависимостей
                    await _dbContext.UpdateTypiconVersionAsync(clone);

                    //копируем вложенные коллекции
                    version.CopyChildrenTo(clone);
                    //сохраняем
                    await _dbContext.UpdateTypiconVersionAsync(clone);

                    //old publish
                    var oldPublish = _dbContext.GetTypiconVersion(job.TypiconId, TypiconVersionStatus.Published);
                    if (oldPublish.Success)
                    {
                        oldPublish.Value.EDate = DateTime.Now;
                    }

                    //new publish
                    version.BDate = DateTime.Now;

                    //outputforms
                    await _dbContext.ClearOutputFormsAsync(job.TypiconId, job.DeleteModifiedOutputDays);

                    //TODO: SendMessage to Owner and sender


                    //typiconEntity
                    version.Typicon.Status = TypiconStatus.Published;

                    _dbContext.SaveChanges();

                    transaction.Commit();

                    return(Finish(job));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();

                    //version.Typicon.Status = prevStatus;
                    //version.IsModified = true;
                    await _dbContext.UpdateTypiconEntityStatusAsync(version.TypiconId, prevStatus);

                    return(Fail(job, ex.Message));
                }
            }
        }