static void Main(string[] args) { var context = new phone_callContext(); Console.WriteLine("\nList of 10 persons:\n"); var person = context.Person.ToList(); Console.WriteLine(string.Join("\n", person)); Console.WriteLine("\n\nList of 5 cities:\n"); var city = context.City.ToList(); Console.WriteLine(string.Join("\n", city)); Console.WriteLine("\n\nPerson made at least 2 calls to different cities:\n"); var calling = context.Person .Join(context.Calling, person => person.Id, calling => calling.Personid, (p, c) => new { PersonId = p.Id, Surname = p.Surname, Name = p.Name, FName = p.Fname, c.Personid }) .ToList() .GroupBy(table => new { table.PersonId, table.Surname, table.Name, table.FName }) .Where(g => g.Count() >= 2); foreach (var p in calling) { Console.WriteLine($"{p.Key.PersonId} {p.Key.Surname} {p.Key.Name} {p.Key.FName} " + $"Count: {p.Count()}"); } Console.ReadLine(); }
public async Task Invoke(HttpContext httpContext, phone_callContext db) { try { httpContext.Response.ContentType = "text/html; charset=utf-8"; await httpContext.Response.WriteAsync("<img src='/images/logo.png' width=100 heigh=100 alt='My image' />"); await httpContext.Response.WriteAsync("<h2>ТЕЛЕФОННІ ДЗВІНКИ</h2>"); var person = db.Person.ToList(); await httpContext.Response.WriteAsync("</br><h4>Список користувачів:</h4>"); await httpContext.Response.WriteAsync(String.Join("</br>", person)); await httpContext.Response.WriteAsync("</br></br><h4>Список 5 міст:</h4>"); var city = db.City.ToList(); await httpContext.Response.WriteAsync(string.Join("</br>", city)); await httpContext.Response.WriteAsync("</br></br><h4>Список користувачів, які здійснили хоча б 2 дзвінки в різні міста:</h4>"); var calling = db.Person .Join(db.Calling, person => person.Id, calling => calling.Personid, (p, c) => new { PersonId = p.Id, Surname = p.Surname, Name = p.Name, FName = p.Fname, c.Personid }) .ToList() .GroupBy(table => new { table.PersonId, table.Surname, table.Name, table.FName }) .Where(g => g.Count() >= 2); foreach (var p in calling) { await httpContext.Response.WriteAsync($"{p.Key.PersonId} {p.Key.Surname} {p.Key.Name} {p.Key.FName} " + $"Дзвінки: {p.Count()}</br>"); } } catch (Exception ex) { await httpContext.Response.WriteAsync($"Error: {ex.Message}"); } }
public CallingsController(phone_callContext context) { _context = context; }
public PeopleController(phone_callContext context) { _context = context; }
public CitiesController(phone_callContext context) { _context = context; }