public async Task <ActionResult> CreateCode([FromBody] Code_Config code_Config)
        {
            GeneratedCode code = new GeneratedCode();

            code = await CreateCodeRequest.CreateCode(code_Config);

            return(Ok(code));
        }
예제 #2
0
        public static async Task <GeneratedCode> CreateCode(Code_Config code_Config)
        {
            try
            {
                CodeGenerator codeGenerator = new CodeGenerator();
                GeneratedCode result        = new GeneratedCode();
                result.VoucherCode = await codeGenerator.GetGeneratedCode(code_Config.prefix, code_Config.suffix, code_Config.length, code_Config.charset);

                //response using predefined serviceresponse class
                ServiceResponse response = new ServiceResponse("0", "Good Request", "Request Completed");
                return(result);
            }
            catch (Exception e)
            {
                //error response
                ServiceResponse response = new ServiceResponse("100", "Unsuccessful", "Request could not be completed");
            }
            return(null);
        }
        public async Task <ActionResult> UpdateVoucher(string code, [FromBody] VoucherModel update)
        {
            //Passing in values using "VoucherModel" into the Different Model to use params
            Voucher     voucher     = new Voucher(update.Code, update.Voucher_Type, update.Category, update.AdditionalInfo, update.StartDate, update.ExpirationDate, update.Active);
            Discount    discount    = new Discount(update.Discount_Type, update.Percent_Off, update.Amount_Off, update.AmountLimit, update.Unit_Off, update.UnitType);
            Gift        gift        = new Gift(update.Amount);
            Redemption  redemption  = new Redemption(update.Quantity);
            Code_Config code_Config = new Code_Config(update.Prefix, update.Suffix, update.CodeLength, update.CharSet);
            MetaData    metadata    = new MetaData(update.Test, update.Locale);

            //Run CreateVoucherAsync Service and returns response with ServiceResponse class
            ServiceResponse response = await CreateVoucherRequest.CreateVoucherAsync(voucher, discount, gift, redemption, code_Config, metadata);

            //Checks if response status code is 200, if true returns voucher params and values as Json data, else returns response(Not successful)
            switch (Response.StatusCode == 200)
            {
            case true:
                return(Ok(update));

            default:
                return(Ok(response));
            }
        }
        public static async Task <ServiceResponse> CreateVoucherAsync(Voucher voucher, Discount discount, Gift gift, Redemption redemption, Code_Config code_Config, MetaData metaData)
        {
            try
            {
                int rowAffected = 0;
                using (var conn = Connection)
                {
                    if (conn.State == ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    //Parameters Declaration to be passed into Stored procdure "InsertVoucher"..
                    DynamicParameters parameters = new DynamicParameters();
                    parameters.Add("@Code", voucher.Code);
                    parameters.Add("@VoucherType", voucher.Voucher_type);
                    parameters.Add("@DiscountType", discount.Discount_type);
                    parameters.Add("@DiscountPercentOff", discount.Percent_Off);
                    parameters.Add("@DiscountAmountOff", discount.Amount_Off);
                    parameters.Add("@DiscountAmountLimit", discount.AmountLimit);
                    parameters.Add("@DiscountUnitOff", discount.Unit_Off);
                    parameters.Add("@DiscountUnitType", discount.Unit_Type);
                    parameters.Add("@GiftAmount", gift.Amount);
                    parameters.Add("@VoucherCategory", voucher.Category);
                    parameters.Add("@VoucherAdditionalInfo", voucher.Additional_Info);
                    parameters.Add("@VoucherStartDate", voucher.Start_Date);
                    parameters.Add("@VoucherExpirationDate", voucher.Expiration_Date);
                    parameters.Add("@VoucherActiveStatus", voucher.Active);
                    parameters.Add("@RedemptionQuantity", redemption.Quantity);
                    parameters.Add("@CodePrefix", code_Config.prefix);
                    parameters.Add("@CodeSuffix", code_Config.suffix);
                    parameters.Add("@CodeLength", code_Config.length);
                    parameters.Add("@CodeCharset", code_Config.charset);
                    parameters.Add("@VoucherMetaData", metaData.Meta_Data);

                    rowAffected = await conn.ExecuteAsync("InsertVoucher", parameters, commandType : CommandType.StoredProcedure);
                }

                //response using predefined serviceresponse class
                ServiceResponse response = new ServiceResponse("0", "Good Request", "Request Completed");
                return(response);
            }
            catch (Exception e)
            {
                //error response
                ServiceResponse response = new ServiceResponse("100", "Unsuccessful", "Request could not be completed");
                return(response);
            }
        }
예제 #5
0
        public async static Task <ServiceResponse> UpdateVoucherAsync(Voucher voucher, Discount discount, Gift gift, Redemption redemption, Code_Config codeconfig, MetaData metaData)
        {
            ServiceResponse sresponse = null;

            try
            {
                using (var conn = Connection)
                {
                    if (conn.State == System.Data.ConnectionState.Closed)
                    {
                        conn.Open();
                    }

                    //Parameters Declaration to be passed into Stored procdure "InsertVoucher"..
                    DynamicParameters parameters = new DynamicParameters();
                    parameters.Add("@Code", voucher.Code);
                    parameters.Add("@VoucherType", voucher.Voucher_type);
                    parameters.Add("@DiscountType", discount.Discount_type);
                    parameters.Add("@DiscountPercentOff", discount.Percent_Off);
                    parameters.Add("@DiscountAmountOff", discount.Amount_Off);
                    parameters.Add("@DiscountAmountLimit", discount.AmountLimit);
                    parameters.Add("@DiscountUnitOff", discount.Unit_Off);
                    parameters.Add("@DiscountUnitType", discount.Unit_Type);
                    parameters.Add("@GiftAmount", gift.Amount);
                    parameters.Add("@VoucherCategory", voucher.Category);
                    parameters.Add("@VoucherAdditionalInfo", voucher.Additional_Info);
                    parameters.Add("@VoucherStartDate", voucher.Start_Date);
                    parameters.Add("@VoucherExpirationDate", voucher.Expiration_Date);
                    parameters.Add("@VoucherActiveStatus", voucher.Active);
                    parameters.Add("@RedemptionQuantity", redemption.Quantity);
                    parameters.Add("@CodePrefix", codeconfig.prefix);
                    parameters.Add("@CodeSuffix", codeconfig.suffix);
                    parameters.Add("@CodeLength", codeconfig.length);
                    parameters.Add("@CodeCharset", codeconfig.charset);
                    parameters.Add("@VoucherMetaData", metaData.Meta_Data);

                    await conn.ExecuteAsync("UpdateVoucher", parameters, commandType : System.Data.CommandType.StoredProcedure);

                    sresponse = new ServiceResponse("200", "Successful", "Voucher has been Updated");
                }
                return(sresponse);
            }
            catch (AggregateException ae)
            {
                return(sresponse = new ServiceResponse("400", "Unsuccessful", ae.Message));
            }
        }