public ActionResult ChannelSettings(int?spId, int?serviceId, int?instructionId, int?channelId) { string serviceNumber = string.Empty; if (serviceId.HasValue && !instructionId.HasValue && !channelId.HasValue) { var smsSvc = this.SMSUIService.Single <ShortMessageService>(x => x.Id == serviceId); var smsChannel = this.SMSUIService.Single <SMSChannel>(x => x.ServiceId == serviceId); serviceNumber = smsSvc.ServiceNumber; if (smsChannel == null) { SMSChannel channel = new SMSChannel { ServiceId = serviceId.GetValueOrDefault(), ServiceNumber = smsSvc.ServiceNumber, }; this.SMSUIService.Add <SMSChannel>(channel); channelId = channel.Id; } else { channelId = smsChannel.Id; } } if (!serviceId.HasValue && !instructionId.HasValue && channelId.HasValue) { var smsChannel = this.SMSUIService.Single <SMSChannel>(channelId.GetValueOrDefault()); serviceId = smsChannel.ServiceId; var smsSvc = this.SMSUIService.Single <ShortMessageService>(x => x.Id == serviceId); serviceNumber = smsSvc.ServiceNumber; spId = smsSvc.SpId; } ViewData["ServiceNumber"] = serviceNumber; ViewData["SPId"] = spId; ViewData["ServiceId"] = serviceId.GetValueOrDefault(); ViewData["ChannelId"] = channelId.GetValueOrDefault(); var models = this.SMSUIService.Find <SMSChannelSetting>(x => x.ChannelId == channelId.GetValueOrDefault()).ToList(); if (instructionId.HasValue) { models = this.SMSUIService.Find <SMSChannelSetting>(x => x.InstructionId == instructionId.GetValueOrDefault()).ToList(); var instruction = this.SMSUIService.Single <Instruction>(instructionId.GetValueOrDefault()); var service = this.SMSUIService.Single <ShortMessageService>(instruction.ServiceId); ViewData["ServiceNumber"] = instruction.Code; ViewData["SPId"] = service.SpId; ViewData["ServiceId"] = service.Id; ViewData["InstructionId"] = instructionId.GetValueOrDefault(); } return(View(models)); }
public ChannelResult QueryChannel(string imsi, string mobile, ServiceType serviceType, float?amount, string userNo) { ChannelResult result = null; List <ShortMessageService> services = new List <ShortMessageService>(); var mobileInfo = this.GetMobileInfoByPhoneNumber(mobile); IList <ShortMessageService> smsServices; if (serviceType == ServiceType.SMS) { smsServices = this.Find <ShortMessageService>(s => s.Type == serviceType); } else { if (mobileInfo == null) { result = new ChannelResult { Status = ChannelRequestStatus.MissingMobileInfo }; return(result); } // filter by operator switch (mobileInfo.OperatorId) { case 1: smsServices = this.Find <ShortMessageService>(s => s.Type == serviceType && s.IsMobile == true); break; case 2: smsServices = this.Find <ShortMessageService>(s => s.Type == serviceType && s.IsUnicom == true); break; case 3: smsServices = this.Find <ShortMessageService>(s => s.Type == serviceType && s.IsTelcom == true); break; default: smsServices = this.Find <ShortMessageService>(s => s.Type == serviceType); break; } } if (smsServices != null && smsServices.Count > 0) { services = smsServices.ToList(); ShortMessageService service = new ShortMessageService(); Instruction selectedInstruction = new Instruction(); SMSChannel channel = new SMSChannel(); ServiceProvider sp = new ServiceProvider(); for (int i = 0; i < services.Count; i++) { service = services[i]; sp = this.Single <ServiceProvider>(x => x.Id == service.SpId); // TODO: check channel restriction here if (!service.IsManully) { var instructions = this.Find <Instruction>(s => s.ServiceId == service.Id); channel = this.Single <SMSChannel>(x => x.ServiceId == service.Id); // TODO: check instruction restriction here if (instructions != null && instructions.Count > 0) { selectedInstruction = instructions[0]; result = new ChannelResult(); result.ServiceNumber = service.ServiceNumber; result.Code = instructions[0].Code; break; } } else { switch (sp.DynamicSP) { case DynamicSP.CTU: return(CTUSMSPayRequest(amount.GetValueOrDefault(), userNo, mobileInfo, service.Id, sp.Id, mobile)); } } } if (serviceType == ServiceType.SMSCharge && selectedInstruction != null && channel != null && result != null) { // create order var orderNo = PaymentsService.CreateOrder("[短代]", selectedInstruction.Amount, "短信充值:" + selectedInstruction.Amount.ToString(), mobile); result.OrderNo = orderNo; // initial channel log if (mobileInfo == null) { mobileInfo = new MobileInfo(); } SMSChannelLog log = new SMSChannelLog { Amount = selectedInstruction.Amount, ChargeStatus = SMSChargeStatus.Initial, CityId = mobileInfo.CityId, OpId = mobileInfo.OperatorId, ProvinceId = mobileInfo.ProvinceId, ServiceNumber = result.ServiceNumber, Instruction = result.Code, Mobile = mobile, IMSI = GetIMSI(mobile), OrderNo = orderNo }; this.AddLog <SMSChannelLog>(log); result.LogId = log.ID; // set channel setting if (channel != null) { var settings = this.Find <SMSChannelSetting>(x => x.ChannelId == channel.Id); if (settings != null && settings.Count > 0) { result.SMSChannelSetting = settings[0]; } } } } return(result); }