コード例 #1
0
        public IActionResult GeneratePromoCode(GeneratePromoCodeRequest _request)
        {
            string APIName = "GeneratePromoCode";

            log.LogInformation($"{APIName}\r\njson={StringHelper.SerializeObject(_request)}");
            try
            {
                var response = repo.PromoCode.GeneratePromoCode(_request);
                if (response.StatusCode == 200)
                {
                    log.LogInformation($"{APIName}\r\n Success ");
                    return(Ok(response));
                }
                else
                {
                    log.LogError($"{APIName}\r\nStautsCode:{response.StatusCode}\r\nErrorType:{response.ErrorType}" +
                                 $"\r\nErrorMsg:{response.ErrorMessage}");
                    return(StatusCode(response.StatusCode, response.GetError()));
                }
            }
            catch (Exception e)
            {
                log.LogError($"{APIName}\r\n{e}");
                return(StatusCode(500, new Error("internal-error", e.Message)));
            }
        }
コード例 #2
0
        public GeneratePromoCodeResponse GeneratePromoCode(GeneratePromoCodeRequest _request)
        {
            GeneratePromoCodeResponse response = new GeneratePromoCodeResponse();
            var order = (from o in db_Evoucher.TblPurchaseOrders
                         where o.PurchaseOrderNo == _request.PurchaseOrder_No &&
                         o.VoucherGenerated == false
                         select o
                         ).FirstOrDefault();

            if (order != null)
            {
                for (int i = 0; i < order.Quantity; i++)
                {
                    bool   isUnique  = false;
                    string promoCode = StringHelper.GeneatePromo();
                    string qrCodePath;
                    do
                    {
                        isUnique = !(from gp in db_Evoucher.TblGeneratedEvouchers
                                     where gp.PromoCode == promoCode
                                     select true
                                     ).FirstOrDefault();
                    } while (!isUnique);

                    qrCodePath = QRCodeHelper.GenerateQRCode(promoCode);

                    if (qrCodePath != "")
                    {
                        TblGeneratedEvoucher generatedEvoucher = new TblGeneratedEvoucher
                        {
                            ExpiryDate       = order.ExpiryDate,
                            OwnerName        = order.BuyerName,
                            OwnerPhone       = order.BuyerPhone,
                            PromoCode        = promoCode,
                            PurchaseOrderNo  = order.PurchaseOrderNo,
                            QrImagePath      = qrCodePath,
                            Status           = (int)RecordStatus.Active,
                            VoncherAmount    = order.VoncherAmount,
                            VoucherImagePath = order.ImagePath,
                            VoucherNo        = order.VoucherNo
                        };

                        db_Evoucher.TblGeneratedEvouchers.Add(generatedEvoucher);
                    }
                }
                order.VoucherGenerated = true;
            }
            else
            {
                response.StatusCode   = 404;
                response.ErrorType    = "Not-Found";
                response.ErrorMessage = "Record Not Found";
            }
            db_Evoucher.SaveChanges();
            response.PromoCodeGenerated = true;

            return(response);
        }
コード例 #3
0
        public void ScheduleGeneratePromoCode(GeneratePromoCodeRequest _requestData)
        {
            var serviceURL = configuration["PromoCodeServiceURL"];
            var client     = new RestClient(serviceURL);
            var request    = new RestRequest(serviceURL + "/v1/PromoService/GeneratePromoCode");

            request.Method = Method.POST;
            request.AddJsonBody(_requestData);
            var resp = client.Execute(request);
        }