jibai-kia / ICT2106_P1-6

0 stars 0 forks source link

Implementation of Reward and IReward #43

Closed jibai-kia closed 1 year ago

jibai-kia commented 1 year ago

This thread provides updates related to Reward and IReward

jibai-kia commented 1 year ago

Reward.cs

// Reward.cs
using System.ComponentModel.DataAnnotations;
namespace CleanBrightCompany.Domain
{
    public class Reward : IReward
    {
        private int _id;
        private string _name = string.Empty;
        private string _description = string.Empty;

        [Key]
        public int Id
        {
            get => GetId();
            set => SetId(value);
        }

        public string Name
        {
            get => GetName();
            set => SetName(value);
        }

        public string Description
        {
            get => GetDescription();
            set => SetDescription(value);
        }

        public Reward() { }

        public Reward(int id, string name, string description, int pointValue)
        {
            SetId(id);
            SetName(name);
            SetDescription(description);
        }

        public int GetId()
        {
            return _id;
        }

        public void SetId(int id)
        {
            if (id < 0)
            {
                throw new ArgumentException("Reward id cannot be negative.");
            }

            _id = id;
        }

        public string GetName()
        {
            return _name;
        }

        public void SetName(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Reward name cannot be null or empty.");
            }

            _name = name.Trim();
        }

        public string GetDescription()
        {
            return _description;
        }

        public void SetDescription(string description)
        {
            if (string.IsNullOrWhiteSpace(description))
            {
                throw new ArgumentException("Reward description cannot be null or empty.");
            }

            _description = description.Trim();
        }
    }
}
jibai-kia commented 1 year ago

IReward.cs

// IReward.cs
namespace CleanBrightCompany.Domain
{
    public interface IReward
    {
        public int GetId();

        public void SetId(int id);

        public string GetName();

        public void SetName(string name);

        public string GetDescription();

        public void SetDescription(string description);
    }
}
jibai-kia commented 1 year ago

Explanation

The Reward class represents a reward object and has the following properties and methods:

Properties:

Methods:

Overall, the Reward class provides basic validation for its properties and can be used to create, read, update, and delete rewards in the system.

jibai-kia commented 1 year ago

Explanation

The IReward.cs file defines an interface IReward that contains the basic properties and methods for a Reward object.

Interfaces are used to define a contract that a class must implement. In this case, any class that wants to be considered a Reward must implement the IReward interface, which requires it to have Id, Name, and Description properties, and GetId(), SetId(), GetName(), SetName(), GetDescription(), and SetDescription() methods.

This allows other parts of the code, such as the RewardService or the RewardRepository, to interact with Reward objects through the IReward interface, without having to know the specific implementation of the Reward class.