2024-04-19 19:30:16 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UniversityContracts.BindingModels;
|
|
|
|
|
using UniversityContracts.ViewModels;
|
|
|
|
|
using UniversityDataModels.Models;
|
|
|
|
|
|
|
|
|
|
namespace UniversityDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Statement : IStatementModel
|
|
|
|
|
{
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
[Required]
|
2024-04-29 22:15:15 +04:00
|
|
|
|
public int UserId { get; private set; }
|
|
|
|
|
[Required]
|
2024-04-19 19:30:16 +04:00
|
|
|
|
public int TeacherId { get; private set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public string Name { get; private set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
public DateTime Date { get; private set; }
|
2024-04-29 22:15:15 +04:00
|
|
|
|
public virtual User User { get; set; } = new ();
|
2024-04-19 19:30:16 +04:00
|
|
|
|
public virtual Teacher Teacher { get; set; } = new ();
|
2024-05-27 23:18:20 +04:00
|
|
|
|
public static Statement? Create(UniversityDatabase context, StatementBindingModel model)
|
2024-04-19 19:30:16 +04:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new Statement()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
2024-04-29 22:15:15 +04:00
|
|
|
|
UserId = model.UserId,
|
2024-05-27 23:18:20 +04:00
|
|
|
|
User = context.Users.First(x => x.Id == model.UserId),
|
2024-04-19 19:30:16 +04:00
|
|
|
|
TeacherId = model.TeacherId,
|
2024-05-27 23:18:20 +04:00
|
|
|
|
Teacher = context.Teachers.First(x => x.Id == model.TeacherId),
|
2024-04-19 19:30:16 +04:00
|
|
|
|
Name = model.Name,
|
|
|
|
|
Date = model.Date,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public static Statement Create(StatementViewModel model)
|
|
|
|
|
{
|
|
|
|
|
return new Statement()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
2024-04-29 22:15:15 +04:00
|
|
|
|
UserId = model.UserId,
|
2024-04-19 19:30:16 +04:00
|
|
|
|
TeacherId = model.TeacherId,
|
|
|
|
|
Name = model.Name,
|
|
|
|
|
Date = model.Date,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public void Update(StatementBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Id = model.Id;
|
2024-04-29 22:15:15 +04:00
|
|
|
|
UserId = model.UserId;
|
2024-04-19 19:30:16 +04:00
|
|
|
|
TeacherId = model.Id;
|
|
|
|
|
Name = model.Name;
|
|
|
|
|
Date = model.Date;
|
|
|
|
|
}
|
|
|
|
|
public StatementViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
2024-04-29 22:15:15 +04:00
|
|
|
|
UserId = UserId,
|
2024-04-19 19:30:16 +04:00
|
|
|
|
TeacherId = TeacherId,
|
2024-05-27 23:22:44 +04:00
|
|
|
|
TeacherName = Teacher.Name,
|
2024-04-19 19:30:16 +04:00
|
|
|
|
Name = Name,
|
|
|
|
|
Date = Date,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|