public async Task <IActionResult> Create([Bind("UserID,Image,Location")] SetLocationVM setLocationVM) { if (ModelState.IsValid) { var userData = new UserData(); var user = await _context.Users.FirstOrDefaultAsync(m => m.UserName == User.Identity.Name); userData.UserID = user.Id; if (string.IsNullOrEmpty(userData.Image)) { userData.Image = "None"; } if (string.IsNullOrEmpty(setLocationVM.Location)) { userData.Location = "Dhaka"; } else { userData.Location = setLocationVM.Location; } _context.Add(userData); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Shouts")); } return(View(setLocationVM)); }
public async Task <IActionResult> Edit(string id, [Bind("UserID,Image,Location")] SetLocationVM setLocationVM) { if (id != setLocationVM.UserID) { return(NotFound()); } if (ModelState.IsValid) { var userData = new UserData(); try { var user = await _context.Users.FirstOrDefaultAsync(m => m.UserName == User.Identity.Name); setLocationVM.UserID = user.Id; userData.UserID = setLocationVM.UserID; userData.Image = setLocationVM.Image; userData.Location = setLocationVM.Location; _context.Update(userData); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserDataExists(userData.UserID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index", "Shouts")); } return(View(setLocationVM)); }
public async Task <IActionResult> Edit(string id) { if (id == null) { return(NotFound()); } var userData2 = await _context.UserData.FindAsync(id); var userData = new SetLocationVM(this._context); if (userData2 == null) { return(RedirectToAction("Create", "UserDatas")); } else { userData.UserID = userData2.UserID; userData.Image = userData2.Image; userData.Location = userData2.Location; return(View(userData)); } }
public IActionResult Create() { var userData = new SetLocationVM(this._context); return(View(userData)); }