63 lines
1.6 KiB
C#
63 lines
1.6 KiB
C#
using SchoolContracts.BindingModel;
|
|
using SchoolContracts.ViewModels;
|
|
using SchoolDataModels.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SchoolDatabaseImplement.Models
|
|
{
|
|
public class Lesson : ILessonModel
|
|
{
|
|
public int Id { get; private set; }
|
|
[Required]
|
|
public string LessonName { get; private set; } = string.Empty;
|
|
[Required]
|
|
public int LessonPrice { get; private set; }
|
|
[Required]
|
|
public int EmployeeId { get; private set; }
|
|
public virtual Employee Employee { get; private set; } = new();
|
|
[ForeignKey("LessonId")]
|
|
public virtual List<CircleLesson> CircleLessons { get; set; } = new();
|
|
[ForeignKey("LessonId")]
|
|
public virtual List<Payment> Payments { get; set; } = new();
|
|
public static Lesson? Create(SchoolDatabase context, LessonBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Lesson()
|
|
{
|
|
Id = model.Id,
|
|
LessonName = model.LessonName,
|
|
LessonPrice = model.LessonPrice,
|
|
Employee = context.Employees.First(x => x.Id == model.EmployeeId),
|
|
EmployeeId = model.EmployeeId
|
|
};
|
|
}
|
|
public void Update(LessonBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
LessonName = model.LessonName;
|
|
LessonPrice = model.LessonPrice;
|
|
EmployeeId = model.EmployeeId;
|
|
}
|
|
public LessonViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
LessonName = LessonName,
|
|
LessonPrice = LessonPrice,
|
|
EmployeeId = EmployeeId
|
|
};
|
|
}
|
|
}
|