Ejemplo n.º 1
0
 /// <summary>Updates the group for the current supplier.</summary>
 public void UpdateGroup(SupplierGroup group)
 {
     if (group != null)
     {
         Group = group;
         group.AddSupplier(this);
     }
 }
Ejemplo n.º 2
0
        /// <summary>Creates a new instance of <see cref="Supplier"/>.</summary>
        /// <exception cref="ArgumentException">Thrown when any of the string arguments is invalid (null or empty).</exception>
        /// <exception cref="ArgumentNullException">Thrown when supplier group is not provided.</exception>
        /// <exception cref="FormatException">Thrown when either email or phone number have incorrect format.</exception>
        public Supplier(int id, string name, string address, string emailAddress, string phoneNumber, SupplierGroup group)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Supplier's name must be provided.");
            }
            if (string.IsNullOrEmpty(address))
            {
                throw new ArgumentException("Supplier's address must be provided.");
            }
            if (string.IsNullOrEmpty(emailAddress))
            {
                throw new ArgumentException("Supplier's email address must be provided.");
            }
            if (string.IsNullOrEmpty(phoneNumber))
            {
                throw new ArgumentException("Supplier's phone number must be provided.");
            }
            if (group == null)
            {
                throw new ArgumentNullException(nameof(@group));
            }
            if (!phoneNumberRegex.Match(phoneNumber).Success)
            {
                throw new FormatException("Invalid phone number.");
            }

            Id           = id;
            Name         = name;
            Address      = address;
            EmailAddress = new MailAddress(emailAddress);
            PhoneNumber  = phoneNumber;
            Group        = group;

            group.AddSupplier(this);
        }