【问题标题】:Business Logic ASP.NET MV业务逻辑 ASP.NET MV
【发布时间】: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; }
}

【问题讨论】:

标签: c# asp.net-mvc mongodb


【解决方案1】:

您可以在模型中定义一个函数来使用 PersenTopUp 计算 JumlahTransaksi。

public double MakeSum()
{
   return PersenTopUp + JumlahTransaksi;
}

【讨论】:

  • 以及我如何在控制器中调用它?还是使用剃须刀??
  • 我认为在控制器中你将创建一个 Transaksi 类的新实例。然后您可以将 MakeSum 函数的结果保存在一个变量中,然后将此结果传递给 ViewBag 对象。您在模型中有 ViewBag 对象,因此您可以使用它:)。
  • ok,感谢 loot lucian,它可以使用存储库模式实现吗??
猜你喜欢
  • 2011-12-03
  • 2011-09-03
  • 1970-01-01
  • 2021-02-24
  • 1970-01-01
  • 2018-04-17
  • 1970-01-01
  • 1970-01-01
  • 2012-02-09
相关资源
最近更新 更多