subd/Subd/Controller.cs

76 lines
2.0 KiB
C#

using ConsoleTableExt;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Subd
{
internal class Controller
{
private readonly Onlinecinema2Context _context;
public Controller(Onlinecinema2Context feedContext)
{
_context = feedContext;
}
public void GetFilms()
{
ConsoleTableBuilder.From(_context.Films.Select(x => new { x.IdFilm, x.NameFilm, x.Genre }).ToList())
.WithTitle("Films")
.ExportAndWriteLine();
}
public void GetDirectors()
{
ConsoleTableBuilder.From(_context.Directors.Select(x => new { x.IdDirector, x.Name, x.Date }).ToList())
.WithTitle("Directors")
.ExportAndWriteLine();
}
public void GetStudios()
{
ConsoleTableBuilder.From(_context.Studios.Select(x => new { x.IdStudio, x.Name }).ToList())
.WithTitle("Studios")
.ExportAndWriteLine();
}
public void GetUsers()
{
ConsoleTableBuilder.From(_context.Users.Select(x => new { x.IdUser, x.Nikname }).ToList())
.WithTitle("Users")
.ExportAndWriteLine();
}
public void AddUser(User User)
{
try
{
_context.Users.Add(User);
_context.SaveChanges();
}
catch (Exception e)
{
Console.WriteLine(e.InnerException.Message);
}
}
public UserRating? GetReview(int IdUser, int IdFilm)
{
return _context.UserRatings.FirstOrDefault(x => x.IdUser == IdUser && x.IdFilm == IdFilm);
}
public void RemoveReview(UserRating Review)
{
_context.UserRatings.Remove(Review);
_context.SaveChanges();
}
public void UpdateReview(UserRating Review)
{
_context.SaveChanges();
}
}
}