2024-04-02 02:15:17 +04:00
|
|
|
|
using RouteGuideContracts.BindingModels;
|
|
|
|
|
using RouteGuideContracts.ViewModels;
|
|
|
|
|
using RouteGuideDataModels.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 RouteGuideDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сущность "Расписание"
|
|
|
|
|
/// </summary>
|
2024-04-23 19:38:25 +04:00
|
|
|
|
public class Schedule : IScheduleModel<int>
|
2024-04-02 02:15:17 +04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Идентификатор
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Дата записи расписания
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Required]
|
|
|
|
|
public DateTime Date { get; private set; } = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Время отправления
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Required]
|
|
|
|
|
public DateTime DepartureTime { get; private set; } = DateTime.MinValue;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Время прибытия
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Required]
|
|
|
|
|
public DateTime ArrivalTime { get; private set; } = DateTime.MinValue;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Периодичность движения транспорта
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Required]
|
|
|
|
|
public DateTime Frequency { get; private set; } = DateTime.MinValue;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Идентификатор маршрута
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ForeignKey("RouteId")]
|
|
|
|
|
public int RouteId { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сущность "Маршрут"
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual Route Route { get; private set; } = new();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание модели
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static Schedule? Create(RouteGuideDatabase context, ScheduleBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Schedule()
|
|
|
|
|
{
|
2024-04-23 19:38:25 +04:00
|
|
|
|
Id = (int)model.Id,
|
2024-04-02 02:15:17 +04:00
|
|
|
|
Date = model.Date,
|
|
|
|
|
DepartureTime = model.DepartureTime,
|
|
|
|
|
ArrivalTime = model.ArrivalTime,
|
|
|
|
|
Frequency = model.Frequency,
|
2024-04-23 19:38:25 +04:00
|
|
|
|
RouteId = (int)model.RouteId,
|
2024-04-02 02:15:17 +04:00
|
|
|
|
Route = context.Routes
|
2024-04-23 19:38:25 +04:00
|
|
|
|
.FirstOrDefault(x => x.Id.Equals(model.RouteId))
|
2024-04-02 02:15:17 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменение модели
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
public void Update(ScheduleBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Date = model.Date;
|
|
|
|
|
DepartureTime = model.DepartureTime;
|
|
|
|
|
ArrivalTime = model.ArrivalTime;
|
|
|
|
|
Frequency = model.Frequency;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение модели
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ScheduleViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
Date = Date,
|
|
|
|
|
DepartureTime = DepartureTime,
|
|
|
|
|
ArrivalTime = ArrivalTime,
|
|
|
|
|
Frequency = Frequency,
|
2024-04-05 02:48:52 +04:00
|
|
|
|
RouteId = RouteId,
|
|
|
|
|
RouteName = Route.Name
|
2024-04-02 02:15:17 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|