Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            using (var ms = new MemoryStream())
            {
                var image = ImageUpload.Image;

                await image.CopyToAsync(ms);

                var imageBytes   = ms.ToArray();
                var imageContent = Convert.ToBase64String(imageBytes);

                var imageRequest = new ImageRequest
                {
                    Name      = ImageUpload.Name,
                    Content   = imageContent,
                    ImageType = image.ContentType
                };

                if (AttendeeUsername == null)
                {
                    TempData.Set(TempDataKey.NewImage, imageRequest);
                }
                else
                {
                    await _apiClient.AddImageToAttendeeAsync(AttendeeUsername, imageRequest);
                }

                return(RedirectToPage());
            }
        }