Esempio n. 1
0
 public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     if (!string.IsNullOrWhiteSpace(Cipher.OrganizationId) && (!CollectionIds?.Any() ?? true))
     {
         yield return(new ValidationResult("You must select at least one collection.",
                                           new string[] { nameof(CollectionIds) }));
     }
 }
Esempio n. 2
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (!Ciphers?.Any() ?? true)
            {
                yield return(new ValidationResult("You must select at least one cipher.",
                                                  new string[] { nameof(Ciphers) }));
            }
            else
            {
                var allHaveIds      = true;
                var organizationIds = new HashSet <string>();
                foreach (var c in Ciphers)
                {
                    organizationIds.Add(c.OrganizationId);
                    if (allHaveIds)
                    {
                        allHaveIds = !(string.IsNullOrWhiteSpace(c.Id) || string.IsNullOrWhiteSpace(c.OrganizationId));
                    }
                }

                if (!allHaveIds)
                {
                    yield return(new ValidationResult("All Ciphers must have an Id and OrganizationId.",
                                                      new string[] { nameof(Ciphers) }));
                }
                else if (organizationIds.Count != 1)
                {
                    yield return(new ValidationResult("All ciphers must be for the same organization."));
                }
            }

            if (!CollectionIds?.Any() ?? true)
            {
                yield return(new ValidationResult("You must select at least one collection.",
                                                  new string[] { nameof(CollectionIds) }));
            }
        }