コード例 #1
0
        public SmsLogViewModel(SmsLogs obj, string connectionString) : this()
        {
            context = new MySqlContext(new MySqlConnectionFactory(connectionString));

            Id = obj.Id;
            HealthFacilitiesId = obj.HealthFacilitiesId;
            SmsTemplateId      = obj.SmsTemplateId;
            PhoneNumber        = obj.PhoneNumber;
            Message            = obj.Message;
            Status             = obj.Status;
            SentDate           = obj.SentDate;
            LogType            = obj.LogType;
            Telco         = obj.Telco;
            ResultMessage = obj.ResultMessage;


            var healthFacilities = context.JoinQuery <SmsLogs, HealthFacilities>((s, h) => new object[]
            {
                JoinType.InnerJoin, s.HealthFacilitiesId == h.HealthFacilitiesId
            })
                                   .Where((s, h) => s.Id == obj.Id)
                                   .Select((s, h) => h).FirstOrDefault();

            healthfacilitiesName = healthFacilities != null ? healthFacilities.Name : "";

            var smsTemplate = context.JoinQuery <SmsLogs, SmsTemplate>((s, h) => new object[]
            {
                JoinType.InnerJoin, s.SmsTemplateId == h.Id
            })
                              .Where((s, h) => s.Id == obj.Id)
                              .Select((s, h) => h).FirstOrDefault();

            SmsTemplateContent = smsTemplate != null ? smsTemplate.SmsContent : "";
            SmsTemplateName    = smsTemplate != null ? smsTemplate.SmsTemplateName : "";
        }
コード例 #2
0
ファイル: SmsLogsBll.cs プロジェクト: kylin589/EmePro
 public static bool AddLog(SmsLogs log)
 {
     using (var dbContext = new EmeLogsEntities())
     {
         dbContext.Entry(log).State = EntityState.Added;
         return dbContext.SaveChanges() > 0;
     }
 }
コード例 #3
0
        public static void SaveInfoSmsBookingError(string configuration, SmsInfoBookingInputViewModel infoInput, string message)
        {
            DbContext      _context  = new MySqlContext(new MySqlConnectionFactory(configuration));
            List <SmsLogs> lstSmsLog = new List <SmsLogs>();

            foreach (var resp in infoInput.lstMedicalHealthcareHistories)
            {
                SmsLogs smsLog = new SmsLogs();
                smsLog.PhoneNumber             = resp.PhoneNumber;
                smsLog.Message                 = "";
                smsLog.ResultMessage           = message;
                smsLog.Status                  = 0;
                smsLog.HealthFacilitiesId      = (infoInput.healthFacilitiesId != null ? infoInput.healthFacilitiesId.Value : 0);
                smsLog.SmsTemplateId           = 0;
                smsLog.SmsPackagesDistributeId = 0;
                smsLog.SentDate                = DateTime.Now;
                smsLog.LogType                 = 1;

                lstSmsLog.Add(smsLog);
            }

            _context.InsertRange(lstSmsLog);
        }
コード例 #4
0
ファイル: StudentController.cs プロジェクト: kylin589/EmePro
        private void SendSms(StudentDto studentDto)
        {
            var logs = SmsLogsBll.GetLogs(studentDto.UserName, DateTime.Today);
            if (logs.Any()) return;

            var sa = StudentBLL.GetSaInfoByUserName(studentDto.UserName);
            var workTime = UserBLL.GetUserWorkTimeByUserId(sa.UserId, DateTime.Today);
            if (workTime != null)
            {
                var strBuilder = new StringBuilder();
                foreach (var bookRecordDto in studentDto.BookRecords)
                {
                    strBuilder.AppendFormat(Global.WelcomeSmsCourseTemplate, bookRecordDto.CourseEName,
                        bookRecordDto.ArrangeCourseBeginTime, bookRecordDto.ClassRoom, bookRecordDto.TeacherName);
                }
                string smsContent = string.Format(Global.WelcomeSmsTemplate, studentDto.CName, studentDto.CC) + strBuilder;
                var smsApi = new Api.Invoke.Sms.SmsApi();
                var recordId = Guid.NewGuid().ToString();
                var smsResults = smsApi.Send(sa.Mobile, smsContent, recordId);//发送短信
                if (smsResults == null) throw new InvalidOperationException();
                var log = new SmsLogs();
                log.SmsRecordId = recordId;
                log.CreateDateTime = DateTime.Now;
                log.FromUserName = studentDto.UserName;
                log.ToUserName = sa.User.UserName;
                log.SendToPhone = sa.Mobile;
                log.SmsContentType = (int)SmsLogContentType.WelcomeSms;
                log.SmsContent = smsResults.Code == 0
                    ? smsContent
                    : string.Format("SMS Failure,Code:{0},ErrorMsg:{1}", smsResults.Code, smsResults.Msg);
                SmsLogsBll.AddLog(log);
            }
        }
コード例 #5
0
        public static string SaveInfoSMS(string configuration, List <SmsRespone> resps, int type)
        {
            DbContext      _context   = new MySqlContext(new MySqlConnectionFactory(configuration));
            List <SmsLogs> lstSmsLog  = new List <SmsLogs>();
            List <string>  lstSmsUsed = new List <string>();
            int            fail       = 0;
            string         result     = "";

            foreach (var resp in resps)
            {
                SmsLogs smsLog = new SmsLogs();
                smsLog.PhoneNumber        = resp.PhoneNumber;
                smsLog.Message            = resp.Message;
                smsLog.ResultMessage      = resp.Result;
                smsLog.Status             = resp.Code == 0 ? 0 : 1;
                smsLog.HealthFacilitiesId = resp.HealthFacilitiesId;
                smsLog.SmsTemplateId      = resp.SmsTemplateId;
                //smsLog.SmsTemplateCode = resp.SmsTemplateCode;
                smsLog.SmsPackagesDistributeId = resp.SmsPackagesDistributeId;
                smsLog.SentDate   = DateTime.Now;
                smsLog.LogType    = 1;
                smsLog.Telco      = resp.Telco;
                smsLog.ObjectId   = resp.PatientId;
                smsLog.ObjectType = resp.ObjectType;
                lstSmsLog.Add(smsLog);

                result = resp.Result;
                if (resp.Code == 0)
                {
                    fail++;
                }
                if (lstSmsUsed.IndexOf(resp.SmsPackageUsedId.ToString()) < 0 && resp.Code != 0)//
                {
                    lstSmsUsed.Add(resp.SmsPackageUsedId.ToString());
                }
                if (type == 1)
                {
                    _context.Update <MedicalHealthcareHistories>(m => m.PatientHistoriesId == resp.PatientHistoriesId, a => new MedicalHealthcareHistories
                    {
                        IsReExamination = true
                    });
                }
                else if (type == 2)
                {
                    _context.Update <MedicalHealthcareHistories>(m => m.PatientHistoriesId == resp.PatientHistoriesId, a => new MedicalHealthcareHistories
                    {
                        IsBirthDay = true
                    });
                }
            }

            foreach (string smsUsedId in lstSmsUsed)
            {
                int totalSms = 0;

                foreach (var resp in resps)
                {
                    if (smsUsedId == resp.SmsPackageUsedId.ToString())
                    {
                        totalSms++;
                    }
                }

                _context.Update <SmsPackageUsed>(u => u.SmsPackageUsedId == int.Parse(smsUsedId), pu => new SmsPackageUsed
                {
                    Quantityused = pu.Quantityused - totalSms
                });
            }

            _context.InsertRange(lstSmsLog);

            return("Tổng số SMS đã gửi/Số sms gửi lỗi:  " + resps.Count + "/" + fail + "<br> Thông tin lỗi: " + result);
        }