Beispiel #1
0
        public async Task <IActionResult> OnPost()
        {
            if (ModelState.IsValid)
            {
                var byteFile = await _fileHelper.ConvertToByteArrayAsync(OnlineEventImage);

                if (_fileValidator.ValidateSize(OnlineEventImage.Length) &&
                    _fileValidator.ValidateExtension(OnlineEventImage.FileName) &&
                    _fileValidator.ValidateSignature(OnlineEventImage.FileName, byteFile))
                {
                    OnlineEvent.ImageContent = byteFile;
                    await _httpHelper.PostAsJsonAsync <CreatedRow, OnlineEvent>(BandCamsEndpoints.OnlineEvent, OnlineEvent);

                    return(Redirect("/Index"));
                }
                else
                {
                    ModelState.AddModelError(nameof(OnlineEventImage), $"Plik nie może być większy niż {_fileValidator.GetMaxFileSizeInMb}. Dopuszczalne rozszerzenia to {_fileValidator.GetPermittedExtensions}");
                    return(Page());
                }
            }
            else
            {
                return(Page());
            }
        }