public async Task <IActionResult> PutChatMessage([FromRoute] int id, [FromBody] ChatMessage chatMessage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != chatMessage.Id) { return(BadRequest()); } _context.Entry(chatMessage).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ChatMessageExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task SaveHistory(int curruserid, int respuserid, int resuseridcurrnt, string msghtm) { if (respuserid == 0) { respuserid = resuseridcurrnt; } string groupname = ""; int i = curruserid; int j = respuserid; if (i < j) { groupname = i + "-" + j; } else { groupname = j + "-" + i; } ChatHistory chatHistory; // ChatMessage chatcurrent = await appContext.ChatMessage.FindAsync(curruserid); /// ChatMessage chatrespec = await appContext.ChatMessage.FindAsync(respuserid); chatHistory = await appContext.ChatHistory.Where(p => p.UserId == curruserid && p.GrpName == groupname).FirstOrDefaultAsync(); if (chatHistory == null) { chatHistory = new ChatHistory(); chatHistory.UserId = curruserid; if (msghtm != "") { chatHistory.ChatData = msghtm; } chatHistory.GrpName = groupname; appContext.ChatHistory.Add(chatHistory); } else { if (msghtm != "") { chatHistory.ChatData = msghtm; } appContext.ChatHistory.Attach(chatHistory); appContext.Entry(chatHistory).State = EntityState.Modified; } await appContext.SaveChangesAsync(); SaveLog("SaveHistory for Userid " + curruserid + " with connection id" + Context.ConnectionId + " for respective user " + resuseridcurrnt + " Group Name " + groupname); await Clients.All.SendAsync("HistorySaved", curruserid, resuseridcurrnt); }