public int Save(ServiceProvider entity) { ValidationResultInfo vri = Validate(entity); if (!vri.IsValid) { throw new DomainValidationException(vri, "Product Details provided not valid"); } DateTime date = DateTime.Now; tblServiceProvider tbl = _ctx.tblServiceProvider.FirstOrDefault(s => s.Id == entity.Id); if (tbl == null) { tbl = new tblServiceProvider (); tbl.IM_DateCreated = date; tbl.IM_IsActive = true; _ctx.tblServiceProvider.Add(tbl); } tbl.IM_DateUpdated = date; tbl.AllowOverPayment= entity.AllowOverPayment; tbl.AllowPartialPayment = entity.AllowPartialPayment; tbl.Currecy = entity.Currency; tbl.SDP_APP_ID = entity.SdpAppId; tbl.SDP_Password = entity.SdpPassword; tbl.SPCode = entity.Code; tbl.SPId = entity.Sid; tbl.SPName = entity.Name; tbl.SubscriberId = entity.SubscriberId; tbl.SmsShortCode = entity.SmsShortCode; _ctx.SaveChanges(); _cacheProvider.Put(_cacheListKey, _ctx.tblServiceProvider.Where(x => x.IM_IsActive).Select(s => s.Id).ToList()); _cacheProvider.Remove(string.Format(_cacheKey, tbl.Id)); return tbl.Id; }
public ValidationResultInfo Validate(ServiceProvider objToValidate) { ValidationResultInfo vri = objToValidate.BasicValidation(); //bool hasDuplicateAppId = GetAll().Where(v => v.Id != objToValidate.Id) // .Any(p => p.SdpAppId == objToValidate.SdpAppId); //if (hasDuplicateAppId) // vri.Results.Add(new ValidationResult("Duplicate Applicatin ID Found")); bool hasDuplicateServiceAppId = GetAll().Where(v => v.Id != objToValidate.Id) .Any(p => p.Sid == objToValidate.Sid); if (hasDuplicateServiceAppId) vri.Results.Add(new ValidationResult("Duplicate Service Provider ID Found")); return vri; }
public ActionResult Edit(ServiceProvider model) { try { _serviceProvider.Save(model); } catch (DomainValidationException dve) { ValidationSummary.DisplayDomainValidationResult(dve, ModelState); return View(model); } catch (Exception ex) { ValidationSummary.DisplayValidationResult(ex.Message, ModelState); return View(model); } return RedirectToAction("Index"); }
public void ProcessClientRequest(ClientRequestResponseBase crrMessage, ServiceProvider serviceProvider, out ServerRequestBase serverReqBase) { if (crrMessage == null) { throw new Exception("Message null"); } serverReqBase = new ServerRequestBase(); string userName = ""; string password = "******"; string subscriberId = "tel:254701234563"; string applicationId = "APP_000007"; bool allowOverPayment = true, allowPartialPayment = true; string version = "1.0"; string sourcesAddress = "hewani"; string binaryHeader = "Content-Type:application/json"; if (serviceProvider != null) { applicationId = serviceProvider.SdpAppId; subscriberId = serviceProvider.SubscriberId; password = serviceProvider.SdpPassword; allowOverPayment = serviceProvider.AllowOverPayment; allowPartialPayment = serviceProvider.AllowPartialPayment; } else { throw new Exception("This service provider is not registered."); } // if (crrMessage is PaymentInstrumentRequest) { PaymentInstrumentRequest pir = crrMessage as PaymentInstrumentRequest; SDPPaymentInstrumentRequest paymentIstReq = new SDPPaymentInstrumentRequest { applicationId = applicationId, password = password, type = pir.paymentInstrumentType, //subscriberId = subscriberId subscriberId = pir.SubscriberId }; serverReqBase = paymentIstReq; } if (crrMessage is PaymentRequest) { PaymentRequest apr = crrMessage as PaymentRequest; SDPPaymentRequest sdpapr = new SDPPaymentRequest(); sdpapr.accountId = apr.AccountId.ToString(); sdpapr.allowOverPayments = allowOverPayment ? AllOverPayment.Allow.ToString() : AllOverPayment.Disallow.ToString(); sdpapr.allowPartialPayments = allowPartialPayment ? AllowPartialPayments.Allow.ToString() : AllowPartialPayments.Disallow.ToString(); sdpapr.amount = apr.Amount.ToString(); sdpapr.applicationId = applicationId; sdpapr.currency = apr.Currency; sdpapr.externalTrxId = apr.TransactionRefId.Replace("-",""); sdpapr.extra = apr.Extra; //new Dictionary<string, string>();// {new string("tilNo","66363" )}; // sdpapr.extra.Add("tillNo","66361"); sdpapr.invoiceNo = apr.InvoiceNumber; sdpapr.orderNo = apr.OrderNumber; sdpapr.password = password; sdpapr.paymentInstrumentName = apr.PaymentInstrumentName; //sdpapr.subscriberId = subscriberId; sdpapr.subscriberId = apr.SubscriberId; sdpapr.smsDescription = apr.smsDescription; serverReqBase = sdpapr; } if (crrMessage is PaymentQueryRequest) { PaymentQueryRequest apq = crrMessage as PaymentQueryRequest; SDPPaymentQueryRequest sdpapq = new SDPPaymentQueryRequest(); sdpapq.applicationId = applicationId; sdpapq.internalTrxId = apq.TransactionRefId.ToString(); sdpapq.password = password; serverReqBase = sdpapq; } if(crrMessage is DocSMS) { DocSMS sms = crrMessage as DocSMS; SDPSMSRequest reqSMS = new SDPSMSRequest { applicationId = applicationId, password = password, destinationAddresses = sms.Recipitents.Select(n => "tel:" + n).ToList(), deliveryStatusRequest = 1, encoding = SDPSmsEncoding.Text, message = sms.SmsBody, }; } }