Exemple #1
0
        public async Task ExecuteAsync(string[] args)
        {
            if (args.Length < 2)
            {
                throw new ArgumentException("Not enough args.");
            }

            var contentArgs = new ContentArgs
            {
                Release     = _DateTimeProvider.Snapshot,
                ContentType = ParseContentType(args[0]),
                Json        = File.ReadAllText(args[1])
            };

            if (!_Validator.IsValid(contentArgs))
            {
                throw new InvalidOperationException("Content not valid.");
            }

            _Logger.WriteStartWriting(contentArgs.ContentType);

            _ContentDbContext.BeginTransaction();
            await _InsertDbCommand.ExecuteAsync(contentArgs);

            _ContentDbContext.SaveAndCommit();

            _Logger.WriteFinishedWriting(contentArgs.ContentType);
        }
        public async Task <IActionResult> PostContent([FromForm] ContentArgs contentArgs)
        {
            if (!_Validator.IsValid(contentArgs))
            {
                return(BadRequest("Invalid Json"));
            }

            using var tx = _Context.Database.BeginTransaction();
            await _InsertDbCommand.Execute(contentArgs);

            _Context.SaveAndCommit();

            return(new OkObjectResult(contentArgs));
        }
        private async Task Write(string type, string resource)
        {
            var rcd  = ReadFromResource(resource);
            var args = new ContentArgs
            {
                Release     = _DateTimeProvider.Snapshot,
                ContentType = type,
                Json        = rcd
            };

            if (!_Validator.IsValid(args))
            {
                throw new InvalidOperationException();
            }
            await _InsertDbCommand.Execute(args);
        }