public async Task <ActionResult <dtoSmsCampaigin> > PostSmsInfo(dtoSmsCampaigin p_SmsCampaigin) { int ClientSmsLimit = 0; long recipientsCount = 0; if (ModelState.IsValid) { SmsCampaign newSmsCampaign = GetSmsCampaignFromSmsc(p_SmsCampaigin); //get sms limit info ClientSmsLimit = _smsInfo.SmsLimitInfo("KB" + _CurrentUserCompanyID().ToString(), _CurrentUserCompanyTaxID()); recipientsCount = newSmsCampaign.RecipientsCount; } return(Json(new { limit = ClientSmsLimit, recipients = recipientsCount })); }
private SmsCampaign GetSmsCampaignFromSmsc(dtoSmsCampaigin p_SmsCampaigin) { SmsCampaign newSmsCampaign = new SmsCampaign(); newSmsCampaign.Company.Id = _CurrentUserCompanyID(); newSmsCampaign.AppUser.Id = _CurrentUserID(); newSmsCampaign.MsgTxt = p_SmsCampaigin.MsgTxt; newSmsCampaign.SendAfter = p_SmsCampaigin.SendAfter; newSmsCampaign.Name = ""; switch (p_SmsCampaigin.CampaignType) { case 0: //individual recipients (ClientIDs) foreach (string item in p_SmsCampaigin.Recipients) { Client client = _context.Clients.Where(a => a.CompanyId == _CurrentUserCompanyID() && a.Id == long.Parse(item) && a.Mobile != null && a.AllowsSMS == true).SingleOrDefault(); if (client != null) { newSmsCampaign.Recipients.Add(new SmsMsg(client.Mobile)); } } break; case 1: //recipients by location foreach (string item in p_SmsCampaigin.Recipients) { foreach (Client client in _context.Clients.Where(a => a.CompanyId == _CurrentUserCompanyID() && a.LocationId == long.Parse(item) && a.Mobile != null && a.AllowsSMS == true)) { newSmsCampaign.Recipients.Add(new SmsMsg(client.Mobile)); } } break; case 2: //recipients by sex foreach (Client client in _context.Clients.Where(a => a.CompanyId == _CurrentUserCompanyID() && a.Sex == p_SmsCampaigin.Recipients.ToArray()[0] && a.Mobile != null && a.AllowsSMS == true)) { newSmsCampaign.Recipients.Add(new SmsMsg(client.Mobile)); } break; default: break; } return(newSmsCampaign); }
public SmsCampaignViewModel(SmsCampaign obj, string connectionString) { context = new MySqlContext(new MySqlConnectionFactory(connectionString)); CampaignId = obj.CampaignId; CampaignName = obj.CampaignName; SendType = obj.SendType; SendDate = obj.SendDate; SendHour = obj.SendHour; SendMinute = obj.SendMinute; IsDelete = obj.IsDelete; Status = obj.Status; HealthFacilities = context.Query <HealthFacilities>().Where(h => h.HealthFacilitiesId == obj.HealthFacilitiesId && h.IsDelete == false && h.IsActive == true).FirstOrDefault(); MessageType = context.Query <CategoryCommon>().Where(cc => cc.Code.Equals("CSKH") && cc.Type.Equals("LOAITINNHAN") && cc.IsDelete == false && cc.IsActive == true).FirstOrDefault(); SmsBrand = context.Query <SmsBrand>().Where(sb => sb.SmsBrandId == obj.SmsBrandId && sb.IsDelete == false && sb.IsActive == true).FirstOrDefault(); SmsPackageUsed = context.Query <SmsPackageUsed>() //.Where(spu => spu.SmsPackageDistributeId == obj.Sms && spu.IsDelete==false) .OrderByDesc(spu => spu.CreateDate).ToList(); //Lấy tổng số sms còn lại SmsContent = context.Query <SmsTemplate>() .Where(st => st.SmsTemplateCode == obj.SmsContent && st.IsDelete == false && st.IsActive == true).FirstOrDefault(); var campaignDetails = context.Query <SmsCampaign>() .Where(sc => sc.CampaignId == obj.CampaignId && sc.IsDelete == false) .InnerJoin <SmsCampaignDetail>((sc, scd) => sc.CampaignId == scd.CampaignlId && IsDelete == false); CampaignDetails = new List <SmsCampaignDetail>(); foreach (var item in campaignDetails.Select((sc, scd) => scd).ToList()) { CampaignDetails.Add(item); } }
/// <summary> /// Create new sms campaign Create a new sms campaign /// </summary> /// <exception cref="org.egoi.client.api.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="smsCampaign">Parameters for the Sms Campaign</param> /// <param name="cancellationToken">Cancellation Token to cancel request (optional) </param> /// <returns>Task of ApiResponse (HashcodeCampaign)</returns> public async System.Threading.Tasks.Task <ApiResponse <HashcodeCampaign> > CreateSmsCampaignWithHttpInfoAsync(SmsCampaign smsCampaign, CancellationToken cancellationToken = default(CancellationToken)) { // verify the required parameter 'smsCampaign' is set if (smsCampaign == null) { throw new ApiException(400, "Missing required parameter 'smsCampaign' when calling SmsApi->CreateSmsCampaign"); } var localVarPath = "/campaigns/sms"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new List <KeyValuePair <String, String> >(); var localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json" }; String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json" }; String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (smsCampaign != null && smsCampaign.GetType() != typeof(byte[])) { localVarPostBody = this.Configuration.ApiClient.Serialize(smsCampaign); // http body (model) parameter } else { localVarPostBody = smsCampaign; // byte array } // authentication (Apikey) required if (!String.IsNullOrEmpty(this.Configuration.GetApiKeyWithPrefix("Apikey"))) { localVarHeaderParams["Apikey"] = this.Configuration.GetApiKeyWithPrefix("Apikey"); } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType, cancellationToken); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("CreateSmsCampaign", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <HashcodeCampaign>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)), (HashcodeCampaign)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(HashcodeCampaign)))); }
/// <summary> /// Create new sms campaign Create a new sms campaign /// </summary> /// <exception cref="org.egoi.client.api.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="smsCampaign">Parameters for the Sms Campaign</param> /// <param name="cancellationToken">Cancellation Token to cancel request (optional) </param> /// <returns>Task of HashcodeCampaign</returns> public async System.Threading.Tasks.Task <HashcodeCampaign> CreateSmsCampaignAsync(SmsCampaign smsCampaign, CancellationToken cancellationToken = default(CancellationToken)) { ApiResponse <HashcodeCampaign> localVarResponse = await CreateSmsCampaignWithHttpInfoAsync(smsCampaign, cancellationToken); return(localVarResponse.Data); }
/// <summary> /// Create new sms campaign Create a new sms campaign /// </summary> /// <exception cref="org.egoi.client.api.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="smsCampaign">Parameters for the Sms Campaign</param> /// <returns>HashcodeCampaign</returns> public HashcodeCampaign CreateSmsCampaign(SmsCampaign smsCampaign) { ApiResponse <HashcodeCampaign> localVarResponse = CreateSmsCampaignWithHttpInfo(smsCampaign); return(localVarResponse.Data); }
public IActionResult Update(int id, SmsCampaign obj) { return(Json(new ActionResultDto())); }
/// <summary> /// Create new sms campaign Create a new sms campaign /// </summary> /// <exception cref="org.egoi.client.api.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="smsCampaign">Parameters for the Sms Campaign</param> /// <returns>Task of HashcodeCampaign</returns> public async System.Threading.Tasks.Task <HashcodeCampaign> CreateSmsCampaignAsync(SmsCampaign smsCampaign) { ApiResponse <HashcodeCampaign> localVarResponse = await CreateSmsCampaignAsyncWithHttpInfo(smsCampaign); return(localVarResponse.Data); }
public async Task <ActionResult <dtoSmsCampaigin> > PostQueueSmsCampaign(dtoSmsCampaigin p_SmsCampaigin) { if (ModelState.IsValid) { SmsCampaign newSmsCampaign = GetSmsCampaignFromSmsc(p_SmsCampaigin); _context.Attach(newSmsCampaign.Company); _context.Attach(newSmsCampaign.AppUser); _context.SmsCampaigns.Add(newSmsCampaign); string AppBaseUrl = Request.Scheme + @"://" + Request.Host + Request.PathBase; string myWhen = ""; if (newSmsCampaign.SendAfter.HasValue == true) { if (newSmsCampaign.SendAfter.Value < DateTime.Now) { myWhen = "takoj"; } else { string dowName = ""; switch (newSmsCampaign.SendAfter.Value.ToLocalTime().Date.DayOfWeek) { case DayOfWeek.Sunday: dowName = "v nedeljo"; break; case DayOfWeek.Monday: dowName = "v ponedeljek"; break; case DayOfWeek.Tuesday: dowName = "v torek"; break; case DayOfWeek.Wednesday: dowName = "v sredo"; break; case DayOfWeek.Thursday: dowName = "v četrtek"; break; case DayOfWeek.Friday: dowName = "v petek"; break; case DayOfWeek.Saturday: dowName = "v soboto"; break; default: dowName = "?"; break; } if (newSmsCampaign.SendAfter.Value.Date == DateTime.UtcNow.Date) { myWhen = "danes"; } if (newSmsCampaign.SendAfter.Value.Date == DateTime.UtcNow.AddDays(1).Date) { myWhen = "jutri"; } if (newSmsCampaign.SendAfter.Value.Date > DateTime.UtcNow.AddDays(1).Date) { myWhen = newSmsCampaign.SendAfter.Value.Date.ToString("dd.MM.yyyy"); } myWhen += " (" + dowName + ")"; myWhen += " ob " + newSmsCampaign.SendAfter.Value.ToLocalTime().ToShortTimeString(); } } else { myWhen = "Takoj"; } try { await _context.SaveChangesAsync(); //_logger.LogInformation("kampanija shranjena, sedaj pa še pošljem mail na naslov " + _CurrentUserEmail()); //notify user string myMail = "<p>Pozdravljeni! <br />SMS sporočila zahtevajo vašo pozornost.<br />"; myMail += "Če potrdite, bo " + myWhen + " poslanih " + newSmsCampaign.RecipientsCount.ToString() + " sporočil:<br />"; myMail += "<pre>" + newSmsCampaign.MsgTxt + "</pre>"; myMail += @"Prosimo, <a href=""" + AppBaseUrl + @"/api/Sms?guid=" + newSmsCampaign.Guid.ToString() + @"&action=approve"" target=""_blank"">POTRDITE</a> "; myMail += @" ali "; myMail += @"<a href=""" + AppBaseUrl + @"/api/Sms?guid=" + newSmsCampaign.Guid.ToString() + @"&action=cancel"" target=""_blank"">PREKLIČITE</a> "; myMail += @" pošiljanje.<br /> Hvala.</p>"; await _emailSender.SendEmailAsync(_CurrentUserEmail(), "SMS obveščanje", myMail); //_logger.LogInformation("mail poslan...?"); } catch (Exception ex) { _logger.LogError(ex, "/api/Sms/QueueSmsCampaign Error"); throw; } } return(Json("OK")); }