Пример #1
0
        public int AddPoint(string ListChecked, int Point, string Description)
        {
            string[]   listBox = ListChecked.Split(',');
            List <int> boxes   = new List <int>();

            foreach (var number in listBox)
            {
                if (number != null && number != "")
                {
                    boxes.Add(Convert.ToInt32(number));
                }
            }

            try {
                foreach (var box in boxes)
                {
                    NotifyBusiness  notify        = new NotifyBusiness();
                    PackageBusiness package       = new PackageBusiness();
                    PointBusiness   pointBusiness = new PointBusiness();
                    Customer        customer      = cnn.Customers.Find(box);
                    customer.Point += Point;
                    cnn.SaveChanges();
                    string code = Util.CreateMD5(DateTime.Now.ToString()).Substring(0, 6);
                    pointBusiness.CreateHistoryes(box, Point, SystemParam.HISPOINT_HE_THONG_CONG_DIEM, code, Description, null);
                    string contennotify = "Bạn vừa được cộng " + Point + " điểm từ hệ thống";
                    notify.CreateNoti(box, SystemParam.HISPOINT_HE_THONG_CONG_DIEM, 0, contennotify, contennotify, null);
                    //if(customer.DeviceID.Length > 0)
                    //{
                    //    NotifyDataModel notifyData = new NotifyDataModel();
                    //    notifyData.id = customer.ID;
                    //    notifyData.type = SystemParam.HISPOINT_HE_THONG_CONG_DIEM;
                    //    package.StartPushNoti(notifyData, customer.DeviceID, contennotify, SystemParam.ROLE_ADMIN);
                    //    string a = notify.PushNotify(customer.ID, contennotify, SystemParam.HISPOINT_HE_THONG_CONG_DIEM);
                    //}
                }
                return(1);
            } catch (Exception ex) {
                ex.ToString();
                return(0);
            }
        }
Пример #2
0
        public VNPayOutputModel GetVnpIpn(VnpOutputModel vnp)
        {
            VNPayOutputModel output = new VNPayOutputModel();
            int appID = 0;

            try
            {
                try
                {
                    appID = int.Parse(vnp.vnp_TxnRef);
                }
                catch
                {
                    output = output.GetPayOutputModel("Order not found", vnp.vnp_TxnRef, vnp.vnp_TransactionNo, SystemParam.vnp_Return_Rawurl, "01");
                    return(output);
                }
                BuyPackageHistory apb = cnn.BuyPackageHistories.Find(int.Parse(vnp.vnp_TxnRef));
                if (apb != null)
                {
                    int money = 0;
                    try
                    {
                        money = int.Parse(vnp.vnp_Amount) / 100;
                        if (money != apb.Price)
                        {
                            output = output.GetPayOutputModel("Invalid amount", vnp.vnp_TxnRef, vnp.vnp_TransactionNo, "", "04");
                            return(output);
                        }
                    }
                    catch
                    {
                        output = output.GetPayOutputModel("Invalid amount", vnp.vnp_TxnRef, vnp.vnp_TransactionNo, "", "04");
                        return(output);
                    }
                    if (vnp.vnp_TmnCode.Equals(SystemParam.vnp_TmnCode) && vnp.vnp_SecureHash.Equals(apb.KeyVNPay))
                    {
                        if (vnp.vnp_ResponseCode == SystemParam.vnp_CodeSucces)
                        {
                            if (apb.Status == 0)
                            {
                                apb.Status = 1;
                                cnn.SaveChanges();
                                PointBusiness  pBus    = new PointBusiness();
                                int            point   = pBus.CreateAddPointByWarranty(appID, apb.CustomerID, vnp.vnp_TransactionNo);
                                NotifyBusiness noti    = new NotifyBusiness();
                                string         content = "Giao dịch thành công: \n + Mã đơn hàng qua VNPAY: " + vnp.vnp_TxnRef + "\n + Số tiền: " + string.Format("{0:#,0}", apb.Price) + " đ\n + Thời gian: " + DateTime.Now.ToString(SystemParam.CONVERT_DATETIME_HAVE_HOUR);
                                noti.CreateNotiWhenBuyPackage(apb.CustomerID, "Giao dịch đã được thực hiện", content);

                                output = output.GetPayOutputModel("Confirm Success", vnp.vnp_TxnRef, vnp.vnp_TransactionNo, "", vnp.vnp_ResponseCode);
                            }
                            else
                            {
                                output = output.GetPayOutputModel("Order already confirmed", vnp.vnp_TxnRef, vnp.vnp_TransactionNo, "", "02");
                            }
                        }
                        else
                        {
                            if (apb.Status == 0)
                            {
                                apb.Status = 2;
                                cnn.SaveChanges();
                                output = output.GetPayOutputModel("Confirm Success", vnp.vnp_TxnRef, vnp.vnp_TransactionNo, SystemParam.vnp_Return_Rawurl, "00");
                            }
                            else
                            {
                                output = output.GetPayOutputModel("Order already confirmed", vnp.vnp_TxnRef, vnp.vnp_TransactionNo, "", "02");
                            }
                        }
                    }
                    else
                    {
                        output = output.GetPayOutputModel("Invalid signature", vnp.vnp_TxnRef, vnp.vnp_TransactionNo, SystemParam.vnp_Return_Rawurl, "97");
                    }
                }
                else
                {
                    output = output.GetPayOutputModel("Order not found", vnp.vnp_TxnRef, vnp.vnp_TransactionNo, SystemParam.vnp_Return_Rawurl, "01");
                }
            }
            catch
            {
                output = output.GetPayOutputModel("Unknow error", vnp.vnp_TxnRef, vnp.vnp_TransactionNo, SystemParam.vnp_Return_Rawurl, "99");
            }
            return(output);
        }