public async Task <ActionResult> CreateUser(UserPartial iUser) { try { SignalRChatContext DB = new SignalRChatContext(); using (var transaction = DB.Database.BeginTransaction()) { try { bool isExist = UserFunctions.CheckIfUserExist(iUser, DB); if (isExist == true) { return(BadRequest()); } UserCls newUser = UserFunctions.CreateNewUser(iUser, DB); newUser.code = SignInCodesFucntions.GenerateCodeForUser(newUser.id, DB); transaction.Commit(); newUser.token = JwtHandler.CreateJwt(newUser.id, newUser.userName, DateTime.Now); await hubContext.Clients.All.AddUserEvent(newUser.id); return(new JsonResult(newUser)); } catch (Exception exc) { //write exc to log... transaction.Rollback(); return(BadRequest()); } } } catch (Exception ex) { //write ex to log... return(BadRequest()); } }