Subd/SubdShoeStore/Controller.cs
2023-05-04 01:51:38 +04:00

70 lines
1.7 KiB
C#

using ConsoleTableExt;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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();
}
}
}