diff --git a/SubdShoeStore/Controller.cs b/SubdShoeStore/Controller.cs index 6f69b6b..ec2ee0b 100644 --- a/SubdShoeStore/Controller.cs +++ b/SubdShoeStore/Controller.cs @@ -1,4 +1,5 @@ -using System; +using ConsoleTableExt; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +9,61 @@ namespace SubdShoeStore { internal class Controller { + private readonly Shoestorelab5Context _context; + + public Controller(Shoestorelab5Context scheduleContext) + { + _context = scheduleContext; + } + + public void GetConsignment() + { + ConsoleTableBuilder.From(_context.Consignments.Select(x => new { x.Consignmentid, x.Size, x.Amount, x.EnterDate, x.Rangeid }).ToList()) + .WithTitle("Consignments") + .ExportAndWriteLine(); + } + public void GetRange() + { + ConsoleTableBuilder.From(_context.Ranges.Select(x => new { x.Rangeid, x.Shoename, x.Mfr, x.Price }).ToList()) + .WithTitle("Ranges") + .ExportAndWriteLine(); + } + public void GetSeller() + { + ConsoleTableBuilder.From(_context.Sellers.Select(x => new { x.Sellerid, x.Surname, x.Name, x.PhoneNumber }).ToList()) + .WithTitle("Sellers") + .ExportAndWriteLine(); + } + public void GetSelling() + { + ConsoleTableBuilder.From(_context.Sellings.Select(x => new { x.Sellingid, x.Sellerid, x.Consignmentid, x.SellDate }).ToList()) + .WithTitle("Sellings") + .ExportAndWriteLine(); + } + public void AddRange(Range range) + { + try + { + _context.Ranges.Add(range); + _context.SaveChanges(); + } + catch (Exception e) + { + Console.WriteLine(e.InnerException.Message); + } + } + public void RemoveFromRange(Range range) + { + _context.Ranges.Remove(range); + _context.SaveChanges(); + } + public Range? GetRange(int rangeId) + { + return _context.Ranges.FirstOrDefault(x => x.Rangeid == rangeId); + } + public void UpdateRange(Range range) + { + _context.SaveChanges(); + } } }