/// <inheritdoc /> public int Update(IRequest <OutputFormat> request) { var count = 1; request.GetInputEntities().ForEach(entity => { var dbEntity = DbOutputFormat.GetByName(entity.Name); if (dbEntity == null) { return; } Db.TransactAsync(() => { count += 1; dbEntity.IsDefault = entity.IsDefault; if (entity.IsBuiltIn) { return; } dbEntity.RegularPattern = entity.Pattern; }); }); DbOutputFormat.Init(); return(count); }
/// <inheritdoc /> public IEnumerable <OutputFormat> Select(IRequest <OutputFormat> request) { DbOutputFormat.Init(); return(DbOutputFormat.GetAll() .Select(f => new OutputFormat { Name = f.Name, Pattern = f.RegularPattern, IsDefault = f.IsDefault, Example = JToken.Parse(f.RegularPattern.Replace("$data", ExampleArray.ToString())) }) .Where(request.Conditions)); }
/// <inheritdoc /> public int Delete(IRequest <OutputFormat> request) { var count = 0; request.GetInputEntities().ForEach(entity => { if (entity.IsBuiltIn) { return; } Db.TransactAsync(DbOutputFormat.GetByName(entity.Name).Delete); count += 1; }); return(count); }
/// <inheritdoc /> public int Insert(IRequest <OutputFormat> request) { var count = 0; foreach (var entity in request.GetInputEntities()) { if (DbOutputFormat.GetByName(entity.Name) != null) { throw new Exception($"Invalid name. '{entity.Name}' is already in use."); } Db.TransactAsync(() => new DbOutputFormat { Name = entity.Name, RegularPattern = entity.Pattern }); count += 1; } return(count); }