public void UpdateConnectionId(int userId) { var currentUser = _context.Users.FirstOrDefault(u => u.UserId == userId); currentUser.ConnectionId = Context.ConnectionId; // String.Format("{0},{1}", currentUser.ConnectionId, Context.ConnectionId); _context.SaveChanges(); Clients.AllExcept(getExceptions()).InvokeAsync("changeStatus", currentUser); }
public string UploadAvatar([FromBody] User user) { try { string file = String.Format("Images/{0}.jpg", user.UserId); string hostFilePath = String.Format("{0}://{1}/{2}", (HttpContext.Request.IsHttps)?"https":"http", HttpContext.Request.Host.ToUriComponent(), file); string filePath = Path.Combine(_hostingEnvironment.WebRootPath, file); System.IO.File.WriteAllBytes(filePath, Convert.FromBase64String(user.Avatar)); var curruser = _context.Users.FirstOrDefault(e => e.UserId == user.UserId); if (curruser != null) { curruser.Avatar = hostFilePath; _context.SaveChanges(); } return(hostFilePath); } catch (Exception ex) { return(ex.InnerException.ToString()); } }