示例#1
0
        public static async Task <Result> TryAddOrEditAsync(ZvsContext context, ProgramOption programOption, CancellationToken cancellationToken)
        {
            if (programOption == null)
            {
                throw new ArgumentNullException(nameof(programOption));
            }

            var existingOption = await context.ProgramOptions.FirstOrDefaultAsync(o => o.UniqueIdentifier == programOption.UniqueIdentifier, cancellationToken);

            var changed = false;

            if (existingOption == null)
            {
                context.ProgramOptions.Add(programOption);
                changed = true;
            }
            else
            {
                if (existingOption.Value != programOption.Value)
                {
                    changed = true;
                    existingOption.Value = programOption.Value;
                }
            }

            if (changed)
            {
                return(await context.TrySaveChangesAsync(cancellationToken));
            }

            return(Result.ReportSuccess());
        }
        public static async Task<Result> TryAddOrEditAsync(ZvsContext context, ProgramOption programOption, CancellationToken cancellationToken)
        {
            if (programOption == null)
                throw new ArgumentNullException("programOption");

            var existingOption = await context.ProgramOptions.FirstOrDefaultAsync(o => o.UniqueIdentifier == programOption.UniqueIdentifier, cancellationToken);

            var changed = false;

            if (existingOption == null)
            {
                context.ProgramOptions.Add(programOption);
                changed = true;
            }
            else
            {
                if (existingOption.Value != programOption.Value)
                {
                    changed = true;
                    existingOption.Value = programOption.Value;
                }
            }

            if (changed)
                return await context.TrySaveChangesAsync(cancellationToken);

            return Result.ReportSuccess();
        }