public IActionResult Checkout([FromBody] CheckoutRequestModel model)
        {
            var email = GetUser();
            var user  = _db.Users.Where(x => x.Email == email).FirstOrDefault();

            if (user == null)
            {
                return(Unauthorized());
            }

            var basket = _db.Baskets.Include(x => x.User).Include(x => x.Products).ThenInclude(x => x.Product)
                         .Where(x => x.User.Email == email && x.Status == BasketStatus.NotOrdered)
                         .FirstOrDefault();

            basket.Status    = BasketStatus.Ordered;
            basket.OrderDate = DateTime.Now;
            _db.Baskets.Update(basket);
            MailUtil.SendCheckoutEmail(user, basket, model.DeliveryInformation);

            _db.Baskets.Add(new Basket {
                User = user, Status = BasketStatus.NotOrdered
            });
            _db.SaveChanges();
            return(Ok(basket.Id));
        }
Beispiel #2
0
        public async Task <IActionResult> Checkout([FromBody] CheckoutRequestModel request)
        {
            string guestID = HttpContext.Session.Get <string>("guestID");
            string userID  = (HttpContext.Session.Get <UserDto>("current-user"))?.ID;

            try
            {
                await this.cartManager.Checkout(new OrderDto
                {
                    UserID          = userID,
                    GuestID         = guestID,
                    UserName        = request.UserName,
                    Phone           = request.Phone,
                    DeliveryAddress = request.DeliveryAddress,
                    TotalPrice      = request.TotalPrice
                });

                this.responseStatus = new ResponseStatusModel {
                    Success = true
                };
                return(Ok(new { ResponseStatus = this.responseStatus }));
            }
            catch (ArgumentException ex)
            {
                return(NotFound(new { Success = false, Error = ex.Message }));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Execute processing.
        /// </summary>
        /// <param name="request">RequestModel</param>
        /// <returns>ResponseModel</returns>
        private CheckoutResponseModel Execute(CheckoutRequestModel request)
        {
            // Local variable declaration
            CheckoutResponseModel responseModel = null;
            InitDataModel         inputObject   = null;
            InitDataModel         resultObject  = new InitDataModel();

            // Variable initialize
            responseModel = new CheckoutResponseModel();

            // Execute convert input.
            inputObject = Convert(request);

            ClientCheckoutDao checkoutDao = new ClientCheckoutDao();

            resultObject.AcceptSlipNo = checkoutDao.makeCheckout(inputObject.Accept, inputObject.Cart);

            // Send mail
            //SendEmail(inputObject.Accept.ClientCd, inputObject.Accept.AcceptSlipNo);

            // Execute convert ouput.
            responseModel = Convert(resultObject);

            return(responseModel);
        }
Beispiel #4
0
        /// <summary>
        /// Execute convert input.
        /// </summary>
        /// <param name="request">RequestModel</param>
        /// <returns>DataModel</returns>
        private InitDataModel Convert(CheckoutRequestModel request)
        {
            // Local variable declaration
            InitDataModel inputObject = null;

            // Variable initialize
            inputObject = new InitDataModel();

            // Convert data input
            DataHelper.ConvertInput(request, inputObject);
            inputObject.Accept = request.Accept;
            inputObject.Cart   = DataHelper.ConvertInputCart(request.Cart);
            return(inputObject);
        }
        public async Task <IActionResult> Checkout([FromBody] CheckoutRequestModel request)
        {
            try
            {
                await this.cartManager.CheckoutAsync(new User
                {
                    _Id             = request._Id,
                    Name            = request.Name,
                    Phone           = request.Phone,
                    DeliveryAddress = request.DeliveryAddress,
                });

                this.responseStatus = new ResponseStatusModel {
                    Success = true
                };
                return(Ok(new { ResponseStatus = this.responseStatus }));
            }
            catch (ArgumentException ex)
            {
                return(NotFound(new { Success = false, Error = ex.Message }));
            }
        }
Beispiel #6
0
        public async Task <CheckoutResponseModel> CheckOutData(string queryId, CheckoutRequestModel request)
        {
            var res = await PostAsynGraphql <CheckoutRequestModel, CheckoutResponseModel>(queryId, request);

            return(res);
        }
Beispiel #7
0
        /// <summary>
        /// Checkout process.
        /// </summary>
        /// <param name="request">RequestModel</param>
        /// <returns>ResponseModel</returns>
        public CheckoutResponseModel Invoke(CheckoutRequestModel request)
        {
            var responseModel = Execute(request);

            return(responseModel);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            if (Session["Cart"] == null || Session["payMethod"] == null)
            {
                Response.Redirect(Pages.CLIENT_INDEX);
            }
            if (Session["CheckoutRequestModel"] == null || Session["hasCheckout"] == null)
            {
                Response.Redirect(Pages.CLIENT_CHECKOUT);
            }
            if (Session["payMethod"].ToString().Equals("0") && Session["SaveRequestModel"] == null)
            {
                Response.Redirect(Pages.CLIENT_CHECKOUT);
            }
            else
            {
                Session["hasCheckout"] = null;
            }

            //load data
            MCodeCom          codeCom = new MCodeCom();
            IList <ComboItem> citylst = MCodeCom.ToComboItems(codeCom.GetListCity(), "294").ListItems;

            DropDownList1.DataSource = citylst;
            DropDownList1.DataBind();
            DropDownList1.SelectedValue = "294";
            DropDownList2.DataSource    = citylst;
            DropDownList2.DataBind();
            DropDownList2.SelectedValue = "294";

            if (Session["payMethod"].ToString().Equals("0"))
            {
                SaveRequestModel accCreate = (SaveRequestModel)Session["SaveRequestModel"];
                email.Text = accCreate.Email;
            }
            CheckoutRequestModel checkout = (CheckoutRequestModel)Session["CheckoutRequestModel"];
            Accept accept = checkout.Accept;

            clientName.Text             = accept.ClientName;
            clientAddress.Text          = accept.ClientAddress;
            clientTell.Text             = accept.ClientTel;
            DropDownList1.SelectedValue = accept.ClientCityCd;
            deliveryName.Text           = accept.DeliveryName;
            deliveryAddress.Text        = accept.DeliveryAddress;
            deliveryTell.Text           = accept.DeliveryTel;
            DropDownList2.SelectedValue = accept.DeliveryCityCd;
            note.Text = accept.Notes;
            if (accept.PaymentMethods == "01")
            {
                lblPay.Text = "Thanh toán tiền mặt khi nhận hàng";
            }
            else if (accept.PaymentMethods == "02")
            {
                lblPay.Text = "Thanh toán trực truyến bằng thẻ ATM - Internet Banking";
            }
            IList <CartItem> cart    = (IList <CartItem>)Session["Cart"];
            CartCom          cartCom = new CartCom(cart);
            decimal          amount  = cartCom.TotalAmount;
            decimal          ship    = 0;

            if (Session["GiftPrice"] != null && Session["GiftCd"] != null)
            {
                amount = amount - (decimal)Session["GiftPrice"];
            }
            total = amount;
            if (accept.DeliveryCityCd == "294")
            {
                if (amount < 200000)
                {
                    ship  = 20000;
                    total = total + ship;
                }
            }
            else
            {
                if (amount < 1000000)
                {
                    ship  = 30000;
                    total = total + ship;
                }
            }
            Label1.Text = DataHelper.ToString(Formats.CURRENCY, amount);
            if (ship != 0)
            {
                Label2.Text = DataHelper.ToString(Formats.CURRENCY, ship);
            }
            Label3.Text         = DataHelper.ToString(Formats.CURRENCY, total);
            Session["TotalAmt"] = total;
        }
Beispiel #9
0
        private void setCheckoutRequestModel()
        {
            CheckoutRequestModel request = new CheckoutRequestModel();
            DateTime             dateNow = DateTime.Now;
            Accept accept = new Accept();

            if (Session["payMethod"].ToString().Equals("1"))
            {
                accept.ClientCd = txtClientCd.Value.ToString();
            }
            else
            {
                accept.ClientCd = email.Text.Trim().ToString();
            }
            accept.AcceptDate      = DateTime.Now;
            accept.ClientName      = clientName.Text.Trim();
            accept.ClientAddress   = clientAddress.Text.Trim();
            accept.ClientTel       = clientTell.Text.Trim();
            accept.ClientCityCd    = DropDownList1.SelectedValue;
            accept.DeliveryName    = deliveryName.Text.Trim();
            accept.DeliveryAddress = deliveryAddress.Text;
            accept.DeliveryTel     = deliveryTell.Text;
            accept.DeliveryCityCd  = DropDownList2.SelectedValue;
            if (RadioButton1.Checked == true)
            {
                accept.DeliveryName    = accept.ClientName;
                accept.DeliveryAddress = accept.ClientAddress;
                accept.DeliveryTel     = accept.ClientTel;
                accept.DeliveryCityCd  = accept.ClientCityCd;
            }
            accept.Notes      = note.Text.ToString();
            accept.CreateDate = dateNow;
            accept.UpdateDate = dateNow;
            accept.DeleteFlag = false;
            if (pay1.Checked)
            {
                accept.PaymentMethods = "01";
                accept.SlipStatus     = "01";
            }
            else if (pay2.Checked)
            {
                accept.PaymentMethods = "02";
                accept.SlipStatus     = "03";
            }
            else if (pay3.Checked)
            {
                accept.SlipStatus = "03";
            }
            else
            {
                accept.SlipStatus = "04";
            }
            accept.Notes      = note.Text;
            accept.CreateUser = accept.ClientCd;
            accept.UpdateUser = accept.ClientCd;

            request.Accept = accept;
            request.Cart   = Session["Cart"];

            if (Session["GiftCd"] != null)
            {
                accept.UseGiftCd = Session["GiftCd"].ToString();
            }
            Session["CheckoutRequestModel"] = request;
        }