71 lines
1.7 KiB
C#
71 lines
1.7 KiB
C#
|
using SchoolContracts.BindingModel;
|
|||
|
using SchoolContracts.ViewModels;
|
|||
|
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
|
|||
|
{
|
|||
|
public int Id { get; private set; }
|
|||
|
[Required]
|
|||
|
public string LessonName { get; private set; } = string.Empty;
|
|||
|
[Required]
|
|||
|
public double 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)
|
|||
|
};
|
|||
|
}
|
|||
|
public static Lesson Create(LessonViewModel model)
|
|||
|
{
|
|||
|
return new Lesson
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
LessonName = model.LessonName,
|
|||
|
LessonPrice = model.LessonPrice,
|
|||
|
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
|
|||
|
};
|
|||
|
}
|
|||
|
}
|