public Chart(string path) { folderName = path; chartPath = Path.Combine(Directory.GetCurrentDirectory(), "!Content/!Songs", path); // Console.WriteLine(chartPath); chartInfo = JsonConvert.DeserializeObject <JsonChart>(File.ReadAllText(Path.Combine(chartPath, "ChartInfo.json"))); if (chartInfo.previewLength == 0) { chartInfo.previewLength = 3; } hash = Convert.ToBase64String(Program.mD5.ComputeHash(File.ReadAllBytes(Path.Combine(chartPath, "ChartInfo.json")))); }
public IActionResult _VendasJson(string json) { PaginaAdminHomeModel model; JObject o; if (json == null) { model = new PaginaAdminHomeModel(); } else { o = JObject.Parse(json); model = o.ToObject <PaginaAdminHomeModel>(); } IEnumerable <Livro> livros = _facade.ListAllInclude <Livro>(); IList <string> meses = new List <string>(); if (!String.IsNullOrEmpty(model.Nome)) { livros = livros.Where(l => l.Titulo.Contains(model.Nome)); } if (!String.IsNullOrEmpty(model.Categorias)) { string[] ctgs = model.Categorias.Split(" "); IEnumerable <CategoriaLivro> categoriaLivros = _facade.Query <CategoriaLivro>(c => ctgs.Contains(c.Nome), c => c); IEnumerable <LivroCategoriaLivro> livCtl = livros.SelectMany(c => c.LivrosCategoriaLivros); IEnumerable <int> ids = livCtl.Where(l => categoriaLivros.Select(c => c.Id).Contains(l.CategoriaLivroId)) .Select(l => l.LivroId).Distinct(); livros = livros.Where(l => ids.Contains(l.Id)); } var listaMeses = MonthsBetween(model.Comeco, model.Fim); foreach (var(Month, Year) in listaMeses) { meses.Add(Month + "/" + Year); } IEnumerable <JsonData> dados = new List <JsonData>(); IList <JsonData> listaDatasets = new List <JsonData>(); var dateTimeFormat = CultureInfo.CurrentCulture.DateTimeFormat; foreach (var livro in livros) { Random r = new Random(); string cor = "rgba(" + r.Next(0, 255) + ", " + r.Next(0, 255) + ", " + r.Next(0, 255) + ", 0.5)"; JsonData dataset = new JsonData { label = livro.Titulo, backgroundColor = cor, borderColor = cor, fill = false }; IList <int> data = new List <int>(); foreach (var(Month, Year) in listaMeses) { int contagem = livro.LivroPedidos .Where(l => (dateTimeFormat.GetMonthName(l.DtCadastro.Month) == Month && l.DtCadastro.Year == Year)) .Where(l => l.Pedido.Status == StatusPedidos.Aprovado || l.Pedido.Status == StatusPedidos.Entregue || l.Pedido.Status == StatusPedidos.EmTransito) .Count(); data.Add(contagem); } dataset.data = data.ToArray(); listaDatasets.Add(dataset); } string[] labels = meses.ToArray(); JsonData[] datasets = listaDatasets.ToArray(); JsonChart chart = new JsonChart { labels = labels, datasets = datasets }; return(Json(chart)); }