Esempio n. 1
0
        public ActionResult Create(Brand brand)
        {
            if (ModelState.IsValid)
            {
                db.Brands.Add(brand);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(brand);
        }
Esempio n. 2
0
        public ActionResult Create(AddBrandModel brand)
        {
            //  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
                    Brand objnewbrand = new Brand();
                    objnewbrand.BRND_id = (db.Brands.Max(i => (int?)i.BRND_id) ?? 0) + 1;  //Convert.ToInt32(db.PRODUCTs.Max(x => x.Pid)) + 1;
                    objnewbrand.BRND_Name = brand.BRND_Name;
                    objnewbrand.BRND_Description = brand.BRND_Description;
                    objnewbrand.IsActive = true;
                    objnewbrand.cat_id = brand.Category_id;
                    objnewbrand.sub_cat_id = brand.Sub_Category_id;
                    objnewbrand.BRND_Img_Path = string.Empty;
                    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);
                        objnewbrand.BRND_Img_Path = ImageName;
                        objnewbrand.Is_Add_img = true;

                    }
                    objnewbrand.Add_User_id = WebSecurity.CurrentUserId;
                    objnewbrand.Mod_User_Id = WebSecurity.CurrentUserId;
                    objnewbrand.Add_Datetime = System.DateTime.Now;
                    objnewbrand.Modify_Datetime = System.DateTime.Now;
                    db.Brands.Add(objnewbrand);
                    db.SaveChanges();
                    TempData["brnd_Message"] = ConfigurationManager.AppSettings["INS_SUC"];
                    ModelState.Clear();

                }

                catch (Exception exception)
                {

                }

                return RedirectToAction("Create", "Brand");

            }

            return View(brand);
        }
Esempio n. 3
0
 public ActionResult Edit(Brand brand)
 {
     if (ModelState.IsValid)
     {
         db.Entry(brand).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(brand);
 }