コード例 #1
0
        public void ReadNotification([FromBody] AnswerTeamInputModel model)
        {
            var notification = _db.Notifications.FirstOrDefault(n => n.Id == model.NoteId);

            notification.IsRead = true;
            notification.ReadAt = DateTime.Now;
            _db.SaveChanges();
        }
コード例 #2
0
        public void AcceptTeam([FromBody] AnswerTeamInputModel model)
        {
            var currentUser  = _userDb.Users.FirstOrDefault(u => u.Id == _userManager.GetUserId(HttpContext.User));
            var notification = _db.Notifications.FirstOrDefault(n => n.Id == model.NoteId);
            var team         = _db.Teams.FirstOrDefault(t => t.Id == notification.ToTeamId);

            if (team == null)
            {
                return;
            }
            if (notification == null)
            {
                return;
            }
            if (currentUser == null)
            {
                return;
            }
            var userTeam = new UserTeam
            {
                TeamId  = notification.ToTeamId,
                UserId  = currentUser.Id,
                IsAdmin = false
            };

            _db.UserTeams.Add(userTeam);
            _db.SaveChanges();

            notification.IsRead  = true;
            notification.ReadAt  = DateTime.Now;
            notification.Message = "You have accepted the invitation to join " + team.Name;
            _db.SaveChanges();
            var newNotification = new Notification
            {
                ToId      = notification.FromId,
                ToName    = notification.FromName,
                Message   = "@" + notification.ToName + " has accepted the invitation to join your team.",
                FromId    = currentUser.Id,
                FromName  = currentUser.UserName,
                IsRead    = false,
                ToTeamId  = notification.ToTeamId,
                CreatedAt = DateTime.Now,
                Type      = 2,
                Link      = notification.Link
            };

            _db.Notifications.Add(newNotification);
            _db.SaveChanges();
        }