예제 #1
0
        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();
        }
예제 #2
0
        public ActionResult Edit(EditCouponModel edtCoupon)
        {
            string strPdtNames = Request["PDT_Names"];
            string strPdtdiscnt = Request["PDT_Discnt"];
            string strPdtofrtype = Request["PDT_OFRTYPE"];
            string ImageName, physicalPath, targetPath;

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

                    var userToUpdateproducts = db.Coupon_Code.SingleOrDefault(u => u.Cupn_Id == edtCoupon.Couponid);
                    if (userToUpdateproducts != null)
                    {
                        // userToUpdateproducts.Coupon_Code = edtCoupon.Coupon_Code;
                        userToUpdateproducts.Cupn_Name = edtCoupon.Coupon_Name;
                        userToUpdateproducts.Description = edtCoupon.Description;
                        userToUpdateproducts.MinQty = Convert.ToInt32(edtCoupon.MinQty);
                        userToUpdateproducts.MaxQty = Convert.ToInt32(edtCoupon.MaxQty);
                        userToUpdateproducts.StartDate = edtCoupon.StartDate;
                        userToUpdateproducts.EndDate = edtCoupon.EndDate;
                        userToUpdateproducts.ModifiedUser = WebSecurity.CurrentUserId;
                        userToUpdateproducts.ModifiedDate = System.DateTime.Now;
                        userToUpdateproducts.user_id = edtCoupon.userid;
                        db.SaveChanges();
                    }
                    IList<CouponProduct> tvItem = (from p in db.CouponProducts
                                                         where p.CupnID == edtCoupon.Couponid
                                                         select p).ToList();
                    foreach (CouponProduct s in tvItem)
                    {

                        db.CouponProducts.Remove(s);

                    }
                    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 = edtCoupon.Couponid;
                                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["EDT_SUC"];
                    return RedirectToAction("Index");

                }
                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();
        }