protected override Result UpdateValues(Sign entity, EditRuleCommandBase<Sign> command)
        {
            var c = command as EditSignCommand;

            //Синхронизируем Переменные Устава
            //if (entity.RuleDefinition != c.RuleDefinition)
            //{
                entity.RuleDefinition = c.RuleDefinition;
            //    entity.SyncRuleVariables(SerializerRoot);
            //}
            //if (entity.ModRuleDefinition != c.ModRuleDefinition)
            //{
                entity.ModRuleDefinition = c.ModRuleDefinition;
            //    entity.SyncModRuleVariables(SerializerRoot);
            //}

            //не возможно просто присвоить значение, потому как ef core 
            //будет думать, что TypiconEntity удалена
            entity.SignName.ReplaceValues(new ItemText(new ItemTextUnit(CommonConstants.DefaultLanguage, c.Name)));

            entity.TemplateId = (c.TemplateId > 0) ? c.TemplateId : null;
            entity.IsAddition = c.IsAddition;
            entity.PrintTemplateId = (c.PrintTemplateId > 0) ? c.PrintTemplateId : null;
            entity.Priority = c.Priority;

            return Result.Ok();
        }
Пример #2
0
        protected override Result UpdateValues(TriodionRule entity, EditRuleCommandBase <TriodionRule> command)
        {
            var c = command as EditTriodionRuleCommand;

            //Синхронизируем Переменные Устава
            //if (entity.RuleDefinition != c.RuleDefinition)
            //{
            entity.RuleDefinition = c.RuleDefinition;
            //    entity.SyncRuleVariables(SerializerRoot);
            //}
            //if (entity.ModRuleDefinition != c.ModRuleDefinition)
            //{
            entity.ModRuleDefinition = c.ModRuleDefinition;
            //    entity.SyncModRuleVariables(SerializerRoot);
            //}

            entity.TemplateId     = c.TemplateId;
            entity.DaysFromEaster = c.DaysFromEaster;
            entity.IsTransparent  = c.IsTransparent;

            entity.DayRuleWorships.Clear();

            foreach ((int id, int order) in c.DayWorshipIds)
            {
                entity.DayRuleWorships.Add(new DayRuleWorship()
                {
                    DayRuleId = entity.Id, DayWorshipId = id, Order = order
                });
            }

            return(Result.Ok());
        }
Пример #3
0
        protected Result Execute(EditRuleCommandBase <T> command)
        {
            var found = DbContext.Set <T>().FirstOrDefault(c => c.Id == command.Id);

            if (found == null)
            {
                return(Result.Fail($"Объект с Id {command.Id} не найден."));
            }

            var version = found.TypiconVersion;

            //можно редактировать только правила черновика
            if (!(version.BDate == null && version.EDate == null))
            {
                return(Result.Fail($"Правило относится к Версии Устава, находящейся не в статусе Черновика."));
            }

            var updResult = UpdateValues(found, command);

            if (updResult.Failure)
            {
                return(updResult);
            }

            DbContext.Set <T>().Update(found);

            found.TypiconVersion.IsModified = true;

            //await DbContext.SaveChangesAsync();

            return(Result.Ok());
        }
Пример #4
0
        protected override Result UpdateValues(TypiconVariable entity, EditRuleCommandBase <TypiconVariable> command)
        {
            var c = command as EditTypiconWorshipVariableCommand;

            //редактируем только если Устав является Шаблоном
            if (entity.TypiconVersion.IsTemplate)
            {
                entity.Header      = c.Header;
                entity.Description = c.Description;
            }

            try
            {
                var worships = JsonSerializer.Deserialize <List <WorshipModel> >(c.Value);

                var xml = "";

                if (worships.Count > 0)
                {
                    xml = SerializerRoot.TypiconSerializer
                          .Serialize(new WorshipContainer()
                    {
                        Worships = worships
                    });
                }

                entity.Value = xml;

                return(Result.Ok());
            }
            catch (Exception ex)
            {
                return(Result.Fail($"Проищла ошибка при десериализации объекта {nameof(WorshipContainer)}"));
            }
        }
Пример #5
0
        protected override Result UpdateValues(PrintDayTemplate entity, EditRuleCommandBase <PrintDayTemplate> command)
        {
            var c = command as EditPrintDayTemplateCommand;

            entity.Name   = c.Name;
            entity.Number = c.Number;
            entity.Icon   = c.Icon;
            entity.IsRed  = c.IsRed;

            if (c.PrintFile != null)
            {
                entity.PrintFile = c.PrintFile;
            }

            if (!string.IsNullOrEmpty(c.PrintFileName))
            {
                entity.PrintFileName = c.PrintFileName;
            }

            if (c.IsDefault)
            {
                entity.TypiconVersion.PrintDayDefaultTemplate = entity;
            }

            return(Result.Ok());
        }
Пример #6
0
        protected override Result UpdateValues(TypiconVariable entity, EditRuleCommandBase <TypiconVariable> command)
        {
            var c = command as EditTypiconTimeVariableCommand;

            //редактируем только если Устав является Шаблоном
            if (entity.TypiconVersion.IsTemplate)
            {
                entity.Header      = c.Header;
                entity.Description = c.Description;
            }

            entity.Value = c.Value;

            return(Result.Ok());
        }
Пример #7
0
        protected override Result UpdateValues(ExplicitAddRule entity, EditRuleCommandBase <ExplicitAddRule> command)
        {
            var c = command as EditExplicitAddRuleCommand;

            entity.Date = c.Date;

            //Синхронизируем Переменные Устава
            //if (entity.RuleDefinition != c.RuleDefinition)
            //{
            entity.RuleDefinition = c.RuleDefinition;
            //    entity.SyncRuleVariables(SerializerRoot);
            //}

            return(Result.Ok());
        }
Пример #8
0
        protected override Result UpdateValues(PrintWeekTemplate entity, EditRuleCommandBase <PrintWeekTemplate> command)
        {
            var c = command as EditPrintWeekTemplateCommand;

            entity.DaysPerPage = c.DaysPerPage;

            if (c.PrintFile != null)
            {
                entity.PrintFile = c.PrintFile;
            }

            if (!string.IsNullOrEmpty(c.PrintFileName))
            {
                entity.PrintFileName = c.PrintFileName;
            }

            return(Result.Ok());
        }
Пример #9
0
 protected abstract Result UpdateValues(T found, EditRuleCommandBase <T> command);