public async Task <IActionResult> Create(CreateUpdatePostViewModel model) { if (ModelState.IsValid) { AppUser CurrentUser = await this.UserManager.GetUserAsync(HttpContext.User); //Upload File String UploadPath = Path.Combine(HostingEnvironment.WebRootPath, "Uploads"); if (!Directory.Exists(UploadPath)) { Directory.CreateDirectory(UploadPath); } String ThumbnailName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + "-" + model.Thumbnail.FileName; String FullPath = Path.Combine(UploadPath, ThumbnailName); using (FileStream stream = new FileStream(FullPath, FileMode.Create, FileAccess.Write)) { model.Thumbnail.CopyTo(stream); } Post post = new Post() { CategoryId = model.CategoryId, Status = model.Status, Content = model.Content, ThumbnailPath = ThumbnailName, Title = model.Title, UserId = CurrentUser.Id, }; PostsRepository.Add(post); await PostsRepository.CommitAsync(); return(RedirectToAction("Index")); } model.Categories = CategoriesRepository.GetAll(); return(View(model)); }