Exemplo n.º 1
0
        public async Task <PushToken> DeleteToken(string value, PushTokenType type, int userId)
        {
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException("Value");
            }

            var token = await Repository.ByValue(value);

            if (token == null)
            {
                throw new EntityNotFoundException($"not found token with value: {value}");
            }

            if (!token.Type.Equals(type))
            {
                throw new ArgumentException(
                          $"token has different type." +
                          $"Expected: {type}.\n" +
                          $"Actual: {token.Type}");
            }

            if (!token.UserId.Equals(userId))
            {
                throw new ArgumentException(
                          $"token has different user." +
                          $"Expected: {userId}.\n" +
                          $"Actual: {token.UserId}");
            }

            return(await Delete(token));
        }
Exemplo n.º 2
0
		/// <summary>
		/// Creates and initializes a new <see cref="PushToken"/> instance.
		/// </summary>
		/// <param name="type">The type of token in <paramref name="token"/>.</param>
		/// <param name="token">The token.</param>
		/// <exception cref="ArgumentNullException"><paramref name="token"/> is <c>null</c>.</exception>
		/// <exception cref="ArgumentException">
		/// <para><paramref name="type" /> is not a valid <see cref="PushTokenType"/></para>
		/// <para>-- or --</para>
		/// <para><paramref name="token"/> is an empty string.</para>
		/// </exception>
		public PushToken (PushTokenType type, string token)
		{
			if (!Enum.IsDefined (typeof(PushTokenType), type))
				throw new ArgumentException ("Invalid type", "type");
			if (token == null)
				throw new ArgumentNullException ("token");
			if (token.Trim() == String.Empty)
				throw new ArgumentException ("token can not be empty", "token");

			Type = type;
			Token = token;
		}
Exemplo n.º 3
0
        public async Task <PushToken> CreateToken(string value, PushTokenType type, int userId)
        {
            if (await ExistToken(value))
            {
                throw new DublicateException($"token with same value alredy exist. Value: {value}");
            }

            var token = new PushToken
            {
                Value  = value,
                Type   = type,
                UserId = userId
            };

            return(await Create(token));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates and initializes a new <see cref="PushToken"/> instance.
        /// </summary>
        /// <param name="type">The type of token in <paramref name="token"/>.</param>
        /// <param name="token">The token.</param>
        /// <exception cref="ArgumentNullException"><paramref name="token"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">
        /// <para><paramref name="type" /> is not a valid <see cref="PushTokenType"/></para>
        /// <para>-- or --</para>
        /// <para><paramref name="token"/> is an empty string.</para>
        /// </exception>
        public PushToken(PushTokenType type, string token)
        {
            if (!Enum.IsDefined(typeof(PushTokenType), type))
            {
                throw new ArgumentException("Invalid type", "type");
            }
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }
            if (token.Trim() == String.Empty)
            {
                throw new ArgumentException("token can not be empty", "token");
            }

            Type  = type;
            Token = token;
        }