Esempio n. 1
0
            public async Task CheckValidityAsync(CallContext callContext)
            {
                if (QueryValidationHelper.IsReservedGuid(UserId))
                {
                    throw new InvalidOperationException("Invalid user id");
                }
                if (QueryValidationHelper.IsReservedGuid(ImageId))
                {
                    throw new InvalidOperationException("Invalid image id");
                }

                var imageDataBeforeUpdate = await callContext.DbContext.Images
                                            .AsNoTracking()
                                            .Where(img => img.Id == ImageId)
                                            .Select(img => new { nameBeforeUpdate = img.Name, sourceBeforeUpdate = img.Source, descriptionBeforeUpdate = img.Description })
                                            .SingleAsync();

                if (imageDataBeforeUpdate.nameBeforeUpdate == Name && imageDataBeforeUpdate.sourceBeforeUpdate == Source && imageDataBeforeUpdate.descriptionBeforeUpdate == Description)
                {
                    throw new RequestInputException(callContext.Localized.Get("CanNotUpdateMetadataBecauseSameAsOriginal"));
                }

                if (imageDataBeforeUpdate.nameBeforeUpdate != Name)
                {
                    await QueryValidationHelper.CheckCanCreateImageWithNameAsync(Name, callContext.DbContext, callContext.Localized);
                }

                QueryValidationHelper.CheckCanCreateImageWithSource(Source, callContext.Localized);
                QueryValidationHelper.CheckCanCreateImageWithDescription(Description, callContext.Localized);
                QueryValidationHelper.CheckCanCreateImageWithVersionDescription(VersionDescription, callContext.Localized);
            }
Esempio n. 2
0
            public async Task CheckValidityAsync(CallContext callContext)
            {
                //ImageMetadataInputValidator.Run(this, localizer);
                if (!supportedContentTypes.Contains(ContentType))
                {
                    throw new InvalidOperationException(callContext.Localized.Get("InvalidImageContentType") + $" '{ContentType}'");
                }
                if (Blob.Length < minBlobLength || Blob.Length > maxBlobLength)
                {
                    throw new RequestInputException(callContext.Localized.Get("InvalidBlobLength") + $" {Blob.Length}" + callContext.Localized.Get("MustBeBetween") + $" {minBlobLength} " + callContext.Localized.Get("And") + $" {maxBlobLength}");
                }

                await QueryValidationHelper.CheckCanCreateImageWithNameAsync(Name, callContext.DbContext, callContext.Localized);

                QueryValidationHelper.CheckCanCreateImageWithDescription(Description, callContext.Localized);
                QueryValidationHelper.CheckCanCreateImageWithSource(Source, callContext.Localized);
            }