ISEbd-21_Tukaeva_A_A_School/School/SchoolDatabaseImplements/Models/CircleLesson.cs

52 lines
1.3 KiB
C#
Raw Normal View History

using SchoolContracts.BindingModel;
using SchoolContracts.BindingModels;
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.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
namespace SchoolDatabaseImplement.Models
{
public class CircleLesson : ICircleLessonModel
{
public int Id { get; set; }
[Required]
public int CircleId { get; set; }
[Required]
public int LessonId { get; set; }
[Required]
public int Count { get; set; }
public virtual Lesson Lesson { get; set; } = new();
public virtual Circle Circle { get; set; } = new();
[ForeignKey("CircleLessonId")]
public virtual List<Payment> Payments { get; set; } = new();
public static CircleLesson Create(SchoolDatabase context, CircleLessonBindingModel model)
{
return new CircleLesson()
{
Id = model.Id,
Circle = context.Circles.First(x => x.Id == model.CircleId),
Lesson = context.Lessons.First(x => x.Id == model.LessonId),
Count = model.Count
};
}
public void Update(CircleLessonBindingModel model)
{
Id = model.Id;
}
public CircleLessonViewModel GetViewModel => new()
{
Id = Id
};
}
}