Example #1
0
        public static ValidationResult Validate(this RatingInput input, int?id = null)
        {
            if (input == null)
            {
                return(new ValidationResult
                {
                    Message = $"Invalid input, input is null.",
                    IsValid = false
                });
            }

            if (id.HasValue && id < 1)
            {
                return(new ValidationResult
                {
                    Message = $"Invalid Id. Provided id was {id}.",
                    IsValid = false
                });
            }

            if (input.Score < 0 || input.Score > 5)
            {
                return(new ValidationResult
                {
                    Message = $"Invalid score. Provided score was {input.Score}, valid scores are 0-5.",
                    IsValid = false
                });
            }

            return(new ValidationResult
            {
                IsValid = true
            });
        }
Example #2
0
 public static RatingModel ToModel(this RatingInput input, int id)
 {
     return(new RatingModel(input.Name, input.Score, id));
 }