public ActionResult Create(CouponModel Coupon)
        {
            string strPdtNames = Request["PDT_Names"];
            string strPdtdiscnt = Request["PDT_Discnt"];
            string strPdtofrtype = Request["PDT_OFRTYPE"];

            //  var errors = ModelState
            //.Where(x => x.Value.Errors.Count > 0)
            //.Select(x => new { x.Key, x.Value.Errors })
            //.ToArray();
            if (ModelState.IsValid)
            {
                try
                {

                    // Insert Product
                    int Cupn_Id = (db.Coupon_Code.Max(i => (int?)i.Cupn_Id) ?? 0) + 1;
                    Coupon_Code objnewCupn = new Coupon_Code();
                    // objnewCupn.Cupn_Id = Cupn_Id;
                    objnewCupn.Cupn_Code = Coupon.cupn_Code;
                    objnewCupn.Cupn_Name = Coupon.cupn_Name;
                    objnewCupn.Description = Coupon.Description;
                    objnewCupn.StartDate = Coupon.StartDate;
                    objnewCupn.EndDate = Coupon.EndDate;
                    objnewCupn.MinQty = Convert.ToInt32(Coupon.MinQty);
                    objnewCupn.MaxQty = Convert.ToInt32(Coupon.MaxQty);
                    objnewCupn.Active = true;
                    objnewCupn.user_id = Coupon.userid;
                    objnewCupn.Adduser = WebSecurity.CurrentUserId;
                    objnewCupn.ModifiedUser = WebSecurity.CurrentUserId;
                    objnewCupn.AddDatetime = System.DateTime.Now;
                    objnewCupn.ModifiedDate = System.DateTime.Now;
                    db.Coupon_Code.Add(objnewCupn);
                    db.SaveChanges();

                    foreach (var m in strPdtNames.Split('{'))
                    {

                        if (m != "[")
                        {
                            if (!string.IsNullOrEmpty(m.Split(',')[1].Split(':')[1].ToString().Replace("\"", "")))
                            {
                                CouponProduct objcupnPdt = new CouponProduct();
                                objcupnPdt.cupn_No = (db.CouponProducts.Max(i => (int?)i.cupn_No) ?? 0) + 1;
                                objcupnPdt.CupnID = Cupn_Id;
                                objcupnPdt.DiscountPct = Convert.ToInt32(m.Split(',')[1].Split(':')[1].ToString().Replace("\"", ""));
                                objcupnPdt.OFR_VAL_TYPE = Convert.ToInt32(m.Split(',')[2].Split(':')[1].ToString().Replace("\"", ""));
                                objcupnPdt.ProductID = Convert.ToInt32(m.Split(',')[3].Split(':')[1].ToString().Replace("\"", ""));
                                objcupnPdt.PDT_TYPE = m.Split(',')[4].Split(':')[1].ToString().Replace("\"", "").Replace("}", "").Replace("]", "");
                                objcupnPdt.Adduser = WebSecurity.CurrentUserId;
                                objcupnPdt.ModifiedUser = WebSecurity.CurrentUserId;
                                objcupnPdt.AddDatetime = System.DateTime.Now;
                                objcupnPdt.ModifiedDate = System.DateTime.Now;
                                db.CouponProducts.Add(objcupnPdt);
                                db.SaveChanges();
                            }
                        }
                    }
                    TempData["Coupon_Message"] = ConfigurationManager.AppSettings["INS_SUC"];
                    ModelState.Clear();
                    ViewBag.offers = new SelectList(db.OFFER_VALUE_TYPE, "OFR_VAl_Type_Id", "Ofr_Value_type");
                    var stands = db.User_Info.ToList().Select(s => new { ID = s.UidNo, Name = string.Format("{0}, {1}", s.First_name, s.Last_name) });
                    ViewBag.users = new SelectList(stands, "ID", "Name");
                    return RedirectToAction("Create", "Coupon");
                }
                catch
                {
                    ViewBag.offers = new SelectList(db.OFFER_VALUE_TYPE, "OFR_VAl_Type_Id", "Ofr_Value_type");
                    var stands = db.User_Info.ToList().Select(s => new { ID = s.UidNo, Name = string.Format("{0}, {1}", s.First_name, s.Last_name) });
                    ViewBag.users = new SelectList(stands, "ID", "Name");
                    return View();
                }
            }
            ViewBag.offers = new SelectList(db.OFFER_VALUE_TYPE, "OFR_VAl_Type_Id", "Ofr_Value_type");
            var stands1 = db.User_Info.ToList().Select(s => new { ID = s.UidNo, Name = string.Format("{0}, {1}", s.First_name, s.Last_name) });
            ViewBag.users = new SelectList(stands1, "ID", "Name");
            return View();
        }
 private void SetChildren(CouponModel model, List<CouponModel> userList)
 {
     var childs = userList.
                     Where(x => x.parent_name == model.Item_Name).ToList();
     if (childs.Count > 0)
     {
         foreach (var child in childs)
         {
             SetChildren(child, userList);
             model.tvlists.Add(child);
         }
     }
 }