Example #1
0
 public void RemoveData()
 {
     using (var context = new PhotoStudioContext())
     {
         context.Orders.RemoveRange(context.Orders);
         context.Clients.RemoveRange(context.Clients);
         context.Options.RemoveRange(context.Options);
         context.SaveChanges();
     }
 }
Example #2
0
 public void ReadAndWriteOrders()
 {
     using (StreamReader reader = new StreamReader(OrdersFilePath))
     {
         while (!reader.EndOfStream)
         {
             string[] values = reader.ReadLine().Split(';');
             Order    order  = new Order();
             order.Client     = _newClients[Convert.ToInt32(values[0]) - 1];
             order.Option     = _newOptions[Convert.ToInt32(values[1]) - 1];
             order.Quantity   = Convert.ToInt32(values[2]);
             order.DateStart  = DateTime.Parse(values[3]);
             order.DateFinish = DateTime.Parse(values[4]);
             _newOrders.Add(order);
         }
     }
     using (var context = new PhotoStudioContext())
     {
         context.AddRange(_newOrders);
         context.SaveChanges();
     }
 }
Example #3
0
        public void PrintTables()
        {
            using (var context = new PhotoStudioContext())
            {
                var query = context.Orders
                            .Join(context.Clients, orders => orders.ClientId, clients => clients.Id,
                                  (o, c) => new { OptionId = o.OptionId, Name = c.Name, Surname = c.Surname })

                            .Join(context.Options, c => c.OptionId, o => o.Id, (c, o) => new { Option = o.Title, Name = c.Name, Surname = c.Surname })
                            .ToList()
                            .GroupBy(table => new { table.Surname, table.Name })
                            .Where(g => g.Count() >= 2);



                foreach (var element in query)
                {
                    string[] options = element.Select(q => q.Option).ToArray();

                    Console.WriteLine($"{element.Key.Name}, {element.Key.Surname}, Ordered Options: {String.Join(',', options)} " +
                                      $"Options Count: {element.Count()}");
                }
            }
        }