SUBD_SushiBar/SushiBar/SushiBarMongoDB/Models/Buyer.cs

54 lines
1.3 KiB
C#
Raw Normal View History

using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
namespace SushiBarMongoDB.Models
{
public class Buyer : IBuyerModel
{
[BsonId]
[BsonElement("_id")]
public int Id { get; set; }
[BsonRequired]
public string BuyerName { get; set; } = string.Empty;
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public DateTime? BuyerBirthDate { get; set; }
public static Buyer? Create(BuyerBindingModel model)
{
if (model == null) return null;
return new Buyer()
{
Id = model.Id,
BuyerName = model.BuyerName,
BuyerBirthDate = model.BuyerBirthDate,
};
}
public void Update(BuyerBindingModel model)
{
if (model == null) return;
Id = model.Id;
BuyerName = model.BuyerName;
BuyerBirthDate = model.BuyerBirthDate;
}
public BuyerViewModel GetViewModel => new()
{
Id = Id,
BuyerName = BuyerName,
BuyerBirthDate = BuyerBirthDate,
};
}
}