Exemplo n.º 1
0
 public bool SetOrderIsDeliver(int OID)
 {
     COM.Order order = new COM.Order()
     {
         OID         = OID,
         IsDelivered = true
     };
     return(BLL.Salement.UpdateOrderDeliverStatus(order));
 }
Exemplo n.º 2
0
 public static int AddOrder(COM.Order mOrder)
 {
     try
     {
         using (var ent = DB.Entity)
         {
             ent.Orders.Add(mOrder);
             ent.SaveChanges();
             return(mOrder.OID);
         }
     }
     catch (Exception e)
     {
         Log.DoLog(COM.Action.AddOrder, "AddOrder", -100, e.Message);
         return(-100);
     }
 }
Exemplo n.º 3
0
 public static bool UpdateOrderPayStatus(COM.Order mOrder)
 {
     try
     {
         using (var ent = DB.Entity)
         {
             ent.Orders.Attach(mOrder);
             var Entry = ent.Entry(mOrder);
             Entry.Property(ex => ex.PayStatus).IsModified = true;
             ent.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         Log.DoLog(COM.Action.UpdateOrderPayStatus, mOrder.OID.ToString(), -100, e.Message);
         return(false);
     }
 }
Exemplo n.º 4
0
 public static bool UpdateOrderReBuy(COM.Order mOrder)
 {
     try
     {
         using (var ent = DB.Entity)
         {
             ent.Orders.Attach(mOrder);
             var Entry = ent.Entry(mOrder);
             Entry.Property(ex => ex.BuyID).IsModified        = true;
             Entry.Property(ex => ex.GhestNumber).IsModified  = true;
             Entry.Property(ex => ex.GhestValue).IsModified   = true;
             Entry.Property(ex => ex.PishPardakht).IsModified = true;
             return(true);
         }
     }
     catch (Exception e)
     {
         Log.DoLog(COM.Action.UpdateOrderReBuy, mOrder.OID.ToString(), -100, e.Message);
         return(false);
     }
 }
Exemplo n.º 5
0
        public async Task <COM.BuyResult> Buy()
        {
            COM.BuyResult buyResult = new COM.BuyResult();
            try
            {
                if (!Request.Content.IsMimeMultipartContent())
                {
                    buyResult.HasError  = true;
                    buyResult.StateDesc = "Exception dade: UnsupportedMediaType";
                    return(buyResult);
                }


                var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

                if (filesReadToProvider.Contents[0].Headers.ContentDisposition.Name == "Object" || filesReadToProvider.Contents[0].Headers.ContentDisposition.Name == "\"Object\"")
                {
                    var jsonString = await filesReadToProvider.Contents[0].ReadAsStringAsync();
                    var serializer = new JavaScriptSerializer();
                    COM.MiddlePayment mMiddlePayment = serializer.Deserialize <COM.MiddlePayment>(jsonString);


                    double SumPrice = 0;
                    foreach (var itemPro in mMiddlePayment.productInfos)
                    {
                        var pr = BLL.Product.GetProductByID(itemPro.PID);
                        if (pr == null)
                        {
                            buyResult.HasError  = true;
                            buyResult.StateDesc = "product nistesh";
                            return(buyResult);
                        }
                        SumPrice = SumPrice + (pr.PriceOff * itemPro.Count);
                    }

                    var ghestInfo = BLL.Product.GetGhestInfo();

                    if (mMiddlePayment.GhestCount > ghestInfo.MaxGhestNumber || mMiddlePayment.GhestCount < ghestInfo.MinGhestNumber)
                    {
                        buyResult.HasError  = true;
                        buyResult.StateDesc = "tedade ghest mojaz nemibashad";
                        return(buyResult);
                    }

                    double MablagheGhabelePardakht = 0;
                    double MablaghHarGhest         = 0;
                    if (SumPrice < ghestInfo.MinGhestValue)
                    {
                        // go to dagah pardaj
                        MablagheGhabelePardakht = SumPrice;
                    }
                    else
                    {
                        double A = (SumPrice + (((SumPrice * ghestInfo.Percentage) / 100.0f) * mMiddlePayment.GhestCount) - ghestInfo.MinPishPardakht);
                        if (A < ghestInfo.MaxGhestValue)
                        {
                            MablaghHarGhest         = A / mMiddlePayment.GhestCount;
                            MablagheGhabelePardakht = ghestInfo.MinPishPardakht;
                        }
                        else
                        {
                            double C = A - ghestInfo.MaxGhestValue;
                            MablagheGhabelePardakht = ghestInfo.MinPishPardakht + C;
                            MablaghHarGhest         = C / mMiddlePayment.GhestCount;
                        }
                    }

                    string BuyID = "70000324" + DateTime.Now.ToString("MMddyyyyhmms");

                    COM.Order order = new COM.Order()
                    {
                        IsDelivered  = false,
                        OrderTime    = DateTime.Now,
                        PayStatus    = false,
                        ProductsInfo = JsonConvert.SerializeObject(mMiddlePayment.productInfos),
                        ReciverInfo  = JsonConvert.SerializeObject(mMiddlePayment.MiliUser),
                        UID          = mMiddlePayment.MiliUser.UID,
                        BuyID        = BuyID,
                        GhestNumber  = mMiddlePayment.GhestCount,
                        GhestValue   = (long)MablaghHarGhest,
                        MainPrice    = (long)SumPrice,
                        TypePay      = mMiddlePayment.PayoffType,
                        PishPardakht = (long)MablagheGhabelePardakht
                    };
                    int OIDRes = BLL.Salement.AddOrder(order);
                    if (OIDRes < 0)
                    {
                        buyResult.HasError  = true;
                        buyResult.StateDesc = "Etela'at Kharid dar DB Save nashode";
                        return(buyResult);
                    }



                    COM.PayResultRequested payResultRequested = PayStart(10000, BuyID);
                    if (payResultRequested.Result > 0)
                    {
                        COM.Pay newPay = new COM.Pay()
                        {
                            Amount      = 10000,//MablagheGhabelePardakht
                            BuyID       = BuyID,
                            StartMoment = DateTime.Now,
                            UID         = mMiddlePayment.MiliUser.UID,
                            OID         = OIDRes,
                        };
                        int resDB = BLL.Payment.AddPay(newPay);
                        if (resDB < 0)
                        {
                            buyResult.HasError  = true;
                            buyResult.StateDesc = "Etela'at pardakht dar DB Save nashode";
                            return(buyResult);
                        }

                        buyResult.PayID = resDB;
                        buyResult.MablagheKoleKharid   = (long)SumPrice;
                        buyResult.MablagheHarGhest     = (long)MablaghHarGhest;
                        buyResult.MablaghePishpardakht = (long)MablagheGhabelePardakht;
                        buyResult.HasError             = false;
                        buyResult.LinkPardakht         = "http://www.poolban.ir/V2PayGate/Pool/StartPayRedirectww/" + payResultRequested.Result;
                        buyResult.StateDesc            = "OK Successsssss hoooraaa";
                    }
                    else
                    {
                        buyResult.MablagheKoleKharid   = (long)SumPrice;
                        buyResult.MablagheHarGhest     = (long)MablaghHarGhest;
                        buyResult.MablaghePishpardakht = (long)MablagheGhabelePardakht;
                        buyResult.HasError             = true;
                        buyResult.StateDesc            = "irad dar dargahe pardakht";
                    }

                    return(buyResult);
                }
                else
                {
                    buyResult.HasError  = true;
                    buyResult.StateDesc = "eshtbahi dar ersal Post pish amade";
                    return(buyResult);
                }
            }
            catch (Exception e)
            {
                new System.Threading.Thread(delegate() { Log.DoLog(COM.Action.Buy, "", -100, e.Message); }).Start();
                buyResult.HasError  = true;
                buyResult.StateDesc = "Exception dade: " + e.Message;
                return(buyResult);
            }
        }