Пример #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");
        }
Пример #2
0
        public ActionResult Edit(EditOfferModel edtoffer)
        {
            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.SpecialOffers.SingleOrDefault(u => u.SpecialOfferID == edtoffer.splofferid);
                    if (userToUpdateproducts != null)
                    {
                       // userToUpdateproducts.offer_Code = edtoffer.offer_Code;
                        userToUpdateproducts.offer_Name = edtoffer.offer_Name;
                        userToUpdateproducts.Description = edtoffer.Description;
                        userToUpdateproducts.MinQty = Convert.ToInt32(edtoffer.MinQty);
                        userToUpdateproducts.MaxQty = Convert.ToInt32(edtoffer.MaxQty);
                        userToUpdateproducts.StartDate = edtoffer.StartDate;
                        userToUpdateproducts.EndDate = edtoffer.EndDate;
                        userToUpdateproducts.ModifiedUser = WebSecurity.CurrentUserId;
                        userToUpdateproducts.ModifiedDate = System.DateTime.Now;
                        //userToUpdateproducts.Type = edtoffer.Type;
                        if (edtoffer.AddBannerImgpath != null)
                        {
                                ImageName = System.IO.Path.GetFileName(edtoffer.AddBannerImgpath.FileName);
                                physicalPath = Server.MapPath(ConfigurationManager.AppSettings["ORIGINALPATH"] + ImageName);
                                edtoffer.AddBannerImgpath.SaveAs(physicalPath);
                                targetPath = Server.MapPath(ConfigurationManager.AppSettings["RESZEFILEPATH"] + ImageName);
                                edtoffer.AddBannerImgpath.SaveAs(targetPath);
                               userToUpdateproducts.Image_Path_Name=ImageName;

                        }
                       // userToUpdateproducts.usr_Category = edtoffer.usr_Category;
                        db.SaveChanges();
                    }
                    IList<SpecialOfferProduct> tvItem = (from p in db.SpecialOfferProducts
                                               where p.SpecialOfferID == edtoffer.splofferid
                                      select p).ToList();
                    foreach (SpecialOfferProduct s in tvItem)
                    {

                        db.SpecialOfferProducts.Remove(s);

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

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