Пример #1
0
        /// <summary>
        /// Generates response object for ApiOffence
        /// </summary>
        /// <param name="offense"></param>
        /// <param name="propertName"></param>
        /// <returns></returns>
        private static byte[] getContent(ApiOffence offense, string propertName)
        {
            var obj = new Dictionary <string, object>()
            {
                [propertName] = new { ErrorCode = offense.ErrorCode }
            };

            return(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj)));
        }
Пример #2
0
        /// <summary>
        /// Forms 418 client error response object with response object
        /// </summary>
        /// <param name="offense"></param>
        /// <param name="propertName"></param>
        /// <returns></returns>
        public static ValidationResult ToTeapotResult(ApiOffence offense, string propertName)
        {
            if (offense.Equals(default(ApiOffence)) || propertName == null || propertName.Length == 0)
            {
                return(null);
            }

            var res = new ValidationResult();

            res.Content    = getContent(offense, propertName);
            res.StatusCode = 418;
            return(res);
        }