【发布时间】:2016-04-10 17:16:02
【问题描述】:
我需要一些帮助。我有一个名为Transaction 的模型类,我想用PersenTopUp 计算JumlahTransaksi,我应该把计算的函数放在哪里?在模型中还是在控制器中?
public class Transaksi
{
public Transaksi()
{
Members = new Member();
Groups = new Group();
Profits = new Profit();
Level = new Level();
JenisTransaksi = new JenisTransaksi();
}
[BsonId]
public string Id { get; set; }
public Member Members { get; set; }
public Group Groups { get; set; }
public int NoTransaksi { get; set; }
[BsonRepresentation(MongoDB.Bson.BsonType.Double)]
public double BatasTransaksi { get; set; }
[BsonRepresentation(BsonType.String)]
public JenisTransaksi JenisTransaksi { get; set; }
[BsonRepresentation(BsonType.Double)]
public double PersenTopUp
{
get;
set;
}
[BsonRepresentation(BsonType.Double)]
public double PersenRef
{
get;
set;
}
[BsonRepresentation(BsonType.Double)]
public double JumlahTransaksi { get; set; }
[BsonDateTimeOptions(Kind = DateTimeKind.Local, DateOnly = true)]
public DateTime TanggalTransaksi { get; set; }
[BsonDateTimeOptions(Kind = DateTimeKind.Local, DateOnly = true)]
public DateTime TglJatuhTempo
{
get
{
return (this.TanggalTransaksi.AddYears(1));
}
}
// Setiap member memiliki list profit
public Profit Profits { get; set; }
[BsonRepresentation(BsonType.String)]
public Level Level { get; set; }
[BsonRepresentation(BsonType.String)]
public StatusTransaksi StatusTransaksi;
[BsonRepresentation(MongoDB.Bson.BsonType.String)]
public string Keterangan { get; set; }
[BsonDateTimeOptions(Kind = DateTimeKind.Local, DateOnly = true)]
public DateTime TerakhirDiubah { get; set; }
}
【问题讨论】:
-
您的问题是基于意见的,请查看Rich vs Anemic domain model。 DDD 偏爱富域模型(这意味着行为应该在模型中),请参阅Martin Fowler's post 的主题。
标签: c# asp.net-mvc mongodb