Ejemplo n.º 1
0
        public static String AddClientVoucherCodes(HttpContext context)
        {
            try
            {
                var strOut = "Missing data ('userid', 'portalid' hidden fields needed on input form)";

                //get uploaded params
                var settings = NBrightBuyUtils.GetAjaxDictionary(context);
                if (!settings.ContainsKey("addqty"))
                {
                    settings.Add("addqty", "1");
                }
                if (!settings.ContainsKey("userid"))
                {
                    settings.Add("userid", "");
                }
                var userid = settings["userid"];
                if (!settings.ContainsKey("portalid"))
                {
                    settings.Add("portalid", "");
                }
                var portalid = settings["portalid"];
                if (Utils.IsNumeric(portalid) && Utils.IsNumeric(userid))
                {
                    var clientData = new ClientData(Convert.ToInt32(portalid), Convert.ToInt32(userid));

                    var qty = settings["addqty"];
                    if (!Utils.IsNumeric(qty))
                    {
                        qty = "1";
                    }

                    var lp         = 1;
                    var modelcount = clientData.VoucherCodes.Count;
                    while (lp <= Convert.ToInt32(qty))
                    {
                        clientData.AddNewVoucherCode();
                        lp += 1;
                        if (lp > 10)
                        {
                            break;          // we don;t want to create a stupid amount, it will slow the system!!!
                        }
                    }
                    clientData.Save();
                }
                return(strOut);
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }