78 lines
1.8 KiB
C#
78 lines
1.8 KiB
C#
|
using CarRentContracts.BindingModels;
|
|||
|
using CarRentContracts.BusinessLogicContracts;
|
|||
|
using CarRentContracts.ViewModels;
|
|||
|
using CarRentDataModels.Models;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel.DataAnnotations;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace CarRentDatabase.Models
|
|||
|
{
|
|||
|
public class Rental : IRentalModel
|
|||
|
{
|
|||
|
[Required]
|
|||
|
public DateTime StartDate { get; set; }
|
|||
|
[Required]
|
|||
|
public DateTime? EndDate { get; set; }
|
|||
|
[Required]
|
|||
|
public double RentalCost { get; set; }
|
|||
|
public string? ReviewText { get; set; }
|
|||
|
public int? ReviewRating { get ; set; }
|
|||
|
[Required]
|
|||
|
public int ClientId { get; set; }
|
|||
|
[Required]
|
|||
|
public int CarId { get; set; }
|
|||
|
|
|||
|
public int Id { get; private set; }
|
|||
|
|
|||
|
public virtual Car Car { get; set; }
|
|||
|
public virtual Client Client { get; set; }
|
|||
|
|
|||
|
public static Rental? Create(RentalBindingModel? model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new Rental()
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
StartDate = model.StartDate,
|
|||
|
EndDate = model.EndDate,
|
|||
|
RentalCost = model.RentalCost,
|
|||
|
ReviewText = model.ReviewText,
|
|||
|
ReviewRating = model.ReviewRating,
|
|||
|
CarId = model.CarId,
|
|||
|
ClientId = model.ClientId,
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public void Update(RentalBindingModel? model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
ReviewText = model.ReviewText;
|
|||
|
ReviewRating = model.ReviewRating;
|
|||
|
}
|
|||
|
|
|||
|
public RentalViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
ClientName = Client == null ? string.Empty : Client.Name,
|
|||
|
ClientSurname = Client == null ? string.Empty : Client.Surname,
|
|||
|
StartDate = StartDate,
|
|||
|
EndDate = EndDate,
|
|||
|
RentalCost = RentalCost,
|
|||
|
ReviewText = ReviewText,
|
|||
|
ReviewRating = ReviewRating,
|
|||
|
ClientId = ClientId,
|
|||
|
CarId = CarId,
|
|||
|
};
|
|||
|
}
|
|||
|
}
|