Exemplo n.º 1
0
        public bool Remove(int id)
        {
            Payment        payment        = _context.Payment.Where(m => m.Lite_Merchant_Trace == id).FirstOrDefault();
            PaymentAddress paymentAddress = _context.PaymentAddress.Where(m => m.Lite_Merchant_Trace == id).FirstOrDefault();

            if (payment != null)
            {
                _context.Payment.Remove(payment);
                var result = _context.SaveChanges();
            }


            if (paymentAddress != null)
            {
                _context.PaymentAddress.Remove(paymentAddress);
                var result = _context.SaveChanges();
            }


            List <PaymentLists> paymentLists = _context.PaymentLists.Where(m => m.Lite_Merchant_Trace == id).ToList();

            foreach (var listItem in paymentLists)
            {
                _context.PaymentLists.Remove(listItem);
                _context.SaveChanges();
            }

            if (paymentLists.Count > 0)
            {
                PaymentLists           paylist         = paymentLists.FirstOrDefault();
                List <PaymentProducts> paymentProducts = _context.PaymentProducts.Where(m => m.Lite_Merchant_Trace == id && m.PaymentListsId == paylist.PaymentListsId).ToList();
                foreach (var product in paymentProducts)
                {
                    _context.PaymentProducts.Remove(product);
                    _context.SaveChanges();
                }
            }



            return(true);
        }
Exemplo n.º 2
0
        public PaymentLists GetPaymentLists(PaymentListsInputModel model)
        {
            PaymentLists message = new PaymentLists();

            using (var imisContext = new ImisDB())
            {
                int?HFID;
                int?PLServiceID;
                int?PLItemID;

                List <CodeName>      hf               = new List <CodeName>();
                List <CodeNamePrice> plItemsDetail    = new List <CodeNamePrice>();
                List <CodeNamePrice> plServicesDetail = new List <CodeNamePrice>();

                HFID = imisContext.TblClaimAdmin
                       .Where(c => c.ClaimAdminCode == model.claim_administrator_code &&
                              c.ValidityTo == null)
                       .Select(x => x.Hfid).FirstOrDefault();

                PLServiceID = imisContext.TblHf
                              .Where(h => h.HfId == HFID)
                              .Select(x => x.PlserviceId).FirstOrDefault();

                PLItemID = imisContext.TblHf
                           .Where(h => h.HfId == HFID)
                           .Select(x => x.PlitemId).FirstOrDefault();

                hf = imisContext.TblHf
                     .Where(h => h.HfId == HFID)
                     .Select(x => new CodeName()
                {
                    code = x.Hfcode,
                    name = x.Hfname
                }).ToList();

                plItemsDetail = imisContext.TblPlitemsDetail
                                .Join(imisContext.TblItems,
                                      p => p.ItemId,
                                      i => i.ItemId,
                                      (p, i) => new { TblPlitemsDetail = p, TblItems = i })
                                .Where(r => r.TblItems.ValidityTo == null)
                                .Where(r => r.TblPlitemsDetail.PlitemId == PLItemID &&
                                       r.TblPlitemsDetail.ValidityTo == null &&
                                       (model.last_update_date == null || r.TblPlitemsDetail.ValidityFrom >= model.last_update_date))
                                .Select(x => new CodeNamePrice()
                {
                    code  = x.TblItems.ItemCode,
                    name  = x.TblItems.ItemName,
                    price = (x.TblPlitemsDetail.PriceOverule == null) ? x.TblItems.ItemPrice.ToString() : x.TblPlitemsDetail.PriceOverule.ToString()
                }).ToList();

                plServicesDetail = imisContext.TblPlservicesDetail
                                   .Join(imisContext.TblServices,
                                         p => p.ServiceId,
                                         i => i.ServiceId,
                                         (p, i) => new { TblPlservicesDetail = p, TblServices = i })
                                   .Where(r => r.TblServices.ValidityTo == null)
                                   .Where(r => r.TblPlservicesDetail.PlserviceId == PLServiceID &&
                                          r.TblPlservicesDetail.ValidityTo == null &&
                                          (model.last_update_date == null || r.TblPlservicesDetail.ValidityFrom >= model.last_update_date))
                                   .Select(x => new CodeNamePrice()
                {
                    code  = x.TblServices.ServCode,
                    name  = x.TblServices.ServName,
                    price = (x.TblPlservicesDetail.PriceOverule == null) ? x.TblServices.ServPrice.ToString() : x.TblPlservicesDetail.PriceOverule.ToString()
                }).ToList();

                message.health_facility_code = hf.Select(x => x.code).FirstOrDefault();
                message.health_facility_name = hf.Select(x => x.name).FirstOrDefault();

                message.pricelist_items    = plItemsDetail;
                message.pricelist_services = plServicesDetail;
                message.update_since_last  = DateTime.UtcNow;
            }

            return(message);
        }
Exemplo n.º 3
0
        public Resultss Success([FromBody]  PaymentData model)
        {
            Resultss resultss = new Resultss();
            string   s        = "";

            try
            {
                Payment payment = _context.Payment.Where(m => m.Lite_Merchant_Trace == model.PData.Lite_Merchant_Trace).FirstOrDefault();

                if (payment == null)
                {
                    //Mapper.Map(model.PData, payment);
                    _context.Payment.Add(model.PData);
                    var result = _context.SaveChanges();
                }
                else
                {
                    _context.Payment.Remove(payment);
                    _context.SaveChanges();

                    _context.Payment.Add(model.PData);
                    var result = _context.SaveChanges();
                }


                PaymentAddress paymentAddress = _context.PaymentAddress.Where(m => m.Lite_Merchant_Trace == model.PData.Lite_Merchant_Trace).FirstOrDefault();

                if (paymentAddress == null)
                {
                    model.AData.Lite_Merchant_Trace = model.PData.Lite_Merchant_Trace;
                    _context.PaymentAddress.Add(model.AData);
                    var result = _context.SaveChanges();
                }
                else
                {
                    model.AData.Lite_Merchant_Trace = model.PData.Lite_Merchant_Trace;
                    _context.PaymentAddress.Remove(paymentAddress);
                    _context.SaveChanges();

                    model.AData.Lite_Merchant_Trace = model.PData.Lite_Merchant_Trace;
                    _context.PaymentAddress.Add(model.AData);
                    _context.SaveChanges();
                }

                List <PaymentLists> paymentLists = _context.PaymentLists.Where(m => m.Lite_Merchant_Trace == model.PData.Lite_Merchant_Trace).ToList();
                foreach (var listItem in paymentLists)
                {
                    _context.PaymentLists.Remove(listItem);
                    _context.SaveChanges();
                }

                if (paymentLists.Count > 0)
                {
                    PaymentLists           paylist         = paymentLists.FirstOrDefault();
                    List <PaymentProducts> paymentProducts = _context.PaymentProducts.Where(m => m.Lite_Merchant_Trace == model.PData.Lite_Merchant_Trace && m.PaymentListsId == paylist.PaymentListsId).ToList();
                    foreach (var product in paymentProducts)
                    {
                        _context.PaymentProducts.Remove(product);
                        _context.SaveChanges();
                    }
                }



                foreach (var item in model.OData)
                {
                    s = item.Total;

                    if (paymentLists.Count == 0)
                    {
                        PaymentLists paymentL = new PaymentLists {
                            Grade = item.Grade, Lite_Merchant_Trace = model.PData.Lite_Merchant_Trace, NoOfLearners = item.NoOfLearners, Total = Convert.ToDecimal(item.Total)
                        };
                        _context.PaymentLists.Add(paymentL);
                        var result = _context.SaveChanges();



                        List <PaymentProducts> Plist = new List <PaymentProducts>();

                        foreach (var items in item.Products)
                        {
                            PaymentProducts paymentProducts1 = new PaymentProducts()
                            {
                                Grade = items.Grade, Description = items.Description, LineTotal = items.LineTotal, Lite_Merchant_Trace = model.PData.Lite_Merchant_Trace, PaymentListsId = paymentL.PaymentListsId, ProductCode = items.ProductCode, Quantity = items.Quantity, ScoolGradesListID = items.ScoolGradesListID, Selected = items.Selected, UnitPrice = items.UnitPrice
                            };
                            _context.PaymentProducts.Attach(paymentProducts1);
                        }

                        var results = _context.SaveChanges();
                    }
                }


                resultss.awnser = true;
                return(resultss);
            }
            catch (Exception ex) {
                var aa = ex.InnerException;
                resultss.awnser = false;
                resultss.error  = ex.Message.ToString();
                return(resultss);
            }



            //var client = new RestClient("https://backoffice.nedsecure.co.za/Lite/Transactions/New/EasyAuthorise.aspx");
            //var request = new RestRequest(Method.POST);
            //request.AddHeader("postman-token", "f76737bf-5509-94d4-50e1-5ac40f6780d8");
            //request.AddHeader("cache-control", "no-cache");
            //request.AddHeader("content-type", "application/x-www-form-urlencoded");
            //request.AddParameter("application/x-www-form-urlencoded", "Lite_Merchant_Applicationid=%7B9EBD4A80-3CA5-4968-9004-1A5A827E506E%7D&Lite_Website_Fail_url=http%3A%2F%2Flocalhost%3A58128%2Fapi%2FFail&Lite_Website_TryLater_url=http%3A%2F%2Flocalhost%3A58128%2Fapi%2FTrylater&Lite_Website_Error_url=http%3A%2F%2Flocalhost%3A58128%2Fapi%2FTrylater&Lite_Order_LineItems_Product_1=Donation&Lite_Order_LineItems_Quantity_1=1&Lite_Order_LineItems_Amount_1=1000&Lite_ConsumerOrderID_PreFix=DML&Ecom_BillTo_Online_Email=mathhys.smith%40gmail.com&Ecom_Payment_Card_Protocols=iVeri&Ecom_ConsumerOrderID=AUTOGENERATE&Ecom_TransactionComplete=&Lite_Result_Description=&Lite_Merchant_Trace=779", ParameterType.RequestBody);
            //IRestResponse response = client.Execute(request);
        }
Exemplo n.º 4
0
        public PaymentLists GetPaymentLists(PaymentListsInputModel model)
        {
            var sSQL = @"DECLARE @HFID INT, @PLServiceID INT, @PLItemID INT
                SELECT @HFID = HFId FROM tblClaimAdmin WHERE ClaimAdminCode = @ClaimAdminCode AND ValidityTo IS NULL 
                SELECT @PLServiceID = PLServiceID FROM tblHF Where HFid = @HFID 
                SELECT @PLItemID = PLItemID FROM tblHF Where HFid = @HFID


                SELECT tblHF.HFCode, tblHF.HFName FROM tblHF WHERE HfID = @HFID

                SELECT Items.ItemCode AS code, Items.ItemName AS name, ISNULL(PLID.PriceOverule,Items.ItemPrice) AS price from tblPLItemsDetail PLID
                INNER JOIN tblItems Items ON PLID.ItemID = Items.ItemID AND Items.ValidityTo IS NULL
                WHERE PLItemID = @PLItemID AND PLID.ValidityTo IS NULL AND (PLID.ValidityFrom >= @LastUpdated OR @LastUpdated IS NULL)                        

                Select SE.ServCode AS code, SE.ServName AS name, ISNULL(PLSD.PriceOverule,SE.ServPrice) AS price 
                FROM tblPLServicesDetail PLSD
                INNER JOIN tblServices SE ON PLSD.ServiceID = SE.ServiceID AND SE.ValidityTo IS NULL
                WHERE PLServiceID = @PLServiceID AND PLSD.ValidityTo IS NULL AND (PLSD.ValidityFrom >= @LastUpdated OR @LastUpdated IS NULL)    ";

            DataHelper   helper = new DataHelper(Configuration);
            SqlParameter date;

            if (model.last_update_date != null)
            {
                date = new SqlParameter("@LastUpdated", model.last_update_date);
            }
            else
            {
                date = new SqlParameter("@LastUpdated", System.Data.SqlTypes.SqlDateTime.MinValue);
            }

            SqlParameter[] sqlParameters =
            {
                new SqlParameter("@ClaimAdminCode", model.claim_administrator_code),
                date
            };


            PaymentLists message = new PaymentLists();

            try
            {
                var response = helper.FillDataSet(sSQL, sqlParameters, CommandType.Text);
                if (response.Tables.Count > 0)
                {
                    var diagnoses = response.Tables[0];
                    var items     = JsonConvert.SerializeObject(response.Tables[1]);
                    var services  = JsonConvert.SerializeObject(response.Tables[2]);

                    if (diagnoses.Rows.Count > 0)
                    {
                        message.health_facility_code = diagnoses.Rows[0]["HFCode"].ToString();
                        message.health_facility_name = diagnoses.Rows[0]["HFName"].ToString();
                    }

                    message.pricelist_items    = JsonConvert.DeserializeObject <List <CodeNamePrice> >(items);
                    message.pricelist_services = JsonConvert.DeserializeObject <List <CodeNamePrice> >(services);
                    message.update_since_last  = DateTime.UtcNow;
                }
            }
            catch (Exception e)
            {
                throw e;
            }

            return(message);
        }