示例#1
0
 public JsonResult CheckOfferCode(string code)
 {
     try
     {
         SaleCode saleCode = db.SaleCodes.Find(code);
         if (saleCode != null)
         {
             return(Json(new { IsSuccessful = 1, Percent = saleCode.Percent, Msg = string.Empty }));
         }
         else
         {
             return(Json(new { IsSuccessful = 0, Msg = "Mã giảm giá không đúng hoặc đã được sử dụng!" }));
         }
     }
     catch (Exception ex)
     {
         return(Json(new { IsSuccessful = 0, Msg = ex.Message }));
     }
 }
示例#2
0
 public ActionResult Actions()
 {
     try
     {
         var table = new DataTable();
         table.Columns.Add("code", typeof(string));
         table.Columns.Add("saleId", typeof(int));
         table.Columns.Add("isUse", typeof(bool));
         var preCode  = Request["Pre_Code"];
         var lenght   = Request["LenghtChar"];
         var quantity = Request["QuantityCode"];
         var saleId   = ArrId.FirstOrDefault();
         for (int i = 1; i <= int.Parse(quantity); i++)
         {
             var code  = FDIUtils.RandomKey(int.Parse(lenght ?? "6"));
             var model = new SaleCode
             {
                 Code   = preCode + code,
                 SaleID = saleId,
                 IsUse  = false
             };
             table.Rows.Add(model.Code, model.SaleID, model.IsUse);
         }
         sp_InsertUpdate(WebConfig.ConnectString, "sp_InsertSalesCode", "@tbl", table);
         var msg = new JsonMessage
         {
             Erros   = false,
             Message = "Tạo mã thành công.!"
         };
         return(Json(msg, JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         var msg = new JsonMessage
         {
             Erros   = true,
             Message = "Có lỗi xảy ra.!"
         };
         return(Json(msg, JsonRequestBehavior.AllowGet));
     }
 }
示例#3
0
        public JsonResult ApplySaleCode(string code)
        {
            try
            {
                SaleCode saleCode = db.SaleCodes.Find(code);

                if (saleCode != null)
                {
                    db.SaleCodes.Remove(saleCode);
                    db.SaveChanges();
                    return(Json(new { IsSuccessful = 1 }));
                }

                else
                {
                    return(Json(new { IsSuccessful = 0 }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { IsSuccessful = 0 }));
            }
        }
示例#4
0
        public JsonResult ChargeSaleCode(int offerID)
        {
            try
            {
                var offer        = db.Offers.Find(offerID);
                var userProperty = db.UserProperties.Find(User.Identity.Name);

                if (offer == null || userProperty == null)
                {
                    return(Json(new { isSuccess = false, msg = "Tài khoản không tồn tại" }));
                }
                if (userProperty.Coins < offer.CoinsConsumed)
                {
                    return(Json(new { isSuccess = false, msg = "Số xu không đủ" }));
                }

                var saleCode = new SaleCode()
                {
                    Username     = User.Identity.Name,
                    Percent      = offer.Percent,
                    Code         = Utility.CommonFunction.RandomString(10),
                    OverduedDate = DateTime.Now
                };

                db.SaleCodes.Add(saleCode);
                userProperty.Coins           = userProperty.Coins - offer.CoinsConsumed;
                db.Entry(userProperty).State = EntityState.Modified;
                db.SaveChanges();

                return(Json(new { isSuccess = true, msg = "", leftcoins = userProperty.Coins }));
            }
            catch (Exception ex)
            {
                return(Json(new { isSuccess = false, msg = ex.Message }));
            }
        }
示例#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));
        }