예제 #1
0
        public async Task <JsonResult> ConfirmCode([FromBody] getFullParamViewModel ListFullParam, string code)
        {
            CM_Customer customer = await this.SaleOrderBLL.FindUserByCMND(ListFullParam.Customer.CMND);

            bool isSuccess = await SaleOrderBLL.ConfirmCode(customer, code);

            return(Json(new ResponseMessage {
                Message = SaleOrderBLL.Message, IsSuccess = isSuccess, errorSaleOrder = SaleOrderBLL.enumErrorSaleOrder
            }));
        }
예제 #2
0
        private async Task validateCustomer(CM_Customer objCustomer)
        {
            CM_Customer Customer = await this.unitOfWork.CM_Customer_Repository.FindCustomer(p => p.CMND == objCustomer.CMND);

            if (Customer == null)
            {
                try
                {
                    //check valid phonenumber
                    if (string.IsNullOrEmpty(objCustomer.CustomerPhone) || !IsPhoneNumber(objCustomer.CustomerPhone))
                    {
                        this.enumErrorSaleOrder = ErrorSaleOrder.NotValid;
                        strMessage = "Số điện thoại nhập vào không phù hợp";
                        return;
                    }
                    else if (string.IsNullOrEmpty(objCustomer.CMND) || !CheckCMND(objCustomer.CMND))
                    {
                        this.enumErrorSaleOrder = ErrorSaleOrder.NotValid;
                        strMessage = "Số CMND không phù hợp";
                        return;
                    }

                    await sendCode(objCustomer);

                    this.unitOfWork.CM_Customer_Repository.Insert(objCustomer);
                    await this.unitOfWork.SaveChangeAsync();
                }
                catch (Exception objEx)
                {
                    this.enumErrorSaleOrder = ErrorSaleOrder.Error;
                    strMessage = objEx.ToString();
                    throw objEx;
                }

                return;
            }
            else
            {
                if (string.IsNullOrEmpty(objCustomer.CustomerPhone) || !IsPhoneNumber(objCustomer.CustomerPhone))
                {
                    this.enumErrorSaleOrder = ErrorSaleOrder.NotValid;
                    strMessage = "Số điện thoại nhập vào không phù hợp";
                    return;
                }
                Customer.CustomerPhone = objCustomer.CustomerPhone;
                await   sendCode(Customer);

                this.unitOfWork.CM_Customer_Repository.Update(Customer);
                await this.unitOfWork.SaveChangeAsync();
            }
        }
예제 #3
0
        private async Task sendCode(CM_Customer Customer)
        {
            var    rng    = new Random();
            string first  = rng.Next(10).ToString();
            string second = rng.Next(10).ToString();
            string third  = rng.Next(10).ToString();
            string fourth = rng.Next(10).ToString();

            Customer.ConfirmCode = first + second + third + fourth;
            enumErrorSaleOrder   = ErrorSaleOrder.ConfirmUser;
            strMessage           = "Vui lòng nhập  mã xác nhận  ";


            await this.SMSServices.sendSMS(Customer.CustomerPhone, Customer.ConfirmCode);
        }
예제 #4
0
        public async Task <bool> ConfirmCode(CM_Customer objCustomer, string Code)
        {
            if (objCustomer.ConfirmCode == Code)
            {
                objCustomer.ConfirmCode       = "true";
                objCustomer.CustomerStateEnum = Common.Enum.SM.CustomerStateEnum.active;
                strMessage         = "Xac nhan tai khoan thanh cong";
                enumErrorSaleOrder = ErrorSaleOrder.SuccessActive;
                this.unitOfWork.CM_Customer_Repository.Update(objCustomer);
                await this.unitOfWork.SaveChangeAsync();

                return(true);
            }
            else
            {
                enumErrorSaleOrder = ErrorSaleOrder.ConfirmCodeError;
                strMessage         = "Mã nhập vào không chính xác ";
                return(false);
            }
        }
예제 #5
0
        public async Task <bool> CreateBill(CM_Customer objCustomer, SaleOrder objSaleOrder, List <SaleOrderDetail> listSaleOrderDetails)
        {
            try
            {
                CM_Customer Customer = await this.unitOfWork.CM_Customer_Repository.FindCustomer(p => p.CMND == objCustomer.CMND && p.CustomerPhone == objCustomer.CustomerPhone);

                if (Customer == null || Customer.CustomerStateEnum != Common.Enum.SM.CustomerStateEnum.active)
                {
                    await  validateCustomer(objCustomer);

                    return(false);
                }
                else if (listSaleOrderDetails.Count == 0)
                {
                    enumErrorSaleOrder = ErrorSaleOrder.NotValid;
                    strMessage         = "Khong the tao bill khi khong mua gi";
                    return(false);
                }
                objSaleOrder.CustomerID = Customer.Id;
                foreach (var SaleOrderDetail in listSaleOrderDetails)
                {
                    SaleOrderDetail.SaleOrderID = objSaleOrder.ID;
                    this.unitOfWork.SaleOrderDetailsRepository.Insert(SaleOrderDetail);
                }
                this.unitOfWork.SaleOrderRepository.Insert(objSaleOrder);
                await this.unitOfWork.SaveChangeAsync();

                this.enumErrorSaleOrder = ErrorSaleOrder.Success;
                strMessage = "Tạo đơn hàng  thành công";

                return(true);
            }
            catch (Exception objEx)
            {
                await AddError(objEx);

                this.enumErrorSaleOrder = ErrorSaleOrder.CreateBill;
                strMessage = "Tạo đơn hàng không thành công vui lòng liên hệ nhân viên kiểm tra";
                return(false);
            }
        }
예제 #6
0
 public Task <bool> Update(CM_Customer entity, string UpdatedUser = "******")
 {
     throw new NotImplementedException();
 }
예제 #7
0
 public async Task <bool> Add(CM_Customer customer, string CreatedUser = "******")
 {
     return(false);
 }
예제 #8
0
        public async Task <JsonResult> GetFullParam([FromBody] getFullParamViewModel ListFullParam)
        {
            var         i = 0;
            CM_Customer CurrentCustomer = new CM_Customer()
            {
                CustomerName     = ListFullParam.Customer.Name,
                CustomerPhone    = ListFullParam.Customer.Phone,
                CMND             = ListFullParam.Customer.CMND,
                TypeCustomerEnum = Common.Enum.SM.TypeCustomerEnum.KVL
            };

            #region validateSaleOrder
            SaleOrder CurrentSaleOrder = new SaleOrder()
            {
                ReceiveAddress   = ListFullParam.saleOrder.ReceiveAddress,
                TotalPrice       = ListFullParam.saleOrder.TotalPrice,
                PaymentMethod    = (Common.Enum.SM.PaymentMethod)ListFullParam.saleOrder.PaymentMethod,
                DistrictID       = ListFullParam.saleOrder.DistrictID,
                TransportPriceID = ListFullParam.saleOrder.TransportTypeID,
            };
            CurrentSaleOrder.TransportTypePrice = await GetTransportPrice(ListFullParam.saleOrder.TransportPriceID, ListFullParam.saleOrder.TransportTypeID);

            if (CurrentSaleOrder.TransportTypePrice == -1)
            {
                return(Json(new ResponseMessage {
                    Message = "Vui long chon nha van chuyen ", IsSuccess = false
                }));
            }
            #endregion
            List <SaleOrderDetail> CurrentSaleDetails = new List <SaleOrderDetail>();

            foreach (var item in ListFullParam.saleOrderDetails)
            {
                var productDetails = await ProductDetailsBLL.Find(item.ProductDetailIDSale);

                SaleOrderDetail temp = new SaleOrderDetail()
                {
                    ProductDetailId = item.ProductDetailIDSale,
                    Quality         = item.QuantitySale,
                    ProductDetail   = productDetails
                };
                CurrentSaleDetails.Add(temp);
            }
            var isSuccess = await SaleOrderBLL.CreateBill(CurrentCustomer, CurrentSaleOrder, CurrentSaleDetails);

            string BaseUrl = string.Format("{0}://{1}", HttpContext.Request.Scheme, HttpContext.Request.Host);

            if (isSuccess)
            {
                if (CurrentSaleOrder.PaymentMethod == Common.Enum.SM.PaymentMethod.Paypal)
                {
                    string SuccessUrl = BaseUrl + Url.Action("ExcutePayment", "Bill");
                    string ErrorUrl   = BaseUrl + Url.Action("ErrorBill", "Bill");
                    var    payment    = await this._paypalServicesGatewayBLL.CreatePayment(SuccessUrl, ErrorUrl, CurrentSaleOrder, CurrentSaleDetails, CurrentCustomer);

                    CurrentSaleOrder.AuthenticationMethodGuid = payment.Id;
                    await this.SaleOrderBLL.Update(CurrentSaleOrder);



                    return(Json(new ResponseMessage {
                        Message = SaleOrderBLL.Message, IsSuccess = isSuccess, errorSaleOrder = SaleOrderBLL.enumErrorSaleOrder, RedirectoURl = payment.Links[1].Href
                    }));
                }
                else if (CurrentSaleOrder.PaymentMethod == Common.Enum.SM.PaymentMethod.GDTT)
                {
                    string SuccessUrl = BaseUrl + Url.Action("PaymentTTTN", "Bill");
                    string ErrorUrl   = BaseUrl + Url.Action("ErrorBill", "Bill");
                    return(Json(new ResponseMessage {
                        Message = SaleOrderBLL.Message, IsSuccess = isSuccess, errorSaleOrder = SaleOrderBLL.enumErrorSaleOrder, RedirectoURl = SuccessUrl
                    }));
                }
                else if (CurrentSaleOrder.PaymentMethod == Common.Enum.SM.PaymentMethod.NganLuong)
                {
                    var    ReturnUrlNganLuong = BaseUrl + Url.Action("PaymentTTTN", "Bill");
                    string Note           = "WEB BMT";
                    string UrlNLRedirecto = "https://www.nganluong.vn/[email protected]&product_name=" + CurrentSaleOrder.ID + "&price=" + CurrentSaleOrder.TotalPrice + "&return_url=" + ReturnUrlNganLuong + "&comments=" + Note;

                    return(Json(new ResponseMessage {
                        Message = SaleOrderBLL.Message, IsSuccess = isSuccess, errorSaleOrder = SaleOrderBLL.enumErrorSaleOrder, RedirectoURl = UrlNLRedirecto
                    }));
                }
                return(Json(new ResponseMessage {
                    Message = SaleOrderBLL.Message, IsSuccess = isSuccess, errorSaleOrder = SaleOrderBLL.enumErrorSaleOrder
                }));
            }
            else
            {
                return(Json(new ResponseMessage {
                    Message = SaleOrderBLL.Message, IsSuccess = isSuccess, errorSaleOrder = SaleOrderBLL.enumErrorSaleOrder
                }));
            }
        }
예제 #9
0
        public async Task SendAgainCode(CM_Customer Customer)
        {
            await sendCode(Customer);

            this.unitOfWork.CM_Customer_Repository.Update(Customer);
        }
예제 #10
0
        public async Task <Payment> CreatePayment(string SuccessURl, string ErrorUrl, SaleOrder saleOrder, List <SaleOrderDetail> listSaleOrderDetails, CM_Customer _Customer)
        {
            try
            {
                Amount amount = new Amount
                {
                    Currency = "USD",
                    Total    = FormatCurrencyUSDToPayPal(ExchangeMoneyCurrency(saleOrder.TotalPrice)),
                    Details  = new AmountDetails
                    {
                        Subtotal         = FormatCurrencyUSDToPayPal(ExchangeMoneyCurrency(saleOrder.TotalPrice) - ExchangeMoneyCurrency(saleOrder.TransportTypePrice)),
                        Shipping         = FormatCurrencyUSDToPayPal(ExchangeMoneyCurrency(saleOrder.TransportTypePrice)),
                        Tax              = "0.00",
                        HandlingFee      = "0.00",
                        Insurance        = "0.00",
                        ShippingDiscount = "0.00"
                    }
                };
                List <Item> listItem = new List <Item>();
                foreach (var detail in listSaleOrderDetails)
                {
                    Item item = new Item
                    {
                        Currency = "USD",
                        Price    = FormatCurrencyUSDToPayPal(ExchangeMoneyCurrency(detail.ProductDetail.Product.Price)),
                        Quantity = detail.Quality.ToString(),
                        Name     = detail.ProductDetail.Product.Model,
                    };
                    listItem.Add(item);
                }
                ItemList itemList = new ItemList
                {
                    Items = listItem
                };
                Transaction transaction = new Transaction
                {
                    Amount      = amount,
                    Description = "Phi tien cho Shop BMT",
                    ItemList    = itemList,

                    NoteToPayee = "Goi dien cho 0937019527 cho moi cau hoi",
                };
                return(await this._paypalServices.CreatePayment(SuccessURl, ErrorUrl, transaction));
            }
            catch (Exception objEx)
            {
                Exception exception = new Exception(objEx.Message + "loi goi paypal o sale" + saleOrder.ID);

                await AddError(exception);

                return(null);
            }
        }