Example #1
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();
        }
Example #2
0
 private void EditSetChildren(EditOfferModel model, List<EditOfferModel> userList, int splofferid)
 {
     var childs = userList.
                     Where(x => x.parent_name == model.Item_Name).ToList();
     if (childs.Count > 0)
     {
         foreach (var child in childs)
         {
             EditSetChildren(child, userList, splofferid);
             model.tvlists.Add(child);
         }
     }
 }
Example #3
0
        public ActionResult Edit(int id = 0)
        {
            EditOfferModel editofferdetails = new EditOfferModel();
            var treeview = db.GetTreeView();
            List<EditOfferModel> userList=new List<EditOfferModel>();

            //userList = (from t in db.TreeviewLists
            //            join S in db.SpecialOfferProducts.Where(x => x.SpecialOfferID == id) on new { a = t.menu_id, b = t.origin } equals new { a = S.ProductID, b = S.PDT_TYPE }
            //            into tvGroup
            //            from p in tvGroup.DefaultIfEmpty()
            //            //where itemOffer.SpecialOfferID == id
            //            select new EditOfferModel
            //            {
            //                id = t.id,
            //                menu_id = t.menu_id,
            //                Parent_Menuid = t.Parent_Menuid,
            //                origin = t.origin,
            //                Item_Name = t.Item_Name,
            //                parent_name = t.parent_name,
            //                Discountpct = (p.DiscountPct == null ? null : p.DiscountPct),
            //                offer_id = (p.OFR_VAL_TYPE == null ? null : p.OFR_VAL_TYPE)

            //            }).ToList();

            editofferdetails = userList.
                              Where(x => x.parent_name == "XYA").FirstOrDefault();
            EditSetChildren(editofferdetails, userList, id);
            ViewBag.offers = new SelectList(db.OFFER_VALUE_TYPE, "OFR_VAl_Type_Id", "Ofr_Value_type");

            var model = from p in db.SpecialOffers
                        where p.SpecialOfferID == id
                        select new
                        {
                            p.offer_Code,
                            p.offer_Name,
                            p.SpecialOfferID,
                            p.Type,
                            p.usr_Category,
                            p.Image_Path_Name,
                            p.MinQty,
                            p.MaxQty,
                            p.StartDate,
                            p.EndDate,
                            p.Description
                        };

            foreach (var m in model)
            {
                // editofferdetails = new EditOfferModel();
                editofferdetails.offer_Code = m.offer_Code;
                editofferdetails.offer_Name = m.offer_Name;
                editofferdetails.splofferid = m.SpecialOfferID;
                editofferdetails.Type = m.Type;
                editofferdetails.usr_Category = m.usr_Category;
                editofferdetails.AddBnrimageName = m.Image_Path_Name;
                editofferdetails.MinQty = m.MinQty;
                editofferdetails.MaxQty = m.MaxQty;
                editofferdetails.StartDate = m.StartDate;
                editofferdetails.EndDate = m.EndDate;
                editofferdetails.Description = m.Description;
            }

            return View(editofferdetails);
        }