public IActionResult GetPartFromTypeAndRole( [FromRoute] string database, [FromRoute] string id, [FromRoute] string type, [FromRoute] string role) { ICadmusRepository repository = _repositoryProvider.CreateRepository(database); IPart part = repository.GetItemParts(new[] { id }, type == "any" ? null : type, role == "default" ? null : role) .FirstOrDefault(); if (part == null) { return(NotFound()); } string json = repository.GetPartContent(part.Id); if (json == null) { return(new NotFoundResult()); } json = AdjustPartJson(json); object result = JsonConvert.DeserializeObject(json); return(Ok(result)); }
public IActionResult GetPart( [FromRoute] string database, [FromRoute] string id) { ICadmusRepository repository = _repositoryProvider.CreateRepository(database); string json = repository.GetPartContent(id); if (json == null) { return(new NotFoundResult()); } json = AdjustPartJson(json); object part = JsonConvert.DeserializeObject(json); return(Ok(part)); }
public IActionResult GetPartPins( [FromRoute] string database, [FromRoute] string id) { ICadmusRepository repository = _repositoryProvider.CreateRepository(database); string json = repository.GetPartContent(id); if (json == null) { return(new NotFoundResult()); } // remove ISODate(...) function (this seems to be a Mongo artifact) json = Regex.Replace(json, @"ISODate\(([^)]+)\)", "$1"); // Pascal-case properties json = _camelPropRegex.Replace(json, m => $"\"{m.Groups[1].Value.ToUpperInvariant()}{m.Groups[2].Value}\":"); Match typeMatch = Regex.Match(json, "\"TypeId\":\\s*\"([^\"]+)\""); if (!typeMatch.Success) { return(NotFound()); } Match roleMatch = Regex.Match(json, "\"RoleId\":\\s*\"([^\"]+)\""); string role = roleMatch.Success ? roleMatch.Groups[1].Value : null; IPartTypeProvider provider = _repositoryProvider.GetPartTypeProvider(); Type t = provider.Get(typeMatch.Groups[1].Value); IPart part = (IPart)JsonConvert.DeserializeObject(json, t); var result = (from p in part.GetDataPins() select new { p.Name, p.Value }).ToList(); return(Ok(result)); }