예제 #1
0
        public ActionResult Edit(EditBrandModel brand)
        {
            var errors = ModelState
              .Where(x => x.Value.Errors.Count > 0)
              .Select(x => new { x.Key, x.Value.Errors })
              .ToArray();
            if (ModelState.IsValid)
            {
                var userToUpdatebrands = db.Brands.SingleOrDefault(u => u.BRND_id == brand.brndId);
            if (userToUpdatebrands != null)
            {
                userToUpdatebrands.BRND_Name = brand.BRND_Name;

                userToUpdatebrands.BRND_Description = brand.BRND_Description;
                if (brand.BRND_Img_Path != null)
                {
                    string ImageName = System.IO.Path.GetFileName(brand.BRND_Img_Path.FileName);
                    string physicalPath = Server.MapPath(ConfigurationManager.AppSettings["Mnu_ImgPath"] + ImageName);
                    brand.BRND_Img_Path.SaveAs(physicalPath);
                    //string targetPath = Server.MapPath(ConfigurationManager.AppSettings["RESZEFILEPATH"] + ImageName);
                    //brand.BRND_Img_Path.SaveAs(targetPath);
                    userToUpdatebrands.BRND_Img_Path = ImageName;
                    userToUpdatebrands.Is_Add_img = true;

                }
                userToUpdatebrands.Mod_User_Id= WebSecurity.CurrentUserId;
                userToUpdatebrands.Modify_Datetime = System.DateTime.Now;

                db.SaveChanges();
            }
            TempData["brnd_Message"] = ConfigurationManager.AppSettings["EDT_SUC"];
                return RedirectToAction("Index");

            }
            return View(brand);
        }
예제 #2
0
        public ActionResult Edit(int id = 0)
        {
            var model = from p in db.Brands
                        join m in db.Menus on p.cat_id equals m.Mnu_id
                        from sbtype in db.Menus.Where(e => e.Mnu_id == p.sub_cat_id).DefaultIfEmpty()
                        where p.BRND_id == id
                        select new EditBrandModel
                        {
                           brndId=p.BRND_id,
                           BRND_Name=p.BRND_Name,
                           BRND_Description=p.BRND_Description,
                           Category_id=p.cat_id,
                           Sub_Category_id=p.sub_cat_id,
                          BRND_Img_Path_name=p.BRND_Img_Path

                        };
            EditBrandModel editprddetails = null;
            foreach (var m in model)
            {
                editprddetails = new EditBrandModel();
                editprddetails.brndId = m.brndId;
                editprddetails.BRND_Name = m.BRND_Name;
                editprddetails.BRND_Description = m.BRND_Description;
                editprddetails.Category_id = m.Category_id;
                editprddetails.Sub_Category_id = m.Sub_Category_id;
                editprddetails.BRND_Img_Path_name = m.BRND_Img_Path_name;
            }

            var query = from c in db.Menus
                        where !(from o in db.menuTrees
                                where o.Parent_Menuid != 0
                                select o.Menu_id)
                               .Contains(c.Mnu_id)
                        select new { c.Mnu_id, c.Mnu_Name };
            ViewBag.Menus = new SelectList(query, "mnu_Id", "Mnu_Name", editprddetails.Category_id);

            var subcat = (from c in db.Menus
                          where (from o in db.menuTrees
                                 where o.Parent_Menuid != 0 && o.Parent_Menuid == editprddetails.Category_id
                                 select o.Menu_id)
                                 .Contains(c.Mnu_id)
                          select new { c.Mnu_id, c.Mnu_Name }).ToList();
            ViewBag.subcategory = new SelectList(subcat, "mnu_Id", "Mnu_Name", editprddetails.Sub_Category_id);

            return View(editprddetails);
        }