Ejemplo n.º 1
0
        public async Task <JsonResult> AddTender([FromBody] AddTenderModel data)
        {
            try
            {
                bool   returnStat = false;
                string returnMsg  = String.Empty;
                var    resData    = await _paymentManager.AddTender(data);

                if (resData.Success)
                {
                    returnStat = true;
                }
                else
                {
                    returnMsg = resData.Error.Message;
                }

                return(Json(new AjaxResponse(new { success = returnStat, message = returnMsg })));
            }
            catch (UserFriendlyException ex)
            {
                Log.Error(nameof(PaymentController), ex);
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }
Ejemplo n.º 2
0
        //public async Task<AjaxResponse> AddPayment(Accounting.Payment.Model.AddPayment input)
        //{
        //    try
        //    {
        //        Payment.Repo.PAYMENTHDR paymentHDRLogic = new Payment.Repo.PAYMENTHDR(_env, _connectionString);
        //        Payment.Repo.PAYMENTDTL paymentDTLLogic = new Payment.Repo.PAYMENTDTL(_env, _connectionString);
        //        Payment.Repo.PAYMENTTENDER paymentTenderLogic = new Payment.Repo.PAYMENTTENDER(_env, _connectionString);
        //        Payment.Repo.PAYMENTLOG paymentLogLogic = new Payment.Repo.PAYMENTLOG(_env, _connectionString);
        //        Payment.Repo.TENDERTYPE tenderTypeLogic = new Payment.Repo.TENDERTYPE(_env, _connectionString);
        //        Core.General.Repo.CODEMASTER codemasterLogic = new Core.General.Repo.CODEMASTER(_env, _connectionString);

        //        DTO.Payment.PAYMENTHDR dataMapPaymentHDR = _objectMapper.Map<DTO.Payment.PAYMENTHDR>(input.PaymentHDR);
        //        IList<DTO.Payment.PAYMENTDTL> dataMapPaymentDTL = _objectMapper.Map<IList<DTO.Payment.PAYMENTDTL>>(input.PaymentDTL);
        //        DTO.Payment.PAYMENTTENDER dataMapPaymentTender = _objectMapper.Map<DTO.Payment.PAYMENTTENDER>(input.PaymentTender);
        //        DTO.Payment.PAYMENTLOG dataMapPaymentLog = _objectMapper.Map<DTO.Payment.PAYMENTLOG>(input.PaymentTender);

        //        using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
        //        {
        //            try
        //            {
        //                // PaymentHDR
        //                DTO.Payment.PAYMENTHDR contPaymentHDR = paymentHDRLogic.Retrieve(x => x.PaymentTransID == dataMapPaymentHDR.PaymentTransID);
        //                if (contPaymentHDR == null)
        //                {
        //                    await paymentHDRLogic.Create(dataMapPaymentHDR);
        //                }
        //                else
        //                {
        //                    await paymentHDRLogic.Update(dataMapPaymentHDR);
        //                }

        //                // PaymentDTL
        //                DTO.Payment.PAYMENTDTL contPaymentDTL;
        //                foreach (var index in dataMapPaymentDTL)
        //                {
        //                    contPaymentDTL = paymentDTLLogic.Retrieve(x => x.PaymentTransID == index.PaymentTransID && x.TransRef == index.TransRef && x.SeqNo == index.SeqNo);
        //                    if (contPaymentDTL == null)
        //                    {
        //                        await paymentDTLLogic.Create(index);
        //                    }
        //                }

        //                using (TransactionScope scope_tender = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled))
        //                {
        //                    try
        //                    {
        //                        // PaymentTender
        //                        var contPaymentTender = paymentTenderLogic.Retrieve(x => x.PaymentTransID == dataMapPaymentTender.PaymentTransID && x.TenderID == dataMapPaymentTender.TenderID && x.SeqNo == dataMapPaymentTender.SeqNo);
        //                        if (contPaymentHDR == null)
        //                        {
        //                            await paymentTenderLogic.Create(dataMapPaymentTender);
        //                        }

        //                        // Payment Log
        //                        var contPaymentLog = paymentLogLogic.Retrieve(x => x.PaymentTransID == dataMapPaymentLog.PaymentTransID && x.TenderID == dataMapPaymentLog.TenderID && x.SeqNo == dataMapPaymentLog.SeqNo);
        //                        if (contPaymentLog == null)
        //                        {
        //                            await paymentLogLogic.Create(dataMapPaymentLog);
        //                        }

        //                        scope_tender.Complete();
        //                    }
        //                    catch (Exception ex)
        //                    {
        //                        throw ex;
        //                    }
        //                }

        //                scope.Complete();
        //            }
        //            catch(Exception ex)
        //            {
        //                throw ex;
        //            }
        //        }

        //        return new AjaxResponse(new { success = true, message = "" });
        //    }
        //    catch(Exception ex)
        //    {
        //        string exMsg = ex.Message.ToString();
        //        return null;
        //    }
        //}

        //public async Task<AjaxResponse> UpdatePayment(string PaymentTransID, string RefID)
        //{
        //    try
        //    {
        //        var contPaymentTransID = PaymentTransID;
        //        var contRefID = RefID;
        //        Payment.Repo.PAYMENTHDR paymentHDRLogic = new Payment.Repo.PAYMENTHDR(_env, _connectionString);
        //        Payment.Repo.PAYMENTDTL paymentDTLLogic = new Payment.Repo.PAYMENTDTL(_env, _connectionString);
        //        Payment.Repo.PAYMENTTENDER paymentTenderLogic = new Payment.Repo.PAYMENTTENDER(_env, _connectionString);
        //        Payment.Repo.PAYMENTLOG paymentLogLogic = new Payment.Repo.PAYMENTLOG(_env, _connectionString);

        //        return new AjaxResponse(new { success = true, message = "" });
        //    }
        //    catch (Exception ex)
        //    {
        //        string exMsg = ex.Message.ToString();
        //        return null;
        //    }
        //}

        //public async Task<AjaxResponse> CheckPayment(string PaymentTransID, string RefID)
        //{
        //    try
        //    {
        //        var contPaymentTransID = PaymentTransID;
        //        var contRefID = RefID;
        //        Payment.Repo.PAYMENTHDR paymentHDRLogic = new Payment.Repo.PAYMENTHDR(_env, _connectionString);
        //        Payment.Repo.PAYMENTTENDER paymentTenderLogic = new Payment.Repo.PAYMENTTENDER(_env, _connectionString);
        //        Payment.Repo.TENDERTYPE tenderTypeLogic = new Payment.Repo.TENDERTYPE(_env, _connectionString);

        //        DTO.Payment.PAYMENTHDR contPaymentHDR = paymentHDRLogic.Retrieve(x => x.PaymentTransID == contPaymentTransID);
        //        IList<DTO.Payment.PAYMENTTENDER> contPaymentTender;
        //        DTO.Payment.TENDERTYPE contTenderType;
        //        if (contPaymentTransID != null)
        //        {
        //            contPaymentTender = paymentTenderLogic.RetrieveAll(x => x.PaymentTransID == contPaymentTransID);
        //            if (contPaymentTender != null)
        //            {
        //                foreach (DTO.Payment.PAYMENTTENDER index in contPaymentTender)
        //                {
        //                    contTenderType = tenderTypeLogic.Retrieve(x => x.TenderCode == index.TenderCode);
        //                    if (contTenderType != null)
        //                    {
        //                        // Check Payment by Each Tender
        //                    }
        //                }
        //            }
        //        }

        //        return new AjaxResponse(new { success = true, message = "" });
        //    }
        //    catch (Exception ex)
        //    {
        //        string exMsg = ex.Message.ToString();
        //        return null;
        //    }
        //}

        //public async Task<AjaxResponse> ReceivedResponsePayment(string PaymentTransID, string PaymentType)
        //{
        //    try
        //    {
        //        return new AjaxResponse(new { success = true, message = "" });
        //    }
        //    catch (Exception ex)
        //    {
        //        string exMsg = ex.Message.ToString();
        //        return null;
        //    }
        //}

        //public async Task<AjaxResponse> GetPayment(string PaymentTransID, string RefID)
        //{
        //    try
        //    {
        //        return new AjaxResponse(new { success = true, message = "" });
        //    }
        //    catch (Exception ex)
        //    {
        //        string exMsg = ex.Message.ToString();
        //        return null;
        //    }
        //}

        public async Task <AjaxResponse> AddTender(AddTenderModel input)
        {
            try
            {
                bool                      paymentSuccess     = false;
                PAYMENTTENDER             paymentTenderLogic = new PAYMENTTENDER(_env, _connectionString);
                PAYMENTLOG                paymentLogLogic    = new PAYMENTLOG(_env, _connectionString);
                DTO.Payment.PAYMENTTENDER contPaymentTender;
                DTO.Payment.PAYMENTLOG    contPaymentLog;

                IList <DTO.Payment.PAYMENTTENDER> dataPaymentTender = _objectMapper.Map <IList <DTO.Payment.PAYMENTTENDER> >(input.PaymentTender);
                IList <DTO.Payment.PAYMENTLOG>    dataPaymentLog    = _objectMapper.Map <IList <DTO.Payment.PAYMENTLOG> >(input.PaymentLog);

                foreach (var idxTender in dataPaymentTender)
                {
                    var idxTenderPaymentTransID = idxTender.PaymentTransID;
                    var idxTenderTenderID       = idxTender.TenderID;
                    var idxTenderTenderCode     = idxTender.TenderCode;

                    contPaymentTender = paymentTenderLogic.Retrieve(x => x.PaymentTransID == idxTenderPaymentTransID && x.TenderID == idxTenderTenderID && x.TenderCode == idxTenderTenderCode);
                    if (contPaymentTender != null)
                    {
                        return(new AjaxResponse(new ErrorInfo("Tender Data Already Exist")));
                    }
                    else
                    {
                        using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                        {
                            try
                            {
                                await paymentTenderLogic.Create(idxTender);

                                var seqNo = 1;
                                foreach (var idxLog in dataPaymentLog)
                                {
                                    var idxLogPaymentTransID = idxLog.PaymentTransID;
                                    var idxLogTenderID       = idxLog.TenderID;
                                    var idxLogTenderCode     = idxLog.TenderCode;
                                    var idxLogSeqNo          = seqNo;

                                    contPaymentLog = paymentLogLogic.Retrieve(x => x.PaymentTransID == idxLogPaymentTransID && x.TenderID == idxLogTenderID && x.TenderCode == idxLogTenderCode && x.SeqNo == idxLogSeqNo);
                                    if (contPaymentLog != null)
                                    {
                                        return(new AjaxResponse(new ErrorInfo("Tender Log Already Exist")));
                                    }
                                    else
                                    {
                                        using (TransactionScope scopeLog = new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled))
                                        {
                                            try
                                            {
                                                await paymentLogLogic.Create(idxLog);

                                                paymentSuccess = true;
                                                scopeLog.Complete();
                                            }
                                            catch (Exception ex)
                                            {
                                                throw ex;
                                            }
                                        }
                                        scope.Complete();
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                    }
                }
                return(new AjaxResponse(paymentSuccess));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }