Esempio n. 1
0
        public static Voucher VoucherConvert(object value)
        {
            var dapperRowProperties = value as IDictionary <string, object>;

            if (dapperRowProperties == null)
            {
                return(null);
            }
            switch (dapperRowProperties["voucherType"])
            {
            case 1:
                VoucherDiscount result = GetObject <VoucherDiscount>(dapperRowProperties);
                result.Percent = (int)dapperRowProperties["Percent"];
                return(GetObject <VoucherDiscount>(dapperRowProperties));

            case 2:
                VoucherDiscountPercentPerUnit result_ = GetObject <VoucherDiscountPercentPerUnit>(dapperRowProperties);
                result_.Percent          = (int)dapperRowProperties["Percent"];
                result_.applyPerCantUnit = (int)dapperRowProperties["applyPerCantUnit"];
                return(result_);

            case 3:
                return(GetObject <VoucherPayTwoTakeThree>(dapperRowProperties));

            default:
                return(null);
            }
        }
Esempio n. 2
0
        public async Task <ActionResult <VoucherDiscountPercentPerUnit> > Edit([FromBody] VoucherDiscountPercentPerUnit voucher)
        {
            if (voucher == null || !ModelState.IsValid)
            {
                return(BadRequest("Invalid State"));
            }

            return(await _voucherRepository.Edit((VoucherDiscountPercentPerUnit)voucher));
        }
Esempio n. 3
0
        public async Task <VoucherDiscountPercentPerUnit> Edit(VoucherDiscountPercentPerUnit voucher)
        {
            try
            {
                IEnumerable <int> categorys = voucher.validCategorys.Select <ProductCategory, int>(c => c.Id).ToArray();
                IEnumerable <int> products  = voucher.validProducts.Select <Product, int>(p => p.Id).ToArray();
                IEnumerable <int> days      = voucher.Days.Select <DayOfWeek, int>(p => (int)p).ToArray();

                using (IDbConnection con = Connection)
                {
                    string sQuery = "VoucherFunc";
                    con.Open();
                    DynamicParameters param = new DynamicParameters();
                    param.Add("@Mode", "EDIT");
                    param.Add("@Id", voucher.Id);

                    param.Add("@onUpTo", voucher.onUpTo);

                    param.Add("@validCategorys", categorys);

                    param.Add("@validProducts", products);
                    param.Add("@valid_from_day", voucher.valid_from_day);
                    param.Add("@valid_from_month", voucher.valid_from_month);
                    param.Add("@valid_from_year", voucher.valid_from_year);
                    param.Add("@valid_to_day", voucher.valid_to_day);
                    param.Add("@valid_to_month", voucher.valid_to_month);
                    param.Add("@valid_to_year", voucher.valid_to_year);
                    param.Add("@valid_days", days);
                    param.Add("@voucherType", 1);

                    var result = await con.QueryAsync <VoucherDiscountPercentPerUnit>(sQuery, param, commandType : CommandType.StoredProcedure);

                    return(result.FirstOrDefault());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 4
0
        public Voucher GetVoucher(String id)
        {
            Voucher voucherResult;

            switch (id)
            {
            case "COCO1V1F8XOG1MZZ":
                // 20% off on Wednesdays and Thursdays, on Cleaning products, from Jan 27th to Feb 13th
                voucherResult    = new VoucherDiscount(20);
                voucherResult.Id = id;
                // Setting id
                voucherResult.Id = "COCO1V1F8XOG1MZZ";
                // Valid Vaouchers Week Days
                voucherResult.Days.Add(DayOfWeek.Wednesday);
                voucherResult.Days.Add(DayOfWeek.Thursday);
                // Valid Period
                voucherResult.valid_from_day   = 27;
                voucherResult.valid_from_month = (int)Month.January;
                voucherResult.valid_to_day     = 13;
                voucherResult.valid_to_month   = (int)Month.February;
                // Valid Category (Cleaning)
                voucherResult.validCategorys.Add(getMockProductCategory(ProductCategoryType.Cleaning));
                break;

            case "COCOKCUD0Z9LUKBN":
                // Pay 2 take 3 on "Windmill Cookies" on up to 6 units, from Jan 24th to Feb 6th
                voucherResult = new VoucherPayTwoTakeThree();
                // Setting id
                voucherResult.Id = id;
                // Valid Vaouchers up to 6 units
                voucherResult.onUpTo = 6;
                // Valid Period 24 January to 6th February
                voucherResult.valid_from_day   = 24;
                voucherResult.valid_from_month = (int)Month.January;
                voucherResult.valid_to_day     = 6;
                voucherResult.valid_to_month   = (int)Month.February;
                voucherResult.validProducts.Add(getMockProduct(8, "Windmill Cookies", 100, ProductCategoryType.Food));
                break;

            case "COCOG730CNSG8ZVX":
                // 10% off on Bathroom and Sodas, from Jan 31th to Feb 9th
                voucherResult = new VoucherDiscount(10);
                // Setting id
                voucherResult.Id = id;
                // Valid Period
                voucherResult.valid_from_day   = 31;
                voucherResult.valid_from_month = (int)Month.January;
                voucherResult.valid_to_day     = 9;
                voucherResult.valid_to_month   = (int)Month.February;
                // Valid Category (Bathroom,Sodas)
                voucherResult.validCategorys.Add(getMockProductCategory(ProductCategoryType.Bathroom));
                voucherResult.validCategorys.Add(getMockProductCategory(ProductCategoryType.Sodas));
                break;

            case "COCO2O1USLC6QR22":
                /// 30% off on the second unit (of the same product), on "Nuka-Cola", "Slurm" and "Diet Slurm", for all February
                voucherResult = new VoucherDiscountPercentPerUnit(0, 30, 2);
                // Setting id
                voucherResult.Id = id;
                // Valid Period
                voucherResult.valid_from_month = (int)Month.February;
                voucherResult.valid_to_month   = (int)Month.February;
                // Valid Product: Slurm,Nuke-Cola, Diet Slurm
                voucherResult.validProducts.Add(getMockProduct(5, "Slurm", 100, ProductCategoryType.Sodas));
                voucherResult.validProducts.Add(getMockProduct(3, "Nuke-Cola", 100, ProductCategoryType.Sodas));
                voucherResult.validProducts.Add(getMockProduct(6, "Diet Slurm", 100, ProductCategoryType.Sodas));
                break;

            case "COCO0FLEQ287CC05":
                // 50% off on the second unit (of the same product), on "Hang -yourself toothpaste", only on Mondays, first half of February."
                voucherResult = new VoucherDiscountPercentPerUnit(0, 50, 2);
                // Setting id
                voucherResult.Id = id;
                // Valid Period
                voucherResult.Days.Add(DayOfWeek.Monday);
                voucherResult.valid_from_month = (int)Month.February;
                voucherResult.valid_from_day   = 1;
                voucherResult.valid_to_month   = (int)Month.February;
                voucherResult.valid_to_day     = 15;
                // Valid Product: Hang -yourself toothpaste
                voucherResult.validProducts.Add(getMockProduct(23, "Hang -yourself toothpaste", 100, ProductCategoryType.Bathroom));
                break;

            default:
                throw new Exception("UnitTestVoucher: no result.");
                break;
            }
            return(voucherResult);
        }