Ejemplo n.º 1
0
        public ActionResult Create(OfferModel offer)
        {
            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 SpecialOfferID = (db.SpecialOffers.Max(i => (int?)i.SpecialOfferID) ?? 0) + 1;
                    SpecialOffer objnewOffer = new SpecialOffer();
                    // objnewOffer.SpecialOfferID = SpecialOfferID;
                    objnewOffer.offer_Code = offer.offer_Code;
                    objnewOffer.offer_Name = offer.offer_Name;
                    objnewOffer.Description = offer.Description;
                    objnewOffer.Type ="D";
                    objnewOffer.usr_Category ="O";
                    objnewOffer.StartDate = offer.StartDate;
                    objnewOffer.EndDate = offer.EndDate;
                    objnewOffer.MinQty = Convert.ToInt32(offer.MinQty);
                    objnewOffer.MaxQty = Convert.ToInt32(offer.MaxQty);
                    if (offer.AddBannerImgpath != null)
                    {
                        string ImageName = System.IO.Path.GetFileName(offer.AddBannerImgpath.FileName);
                        string physicalPath = Server.MapPath(ConfigurationManager.AppSettings["ORIGINALPATH"] + ImageName);
                        offer.AddBannerImgpath.SaveAs(physicalPath);
                        string targetPath = Server.MapPath(ConfigurationManager.AppSettings["RESZEFILEPATH"] + ImageName);
                        offer.AddBannerImgpath.SaveAs(targetPath);
                        objnewOffer.Image_Path_Name = ImageName;
                    }
                   // objnewOffer.Image_Path_Name = "";
                    objnewOffer.Active = true;
                    objnewOffer.Adduser = WebSecurity.CurrentUserId;
                    objnewOffer.ModifiedUser = WebSecurity.CurrentUserId;
                    objnewOffer.AddDatetime = System.DateTime.Now;
                    objnewOffer.ModifiedDate = System.DateTime.Now;
                    db.SpecialOffers.Add(objnewOffer);
                    db.SaveChanges();

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

                        if (m != "[")
                        {
                            if(!string.IsNullOrEmpty(m.Split(',')[1].Split(':')[1].ToString().Replace("\"", "")))
                            {
                            SpecialOfferProduct objOfferPdt = new SpecialOfferProduct();
                            objOfferPdt.SeqNo = (db.SpecialOfferProducts.Max(i => (int?)i.SeqNo) ?? 0) + 1;
                            objOfferPdt.SpecialOfferID = SpecialOfferID;
                            objOfferPdt.DiscountPct = Convert.ToInt32(m.Split(',')[1].Split(':')[1].ToString().Replace("\"", ""));
                            objOfferPdt.OFR_VAL_TYPE = Convert.ToInt32(m.Split(',')[2].Split(':')[1].ToString().Replace("\"", ""));
                            objOfferPdt.ProductID = Convert.ToInt32(m.Split(',')[3].Split(':')[1].ToString().Replace("\"", ""));
                            objOfferPdt.PDT_TYPE = m.Split(',')[4].Split(':')[1].ToString().Replace("\"", "").Replace("}", "").Replace("]", "");
                            objOfferPdt.Adduser = WebSecurity.CurrentUserId;
                            objOfferPdt.ModifiedUser = WebSecurity.CurrentUserId;
                            objOfferPdt.AddDatetime = System.DateTime.Now;
                            objOfferPdt.ModifiedDate = System.DateTime.Now;
                            db.SpecialOfferProducts.Add(objOfferPdt);
                            db.SaveChanges();
                            }
                        }
                    }
                    TempData["Offer_Message"] = ConfigurationManager.AppSettings["INS_SUC"];

                    ModelState.Clear();

                    return RedirectToAction("Create", "Offer");
                }
                catch
                {
                    ViewBag.offers = new SelectList(db.OFFER_VALUE_TYPE, "OFR_VAl_Type_Id", "Ofr_Value_type");
                    return View();
                }
            }
            ViewBag.offers = new SelectList(db.OFFER_VALUE_TYPE, "OFR_VAl_Type_Id", "Ofr_Value_type");
            return RedirectToAction("Create", "Offer");
        }
Ejemplo n.º 2
0
 private void SetChildren(OfferModel model, List<OfferModel> 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);
         }
     }
 }