public NotificationModel(Notification notification) { this.Id = notification.Id; this.Message = notification.Message; this.DateCreated = notification.DateCreated; this.Type = notification.Type; this.State = notification.State.ToString(); this.GameId = notification.GameId; }
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(); }