Пример #1
0
        public async Task <ResultDto <StudentCheckInDto> > CheckIn([FromBody] CheckInRequestDto request)
        {
            if (!ModelState.IsValid)
            {
                return(new ResultDto <StudentCheckInDto>(ResponseCode.Validate, "Đầu vào không hợp lệ", null));
            }
            var res = await _studentService.CheckIn(request);

            if (res.StatusCode == ResponseCode.Success)
            {
                // Message to All
                await _hubContext.Clients.All.SendAsync("ReceiveCheckIn", res);

                var notification = await _studentService.AddNotification(res.Result);

                if (notification.TypeNotification == (int)TypeMessage.InClass | notification.TypeNotification == (int)TypeMessage.NotInClass)
                {
                    // Message to parent and monitor
                    await _hubContext.Clients.User(res.Result.ParentId.ToString()).SendAsync("ReceiveNotication", notification);

                    await _hubContext.Clients.User(res.Result.MonitorId.ToString()).SendAsync("ReceiveNotication", notification);
                }
                else if (notification.TypeNotification != (int)TypeMessage.AtHome && notification.TypeNotification != (int)TypeMessage.OnLeave)
                {
                    // Message to parent and teacher
                    await _hubContext.Clients.User(res.Result.ParentId.ToString()).SendAsync("ReceiveNotication", notification);

                    await _hubContext.Clients.User(res.Result.TeacherId.ToString()).SendAsync("ReceiveNotication", notification);
                }
                else
                {
                    // Message to monitor and teacher
                    await _hubContext.Clients.User(res.Result.MonitorId.ToString()).SendAsync("ReceiveNotication", notification);

                    await _hubContext.Clients.User(res.Result.TeacherId.ToString()).SendAsync("ReceiveNotication", notification);
                }
            }
            return(res);
        }