Ejemplo n.º 1
0
        /// <summary>
        /// Validate customer object
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="messages"></param>
        /// <returns></returns>
        public bool Validate(CustomerDataMapperWrapper obj, out IList <Message> messages)
        {
            messages = new List <Message>();

            if (string.IsNullOrEmpty(obj.customer.FirstName))
            {
                messages.Add(_commonErrorHandler.GetFirstNameCantbeEmpty());
                return(false);
            }
            if (string.IsNullOrEmpty(obj.customer.LastName))
            {
                messages.Add(_commonErrorHandler.GetLastNameCantbeEmpty());
                return(false);
            }
            if (obj.customer.Phone.ToString().Length > 9)
            {
                messages.Add(_commonErrorHandler.GetPhoneNumberRange());
                return(false);
            }
            if (string.IsNullOrEmpty(obj.customer.Address))
            {
                messages.Add(_commonErrorHandler.GetAddressCantbeEmpty());
                return(false);
            }

            if (obj.customer.File != null &&
                ((obj.customer.File.ContentType != "image/jpeg") && (obj.customer.File.ContentType != "image/png")))
            {
                messages.Add(_commonErrorHandler.GetInvaildImageFormat());
                return(false);
            }
            if (obj.customer.File == null && obj.customer.Id == 0)
            {
                messages.Add(_commonErrorHandler.GetProfileCantbeEmpty());
                return(false);
            }


            if (obj.customer.Phone == 0)
            {
                messages.Add(_commonErrorHandler.GetPhoneCantbeEmpty());
                return(false);
            }
            if (string.IsNullOrEmpty(obj.customer.PostalCode))
            {
                messages.Add(_commonErrorHandler.GetPostalCodeCantbeEmpty());
                return(false);
            }


            return(true);
        }