예제 #1
0
 /// <summary>
 /// Adds a gift to the database from incoming arguments
 /// </summary>
 /// <param name="name">
 /// The name.
 /// </param>
 /// <param name="price">
 /// The price.
 /// </param>
 /// <param name="description">
 /// The description.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public static bool AddGift(string name, string price, string description)
 {
     if (Gift.IsValidName(name) && Gift.IsValidPrice(price))
     {
         var gift = new Gift {
             GiftName = name, GiftPrice = long.Parse(price), GiftDescription = description
         };
         return(new GiftDataOperations().AddRecord(gift) != 0);
     }
     return(false);
 }
예제 #2
0
        /// <summary>
        /// Returns an error message to the view class if any UI fields are invalid
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="priceString">
        /// The price string.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string HasInvalidGiftTextFields(string name, string priceString)
        {
            if (string.IsNullOrEmpty(name))
            {
                return("Gift name is required");
            }
            if (string.IsNullOrEmpty(priceString))
            {
                return("Price is required");
            }

            if (!Gift.IsValidName(name))
            {
                return("Gift names should have only letters, numbers, dashes and underscores in between characters");
            }

            if (!Gift.IsValidPrice(priceString))
            {
                return("Price should be in US dollars (no $ sign) optional commas (all or none) and optional cents"
                       + "\nExamples:" + "\n1234.34" + "\n123434" + "\n1,234.34" + "\n1,23434");
            }

            return(Gift.CatchIntParseOverflow(priceString));
        }