Skip to content
Snippets Groups Projects

Feature/chat signalr

Merged Enzo Santangelo Dodera requested to merge feature/chat-signalr into develop
1 file
+ 1
2
Compare changes
  • Side-by-side
  • Inline
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Tsi1.BusinessLayer.Helpers;
using Tsi1.BusinessLayer.Interfaces;
using Tsi1.DataLayer;
using Tsi1.DataLayer.Entities;
namespace Tsi1.BusinessLayer.Services
{
public class ChatService : IChatService
{
private readonly Tsi1Context _tsi1Context;
public ChatService(Tsi1Context tsi1Context)
{
_tsi1Context = tsi1Context;
}
public async Task<ServiceResult<Group>> CreateGroup(Group group)
{
var result = new ServiceResult<Group>();
_tsi1Context.Groups.Add(group);
try
{
await _tsi1Context.SaveChangesAsync();
}
catch (Exception)
{
result.HasError = true;
}
return result;
}
public async Task<Group> GetGroupByName(string groupName)
{
var result = new ServiceResult<Group>();
var group = await _tsi1Context.Groups.FirstOrDefaultAsync(x => x.Name == groupName);
return group;
}
public async Task<bool> RemoveConnectionFromGroup(string connectionId)
{
var connection = await _tsi1Context.Connections.FirstOrDefaultAsync(x => x.ConnectionId == connectionId);
if (connection != null)
{
connection.Group = null;
await _tsi1Context.SaveChangesAsync();
}
return true;
}
}
}
Loading