0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【保険商品管理システムの開発】生命保険のModelsを作成

Posted at

保険契約モデル

Models/InsurancePolicy.cs
namespace InsuranceApp.Models
{
    /// <summary>
    /// 保険契約モデル
    /// </summary>
    public class InsurancePolicy
    {
        public string PolicyId { get; set; }      // 契約ID
        public string CustomerId { get; set; }    // 契約者ID
        public string PlanName { get; set; }      // 商品名
        public decimal Premium { get; set; }      // 保険料(月額)
        public decimal CoverageAmount { get; set; } // 保険金額
        public DateTime StartDate { get; set; }   // 契約開始日
        public DateTime EndDate { get; set; }     // 契約終了日
        public bool IsActive { get; set; }        // 契約有効フラグ

        /// <summary>
        /// 満期かどうかを判定
        /// </summary>
        public bool IsExpired() => DateTime.Now > EndDate;
    }
}

IsExpired は「今日が有効期限を過ぎているか」を判定するプロパティです。
例:
• 今日 = 2025-08-18, 期限 = 2025-08-17 → IsExpired = true
• 今日 = 2025-08-18, 期限 = 2025-08-18 → IsExpired = false(同日なのでセーフ)

顧客情報モデル

Models/Customer.cs
namespace InsuranceApp.Models
{
    /// <summary>
    /// 顧客情報モデル
    /// </summary>
    public class Customer
    {
        public string CustomerId { get; set; }
        public string Name { get; set; }
        public DateTime BirthDate { get; set; }
        public string Email { get; set; }

        /// <summary>
        /// 年齢を計算
        /// </summary>
        public int GetAge()
        {
            var today = DateTime.Today;
            int age = today.Year - BirthDate.Year;
            if (BirthDate.Date > today.AddYears(-age)) age--;
            return age;
        }
    }
}

誕生日がまだ来ていなければ1歳分引く処理

if (BirthDate.Date > today.AddYears(-age)) age--;

例:
• 今日が 2025/08/18
• 生年月日が 2000/12/01

age = 2025 - 2000;  // 25歳 (仮)

次に判定👇

today.AddYears(-age)  2025/08/18 - 25 = 2000/08/18

比較すると:
• BirthDate = 2000/12/01
• 2000/12/01 > 2000/08/18 → true

つまり「誕生日(12/01)がまだ来ていない」ので age–;
→ 実際の年齢 = 24歳 🎯

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?