/// <summary> /// Sends SMS message /// </summary> /// <param name="telephone">Telephone number activated</param> /// <returns>Response code from modem</returns> private ResponseCode SendSms(string telephone) { //var e = ExecCommand("AT+CSCA?", Timeout, new[] { ResponseCode.OK, ResponseCode.ERROR }).Code; Logger.Write(String.Format(ResourceManagerProvider.GetLocalizedString("MSG_COMMAND_SMS_EXECUTING", Application.CurrentCulture), telephone)); // Select SMS text mode var res = ExecCommand("AT+CMGF=1", TimeoutCommand, new[] { ResponseCode.OK, ResponseCode.ERROR }).Code; if (res == ResponseCode.OK) { res = ExecCommand(String.Format("AT+CMGS=\"{0}\"", SmsRecipient), TimeoutCommand, new[] { ResponseCode.SMS_TEXT, ResponseCode.ERROR }).Code; if (res == ResponseCode.SMS_TEXT) { var smsText = SmsText.Replace("%PHONE%", telephone); // m_port.WriteLine(m_CurTelephone + System.Environment.NewLine + (char)(26)); //return ExecCommand(telephone + char.ConvertFromUtf32(26) + "\r", 10000, new ResponseCode[] { ResponseCode.OK }); // Ctrl+z is used on keyboard to send filled up text res = ExecCommand(smsText + char.ConvertFromUtf32(26), TimeoutSms, new[] { ResponseCode.OK, ResponseCode.SMS, ResponseCode.ERROR }).Code; if (res == ResponseCode.TIMEOUT) { res = ResponseCode.OK; Logger.Write(String.Format(ResourceManagerProvider.GetLocalizedString("MSG_COMMAND_RESPONSE_CODE_CHANGED", Application.CurrentCulture), res)); } } } else if (res == ResponseCode.TIMEOUT) { res = ResponseCode.ERROR; Logger.Write(String.Format(ResourceManagerProvider.GetLocalizedString("MSG_COMMAND_RESPONSE_CODE_CHANGED", Application.CurrentCulture), res)); } //e = ExecCommand("AT+CMEE=305", Timeout, new[] { ResponseCode.OK, ResponseCode.ERROR }).Code; return(res); }
public JsonResult Save(SmsTextViewModel model) { Response response; var currentUser = GetAuthenticatedUser(); try { using (var db = new KiaGalleryContext()) { if (model.id > 0 && model.id != null) { var entity = db.SmsText.Single(x => x.Id == model.id); entity.Title = model.title; entity.Active = model.active; entity.Text = model.text; entity.UrlKey = model.urlKey; entity.SmsCategoryId = model.smsCategoryId; entity.Order = model.order; entity.ModifyDate = DateTime.Now; entity.ModifyUserId = currentUser.Id; entity.Ip = Request.UserHostAddress; db.SaveChanges(); response = new Response() { status = 200, message = "پیام با موفقیت ویرایش شد." }; } else { var entity = new SmsText() { Title = model.title, Text = model.text, UrlKey = model.urlKey, SmsCategoryId = model.smsCategoryId, Order = model.order, Active = model.active, CreateDate = DateTime.Now, ModifyDate = DateTime.Now, CreateUserId = currentUser.Id, ModifyUserId = currentUser.Id, Ip = Request.UserHostAddress }; db.SmsText.Add(entity); db.SaveChanges(); response = new Response() { status = 200, message = "پیام با موفقیت ایجاد شد." }; } } } catch (Exception ex) { response = Core.GetExceptionResponse(ex); } return(Json(response, JsonRequestBehavior.AllowGet)); }