Пример #1
0
 public EventUpdateValidator(ICommunityService communityService, IEventService eventService)
 {
     RuleFor(x => x.Id).NotEmpty().CustomAsync(async(id, ctx, cancellationToken) =>
     {
         var exist = await eventService.ExistsAsync(id);
         if (!exist)
         {
             ctx.AddFailure(new ValidationFailure("Event", $"Event: '{id}' not exist. Please create first"));
         }
     });
     RuleFor(x => x.Name).NotEmpty();
     RuleFor(x => x.StartDate).NotNull().LessThanOrEqualTo(x => x.EndDate);
     RuleFor(x => x.EndDate).NotNull().GreaterThanOrEqualTo(x => x.StartDate);
     When(x => x.CFP != null, () =>
     {
         RuleFor(x => x.CFP.Url).NotEmpty();
         RuleFor(x => x.CFP.StartDate).NotNull().LessThanOrEqualTo(x => x.CFP.EndDate);
         RuleFor(x => x.CFP.EndDate).NotNull().GreaterThanOrEqualTo(x => x.CFP.StartDate);
     });
     When(x => string.IsNullOrEmpty(x.CommunityName), () =>
     {
         RuleFor(x => x.CommunityName).CustomAsync(async(name, ctx, cancellationToken) =>
         {
             bool exist = await communityService.ExistsAsync(name);
             if (!exist)
             {
                 ctx.AddFailure(new ValidationFailure("CommunityName", $"Community: '{name}' not exist. Please create first"));
             }
         });
     });
 }
 public CommunityValidator(ICommunityService communityService)
 {
     RuleFor(x => x.Name).NotEmpty().CustomAsync(async(name, ctx, cancellationToken) =>
     {
         if (await communityService.ExistsAsync(name))
         {
             ctx.AddFailure($"Community {name} already Exists");
         }
     });
 }
 public CommunityUpdateValidator(ICommunityService communityService)
 {
     RuleFor(x => x.Name).NotEmpty().CustomAsync(async(name, ctx, cancellationToken) =>
     {
         if (!await communityService.ExistsAsync(name))
         {
             ctx.AddFailure($"Community {name} not exist. Please create first");
         }
     });
 }
Пример #4
0
        public async Task <IActionResult> PostImage(
            [HttpTrigger(AuthorizationLevel.Anonymous, HttpVerbs.POST, Route = "UploadImage")] HttpRequestMessage req,
            ILogger log)
        {
            var provider = new MultipartMemoryStreamProvider();
            await req.Content.ReadAsMultipartAsync(provider);

            var file          = provider.Contents.First();
            var fileExtension = new FileInfo(file.Headers.ContentDisposition.FileName.Replace("\"", "")).Extension.ToLower();
            var fileData      = await file.ReadAsByteArrayAsync();

            var    querystring = req.RequestUri.ParseQueryString();
            string typeUpload  = querystring.Get("type");
            string id          = querystring.Get("id");

            if (string.IsNullOrEmpty(typeUpload) || string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("Id and UploadType must not be empty");
            }
            Uri             imageStorageUri = null;
            BlobInformation blobInformation;

            switch (typeUpload.ToUpper())
            {
            case "COMMUNITY":
                if (await communityService.ExistsAsync(id))
                {
                    blobInformation = ImageStructure.CommunityPictureOriginal(id, fileExtension);
                    imageStorageUri = await fileService.UploadImageAsync(blobInformation.BlobContainerName, blobInformation.FileName, fileData).ConfigureAwait(false);

                    await communityService.UpdateImageAsync(id, imageStorageUri).ConfigureAwait(false);
                }
                else
                {
                    throw new ArgumentException($"Community id: {id}, not exist");
                }
                break;

            case "EVENT":
                if (await eventService.ExistsAsync(id))
                {
                    blobInformation = ImageStructure.EventPictureOriginal(id, fileExtension);
                    imageStorageUri = await fileService.UploadImageAsync(blobInformation.BlobContainerName, blobInformation.FileName, fileData).ConfigureAwait(false);

                    await eventService.UpdateLogoAsync(id, imageStorageUri).ConfigureAwait(false);
                }
                else
                {
                    throw new ArgumentException($"Event id: {id}, not exist");
                }
                break;

            case "PERSON":
                if (await personService.ExistsAsync(id))
                {
                    blobInformation = ImageStructure.PersonPictureOriginal(id, fileExtension);
                    imageStorageUri = await fileService.UploadImageAsync(blobInformation.BlobContainerName, blobInformation.FileName, fileData);

                    await personService.UpdateImageAsync(id, imageStorageUri);
                }
                else
                {
                    throw new ArgumentException($"Person id: {id}, not exist");
                }
                break;
            }
            return(new OkObjectResult(new { ImageUrl = imageStorageUri }));
        }