示例#1
0
        public async Task FileUploaded(string message)
        {
            try
            {
                JArray arrMessage    = JArray.Parse(message);
                JArray arrFiles      = new JArray();
                int    RoomId        = (int)arrMessage[0]["RoomId"];
                int    AppointmentId = (int)arrMessage[0]["AppointmentId"];
                string Role          = (string)arrMessage[0]["Role"];
                int    ParticipantId = Role == "patient" ? (int)arrMessage[0]["ParticipantId"] : (int)arrMessage[0]["ProviderId"];
                foreach (JObject objMessage in arrMessage)
                {
                    arrFiles.Add(new JObject
                    {
                        ["Path"]     = objMessage["Path"],
                        ["FileName"] = objMessage["FileName"],
                        ["Size"]     = objMessage["Size"]
                    });
                    await _commonManager.SaveFileDetails(new FileTransferModel
                    {
                        RoomId        = RoomId,
                        AppointmentId = AppointmentId,
                        ParticipantId = ParticipantId,
                        Role          = Role,
                        Path          = (string)objMessage["Path"],
                        FileName      = (string)objMessage["FileName"],
                    });
                }

                if (Role == "doctor" || Role == "admin")
                {
                    var participant = await _commonManager.GetParticipantDetailsById(new CallParticipantModel
                    {
                        RoomId        = RoomId,
                        AppointmentId = AppointmentId,
                        ParticipantId = (int)arrMessage[0]["ParticipantId"],
                        Role          = "patient"
                    });

                    await Clients.Client(participant.SocketId).SendAsync("FileUploaded", arrFiles.ToString());
                }
                else if (Role == "patient")
                {
                    var socketids = await _providerManager.GetProviderToken(RoomId);

                    var user           = Context.User.Identity.Name;
                    var patientDetails = await _patientIManager.GetPatientDetails(user);

                    string HostName = (string)arrMessage[0]["HostName"];
                    foreach (string socketid in socketids)
                    {
                        await Clients.Client(socketid).SendAsync("FileUploadedByPatient", arrFiles.ToString());
                    }
                    foreach (JObject file in arrFiles)
                    {
                        var provider = await _providerManager.GetProviderDetailsById(ParticipantId);

                        string body = await _providerManager.GetPatientFileUploadedEmailBody(new EmailModel
                        {
                            UserId   = provider.UserId,
                            HostName = HostName,
                            RoomId   = RoomId
                        }
                                                                                             , $"{patientDetails.FirstName} {patientDetails.LastName}", (string)file["Path"], (string)file["FileName"]);

                        if (provider.AllowEmail)
                        {
                            await _emailService.SendEmail(provider.Email, body, "File uploaded");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                await Clients.Caller.SendAsync("Exception", new JObject
                {
                    ["error"]      = ex.Message,
                    ["stackTrace"] = ex.StackTrace
                }.ToString());
            }
        }