private void SendNotification(int gameId, string userId, string type, string message)
{
var receiver = this.data.Users.Find(userId);
var game = this.data.Games.All()
.Where(a => a.Id == gameId)
.FirstOrDefault();
if (game == null)
{
throw new ArgumentException("Game do not exists");
}
var newNotification = new Notification
{
Message = message,
DateCreated = DateTime.Now,
Type = type,
State = NotificationState.Unread,
GameId = gameId,
Game = game,
UserId = userId,
User = receiver
};
this.data.Notifications.Add(newNotification);
receiver.Notifications.Add(newNotification);
this.data.SaveChanges();
}
}