public async Task <IActionResult> OnPostAddProductAsync(ProductDto dto) { if (!ModelState.IsValid) { ViewData["productError"] = "Fill all fields"; return(Page()); } Product product = _mapper.Map <Product>(dto); if (dto.File != null) { string path = "/images/product/" + dto.File.FileName; using (var stream = new FileStream(_env.WebRootPath + path, FileMode.OpenOrCreate)) { await dto.File.CopyToAsync(stream); } product.ImageFile = dto.File.FileName; } else { product.ImageFile = "https://piotrkowalski.pw/assets/camaleon_cms/image-not-found-4a963b95bf081c3ea02923dceaeb3f8085e1a654fc54840aac61a57a60903fef.png"; } await _productApi.CreateProduct(product); return(RedirectToPage("Index")); }