示例#1
0
        protected void Import_OnClick(object sender, EventArgs e)
        {
            if (ImportDiscountFileUpload.HasFile)
            {
                using (var reader = new StreamReader(ImportDiscountFileUpload.FileContent))
                    using (var csvReader = new CsvReader(reader))
                    {
                        csvReader.Configuration.HasHeaderRecord = false;
                        csvReader.Configuration.RegisterClassMap <InportDiscountObjectMap>();
                        // Use While(csvReader.Read()); if you want to read all the rows in the records)
                        csvReader.Read();
                        var result = csvReader.GetRecords <InportDiscountObject>().ToList();

                        var discounts = Mapper.Map <List <InportDiscountObject>, List <Discounts> >(result);

                        _discountRepository.Add(discounts);

                        _discountRepository.RefreshData();
                    }

                ImportDiscountFileUpload.SaveAs(Server.MapPath("~/Helper/") + ImportDiscountFileUpload.FileName);
            }
        }
示例#2
0
        protected void SaveDiscountClick(object sender, EventArgs e)
        {
            LblMessage.Visible = false;
            LblMessage.Text    = "";

            if (string.IsNullOrEmpty(DiscountNameText.Text.Trim()))
            {
                LblMessage.Visible = true;
                LblMessage.Text    = "Discount Name is required";
                return;
            }

            if (string.IsNullOrEmpty(StartDateText.Text) || string.IsNullOrEmpty(EndDateText.Text))
            {
                LblMessage.Visible = true;
                LblMessage.Text    = "Start Date and End Date is required";
                return;
            }

            if (string.IsNullOrEmpty(CodeText.Text.Trim()))
            {
                LblMessage.Visible = true;
                LblMessage.Text    = "Code is required";
                return;
            }

            if (string.IsNullOrEmpty(PercentOffText.Text.Trim()))
            {
                LblMessage.Visible = true;
                LblMessage.Text    = "Percent Off is required";
                return;
            }

            int    discountId = int.Parse(Request.Params["id"]);
            double percentOff;

            double.TryParse(PercentOffText.Text, out percentOff);

            double minAmount;

            double.TryParse(MinAmountText.Text, out minAmount);

            DateTime startDate;

            DateTime.TryParseExact(StartDateText.Text, "MM/dd/yyyy", null, DateTimeStyles.None, out startDate);
            DateTime endDate;

            DateTime.TryParseExact(EndDateText.Text, "MM/dd/yyyy", null, DateTimeStyles.None, out endDate);

            if (startDate.Date > endDate.Date)
            {
                LblMessage.Visible = true;
                LblMessage.Text    = "Start Date should not be greater than End Date";
                return;
            }

            bool isCodeRequired;

            bool.TryParse(IsCodeRequiredHidden.Value, out isCodeRequired);

            bool isAllProducts;

            bool.TryParse(IsAllProductHidden.Value, out isAllProducts);

            if (discountId == 0)
            {
                _discounts = new Discounts
                {
                    DiscountName       = DiscountNameText.Text.Trim(),
                    Code               = CodeText.Text.Trim(),
                    StartDate          = startDate,
                    EndDate            = endDate,
                    CodeRequired       = isCodeRequired,
                    PercentOff         = percentOff,
                    PromoType          = byte.Parse(PromoTypeDdl.SelectedValue),
                    MinAmount          = minAmount,
                    IsAllProducts      = isAllProducts,
                    MaxPurchases       = byte.Parse(MaxPurchasesDdl.SelectedValue),
                    FinePrint          = FinePrintText.Text,
                    BillingCycleNumber = byte.Parse(BillingCycleDdl.SelectedValue)
                };
                try
                {
                    discountId = _discountRepository.Add(_discounts);
                }
                catch (Exception ex)
                {
                    LblMessage.Visible = true;
                    LblMessage.Text    = ex.Message;
                    return;
                }
            }
            else
            {
                _discounts = _discountRepository.GetById(discountId);
                _discounts.DiscountName       = DiscountNameText.Text.Trim();
                _discounts.StartDate          = startDate;
                _discounts.EndDate            = endDate;
                _discounts.Code               = CodeText.Text.Trim();
                _discounts.PercentOff         = percentOff;
                _discounts.CodeRequired       = isCodeRequired;
                _discounts.PromoType          = byte.Parse(PromoTypeDdl.SelectedValue);
                _discounts.MinAmount          = minAmount;
                _discounts.IsAllProducts      = isAllProducts;
                _discounts.MaxPurchases       = byte.Parse(MaxPurchasesDdl.SelectedValue);
                _discounts.FinePrint          = FinePrintText.Text;
                _discounts.BillingCycleNumber = byte.Parse(BillingCycleDdl.SelectedValue);

                _discountRepository.Update(_discounts);
            }

            _discountRepository.ResetCache();
            RebindDiscount(discountId);

            Response.Redirect(Constant.PromoDetailPage + "?id=" + discountId);
        }