public async Task <IActionResult> Create(EventPostViewModel eventPostModel) { if (ModelState.IsValid) { var eventForSave = _mapper.Map <EventPostViewModel, Event>(eventPostModel); var eventFromDb = _eventData.AddEvent(eventForSave); var fileExt = eventPostModel.Wallpaper.FileName.Split('.').Last(); string path = $"{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}" + $"eventWallpapers{Path.DirectorySeparatorChar}" + eventFromDb.Id + $".{fileExt}"; using (var fileStream = new FileStream(_env.WebRootPath + path, FileMode.Create)) { await eventPostModel.Wallpaper.CopyToAsync(fileStream); } eventFromDb.ImageUrl = "/images/eventWallpapers/" + eventFromDb.Id + $".{fileExt}"; eventFromDb.Organizer = await _userManager.GetUserAsync(User); eventFromDb.ImageLocalUrl = _env.WebRootPath + path; _eventData.UpdateEvent(eventFromDb); return(RedirectToAction("Index", "Profile")); } return(View()); }