Beispiel #1
0
        /// <summary>
        /// Отправить смс
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <BaseApiResponse> SendSms(SendSmsToClient model)
        {
            if (!IsUserAdmin())
            {
                return(new BaseApiResponse(false, ValidationMessages.YouAreNotAnAdministrator));
            }

            var phoneAndId = await Query <EccUser>().Select(x => new { x.PhoneNumber, x.Id }).FirstOrDefaultAsync(x => x.Id == model.ClientId);

            if (phoneAndId == null)
            {
                return(new BaseApiResponse(false, "Клиент не найден по указанному идентификатору"));
            }

            var toMes = ToSmsMessage(model, phoneAndId.PhoneNumber);

            GetRepository <SmsMessageInteraction>().CreateHandled(toMes.Item1);
            GetRepository <InteractionStatusLog>().CreateHandled(toMes.Item2);

            return(await TrySaveChangesAndReturnResultAsync("Sms-сообщение добавлено в очередь"));
        }
Beispiel #2
0
        /// <summary>
        /// Привести к смс сообщению
        /// </summary>
        /// <param name="message"></param>
        /// <param name="phoneNumber"></param>
        /// <returns></returns>
        public (SmsMessageInteraction, InteractionStatusLog, List <InteractionAttachment>) ToSmsMessage(SendSmsToClient message, string phoneNumber)
        {
            var id = Guid.NewGuid().ToString();

            var attachments = message.AttachmentFileIds?.Select(x => new InteractionAttachment
            {
                FileId        = x,
                InteractionId = id,
            }).ToList();

            return(new SmsMessageInteraction
            {
                Id = id,
                TitleText = null,
                MessageText = message.Message,
                SendNow = true,
                UserId = message.ClientId,
                Type = EccConsts.SmsType,
                Attachments = attachments,
                PhoneNumber = phoneNumber,
            },
                   new InteractionStatusLog
            {
                InteractionId = id,
                Status = InteractionStatus.Created,
                StartedOn = Application.DateTimeProvider.Now
            },
                   attachments);
        }