54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using SchoolContracts.BindingModel;
|
|
using SchoolContracts.ViewModels;
|
|
using SchoolDataModels.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Runtime.ConstrainedExecution;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace SchoolDatabaseImplement.Models
|
|
{
|
|
public class Circle : ICircleModel
|
|
{
|
|
public int Id { get; private set; }
|
|
[Required]
|
|
public DateTime DateStart{ get; private set; } = DateTime.Now;
|
|
[Required]
|
|
public int ClientId { get; private set; }
|
|
public virtual Client Client { get; private set; } = new();
|
|
[ForeignKey("CircleId")]
|
|
public virtual CircleLesson CircleLessons { get; set; } = new();
|
|
[ForeignKey("CircleId")]
|
|
public virtual List<CircleExpense> CircleExpenses { get; set; } = new();
|
|
public static Circle Create(SchoolDatabase context, CircleBindingModel model)
|
|
{
|
|
return new Circle()
|
|
{
|
|
Id = model.Id,
|
|
DateStart = model.DateStart,
|
|
Client = context.Clients.First(x => x.Id == model.ClientId)
|
|
};
|
|
}
|
|
|
|
public void Update(CircleBindingModel model)
|
|
{
|
|
Id = model.Id;
|
|
DateStart = model.DateStart;
|
|
ClientId = model.ClientId;
|
|
}
|
|
|
|
public CircleViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
DateStart = DateStart,
|
|
ClientId = ClientId,
|
|
ClientName = Client.ClientName
|
|
};
|
|
}
|
|
}
|