Exemplo n.º 1
0
        public void AddSubject(Name subjectName)
        {
            if (Subjects.Any(s => s.Name == subjectName))
            {
                throw DomainException.With($"SubjectName '{subjectName}' already exists in this unit.");
            }

            _subjects.Add(new Subject(subjectName));
        }
Exemplo n.º 2
0
        public void AddSmsBalance(int amount)
        {
            if (amount <= 0)
            {
                throw DomainException.With("Invalid addition amount :{0}", amount);
            }

            SmsBalance += amount;
        }
Exemplo n.º 3
0
        public Subject RemoveSubject(int id)
        {
            for (var i = 0; i < _subjects.Count; i++)
            {
                if (_subjects[i].Id == id)
                {
                    var subject = _subjects[i];
                    _subjects.Remove(subject);

                    return(subject);
                }
            }

            throw DomainException.With("Subject id {0} does not exist in {1} - {2} unit", id, Id, Name);
        }
Exemplo n.º 4
0
        public void DeductSmsBalance(int amount)
        {
            if (amount <= 0)
            {
                throw DomainException.With("Invalid deduction amount :{0}", amount);
            }

            if (SmsBalance - amount < 0)
            {
                throw DomainException.With(
                          "Insufficient SMS credit.Current credit :{0}, DeductAmount :{1} ",
                          SmsBalance,
                          amount);
            }

            SmsBalance -= amount;
        }