public ActionResult Edit(UserEditRequest request) { try { _service.UpdateUserInformation(request, Session.SessionID); } catch (Exception e) { ViewBag.Error = e.Message; return View(request); } return RedirectToAction("Index"); }
public async Task UpdateUserInformation(UserEditRequest request, string sessionId) { if (ValidationHelper.ContainsSpecialCharacters(request.NewName)) { throw new ArgumentException("New name contains special characters"); } var session = _db.Sessions.FirstOrDefault(s => s.Id == sessionId); if (session != null) { session.User.Name = request.NewName; await _db.SaveChangesAsync(); } throw new NullReferenceException("No session found"); }