public IActionResult OnPost(AddMediaModel model) { try { var type = HttpContext.Session.GetInt32("EventType"); if (type == 1) { var fileUpload = Path.Combine(ihostingEnvironment.ContentRootPath, "Files", ImageUploader.FileName); var stream = new MemoryStream(); var img = ImageUploader.CopyToAsync(stream); var fileBytes = stream.ToArray(); string base64 = Convert.ToBase64String(fileBytes); model.Image = base64; model.Type = CharityProject.Domain.Common.EventType.image; var res = addMediaCommand.Execute(model); } else if (type == 2) { model.Type = CharityProject.Domain.Common.EventType.vedio; var res = addMediaCommand.Execute(model); } return(RedirectToPage("AddNewEvent")); } catch (Exception ex) { ErrorHandling errorHandling = new ErrorHandling(); var res = errorHandling.GetErrorMessage(ex); TempData["ErrorMessage"] = res; return(null); } }