public async Task <IActionResult> Create(TeamMemCreateViewModel model) { if (ModelState.IsValid) { string fileName = null; if (model.Image != null) { string UploadFplder = Path.Combine(webHostEnvironment.WebRootPath, "TeamImg"); fileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName; string filepath = Path.Combine(UploadFplder, fileName); model.Image.CopyTo(new FileStream(filepath, FileMode.Create)); } TeamMem teamMem = new TeamMem { TitleJob = model.TitleJob, Name = model.Name, Image = fileName }; db.Add(teamMem); await db.SaveChangesAsync(); return(RedirectToAction("ATeamMem", "TeamMem")); } return(View()); }
public IActionResult Update(TeamMem obj) { if (ModelState.IsValid) { db.TeamMems.Update(obj); db.SaveChanges(); return(RedirectToAction("ATeamMem", "TeamMem")); } return(View(obj)); }