BLL.ImageProfile.ValidateImageProfile C# (CSharp) Method

ValidateImageProfile() public static method

public static ValidateImageProfile ( Models imageProfile, bool isNewImageProfile ) : Models.ValidationResult
imageProfile Models
isNewImageProfile bool
return Models.ValidationResult
        public static Models.ValidationResult ValidateImageProfile(Models.ImageProfile imageProfile, bool isNewImageProfile)
        {
            var validationResult = new Models.ValidationResult();

            if (string.IsNullOrEmpty(imageProfile.Name) || !imageProfile.Name.All(c => char.IsLetterOrDigit(c) || c == '_'))
            {
                validationResult.IsValid = false;
                validationResult.Message = "Image Profile Name Is Not Valid";
                return validationResult;
            }

            if (isNewImageProfile)
            {
                using (var uow = new DAL.UnitOfWork())
                {
                    if (uow.ImageProfileRepository.Exists(h => h.Name == imageProfile.Name && h.ImageId == imageProfile.ImageId))
                    {
                        validationResult.IsValid = false;
                        validationResult.Message = "This Image Profile Already Exists";
                        return validationResult;
                    }
                }
            }
            else
            {
                using (var uow = new DAL.UnitOfWork())
                {
                    var originalImageProfile = uow.ImageProfileRepository.GetById(imageProfile.Id);
                    if (originalImageProfile.Name != imageProfile.Name)
                    {
                        if (uow.ImageProfileRepository.Exists(h => h.Name == imageProfile.Name && h.ImageId == imageProfile.ImageId))
                        {
                            validationResult.IsValid = false;
                            validationResult.Message = "This Image Profile Already Exists";
                            return validationResult;
                        }
                    }
                }
            }

            return validationResult;
        }