示例#1
0
        protected string SetCodeC()
        {
            var date       = DateTime.Now;
            var code       = FDIUtils.RandomCode(5);
            var expires    = date.AddHours(3);
            var codeCookie = HttpContext.Request.Cookies["CodeC"];

            if (codeCookie == null)
            {
                codeCookie = new HttpCookie("CodeC")
                {
                    Value = code, Expires = expires
                };
                Response.Cookies.Add(codeCookie);
            }
            else
            {
                if (string.IsNullOrEmpty(codeCookie.Value))
                {
                    codeCookie.Value   = code;
                    codeCookie.Expires = expires;
                    Response.Cookies.Add(codeCookie);
                }
            }
            return(code);
        }
示例#2
0
        public ActionResult ActionsAdd(string codep, int pi)
        {
            var code = FDIUtils.RandomCode(8);
            var obj  = Add(code, codep, pi);

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }
示例#3
0
 public ActionResult GetListSimpleProductDetail(string codec)
 {
     if (Request["key"] == Keyapi)
     {
         var obj = Cates.FirstOrDefault(m => m.Barcode == codec);
         if (obj == null)
         {
             var stt            = 1;
             var listItemDetail = _da.GetListSimpleProductDetail();
             foreach (var item in listItemDetail)
             {
                 item.Stt     = stt;
                 item.Barcode = FDIUtils.RandomCode(8);
                 item.Code    = "f" + stt;
                 stt++;
                 var objinew = new ImportProductAddItem
                 {
                     Stt      = 1,
                     BarCode  = FDIUtils.RandomCode(10),
                     Price    = item.Price,
                     Value    = 0,
                     PriceNew = 0,
                     Quantity = 1,
                 };
                 item.ListImportProductItems = new List <ImportProductAddItem> {
                     objinew
                 };
             }
             obj = new CateValueAddItem
             {
                 Stt      = 1,
                 Barcode  = codec,
                 PriceNew = 0,
                 Pi       = 0,
                 ListProductValueItems = listItemDetail,
             };
             Cates.Add(obj);
         }
         return(Json(obj, JsonRequestBehavior.AllowGet));
     }
     return(Json(new CateValueAddItem(), JsonRequestBehavior.AllowGet));
 }
示例#4
0
        public ActionResult Barcode(int n)
        {
            var code = FDIUtils.RandomCode(n);

            return(Json(code, JsonRequestBehavior.AllowGet));
        }
示例#5
0
        public async Task <ActionResult> Booking(List <OrderAppIG4Item> datas)
        {
            try
            {
                decimal?totalall  = 0;
                var     listOrder = new List <Shop_Orders>();
                foreach (var data in datas)
                {
                    if (data.LisOrderDetailItems == null || !data.LisOrderDetailItems.Any())
                    {
                        return(Json(new JsonMessage(1000, "Không có sản phẩm trong giỏ hàng"),
                                    JsonRequestBehavior.AllowGet));
                    }

                    SaleCode coupon = null;
                    if (!string.IsNullOrEmpty(data.Coupon))
                    {
                        coupon = _productDa.GetSaleCodeUseByCode(data.Coupon);
                        if (coupon != null)
                        {
                            coupon.IsUse = true;
                        }
                        //if (coupon == null)
                        //{
                        //    return Json(new JsonMessage(1000, "Coupon không tồn tại"));
                        //}
                    }

                    var order = new Shop_Orders()
                    {
                        Address       = data.Address,
                        CustomerID    = CustomerId,
                        Longitude     = data.Longitude,
                        Latitude      = data.Latitude,
                        Mobile        = data.Mobile,
                        CustomerName  = data.CustomerName,
                        DateCreated   = DateTime.Now.TotalSeconds(),
                        Code          = FDIUtils.RandomCode(12),
                        FeeShip       = data.FeeShip ?? 0,
                        StatusPayment = (int)PaymentOrder.Process,
                        Coupon        = data.Coupon,
                        ShopID        = data.ShopID,
                        //Discount = data.Discount,
                        CouponPrice       = coupon?.DN_Sale.Price ?? 0,
                        PaymentMethodId   = data.PaymentmethodId,
                        Status            = (int)StatusOrder.Create,
                        Note              = data.Note,
                        CustomerAddressID = data.CustomerAddressID,
                    };
                    order.CouponPrice = !string.IsNullOrEmpty(data.Coupon)
                        ? coupon.DN_Sale.Price ?? 0
                        : order.CouponPrice = 0;

                    foreach (var product in data.LisOrderDetailItems)
                    {
                        var productData = _productDa.GetProductItem(product.ProductId ?? 0);
                        if (productData == null)
                        {
                            return(Json(new JsonMessage(1000, "Sản phẩm không tồn tại"), JsonRequestBehavior.AllowGet));
                        }

                        var item = new Shop_Order_Details()
                        {
                            ProductID     = product.ProductId,
                            Price         = productData.PriceNew ?? 0,
                            Quantity      = product.Quantity ?? 1,
                            Status        = (int)StatusOrder.Create,
                            TotalPrice    = productData.PriceNew * (product.Quantity ?? 1),
                            StatusPayment = (int)PaymentOrder.Process,
                            IsPrestige    = product.IsPrestige,
                        };
                        order.Shop_Order_Details.Add(item);
                    }

                    var total = order.Shop_Order_Details.Sum(m => m.Price * m.Quantity);
                    order.Total      = total;
                    order.TotalPrice = total;
                    order.Payments   = total - order.CouponPrice + data.FeeShip;
                    totalall        += total - order.CouponPrice + data.FeeShip;
                    listOrder.Add(order);
                    //orderDA.Add(order);
                }

                //kiểm tra ví và trừ tiền khách hàng sau đó lưu đơn hàng
                var check = CheckWallets(totalall, CustomerId);
                if (check)
                {
                    foreach (var order in listOrder)
                    {
                        orderDA.Add(order);
                        await orderDA.SaveAsync();

                        var cashout = new CashOutWallet
                        {
                            CustomerID = CustomerId,
                            TotalPrice = order.Payments,
                            DateCreate = DateTime.Now.TotalSeconds(),
                            OrderID    = order.ID,
                            Type       = 1,
                            Code       = order.Code,
                        };
                        _cashOutWalletDa.Add(cashout);
                        _cashOutWalletDa.Save();
                    }
                    await _productDa.SaveAsync();
                }
                else
                {
                    return(Json(new JsonMessage(1001, "Tài khoản của bạn không đủ tiền."),
                                JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                return(Json(new JsonMessage(404, e.ToString()), JsonRequestBehavior.AllowGet));
            }

            return(Json(new JsonMessage(200, ""), JsonRequestBehavior.AllowGet));
        }