示例#1
0
        //returns "MODEL.User" object if successful/found
        //returns "null" if not
        internal User findUserByEmail(string email)
        {
            int result = (int)CODE.MINUS_ONE;
            User user = null;

            //validate email 
            if (
                result == (int)CODE.ZERO ||
                string.IsNullOrWhiteSpace(email) ||
                !Validate.hasMinLength(email, 5) ||
                !Validate.hasMaxLength(email, 50) ||
                !email.Contains("@")
               ) { result = (int)CODE.ZERO; }
            if (result != (int)CODE.ZERO)//safe to proceed
            {
                IUsers _DbUsers = new DbUsers();

                try
                {
                    using (var trScope = TransactionScopeBuilder.CreateSerializable())
                    {
                        user = _DbUsers.findUserByEmail(email);

                        trScope.Complete();
                    }
                }
                catch (TransactionAbortedException taEx)
                {
                    result = (int)CODE.ZERO;
                    Log.Add(taEx.ToString());
                }
                catch (ApplicationException aEx)
                {
                    result = (int)CODE.ZERO;
                    Log.Add(aEx.ToString());
                }
                catch (Exception ex)
                {
                    result = (int)CODE.ZERO;
                    Log.Add(ex.ToString());
                }
            }
            else { result = (int)CODE.ZERO; }

            if (result == (int)CODE.ZERO || user == null) { return null; }
            else { return user; }
        }