コード例 #1
0
        public ActionResult editmanufacturer(manufacture_vm mv)
        {
            string           path = "";
            manufacturer_tbl mt   = new manufacturer_tbl();

            if (ModelState.IsValid)
            {
                mt.brand_name      = mv.brand_name;
                mt.manufacturer_id = mv.manufacturer_id;
                mt.sort_order      = mv.sort_order;
                if (mv.file != null)
                {
                    path = Server.MapPath("~/AppFiles/manufacturer/" + mv.logo);
                    if (System.IO.File.Exists(path))
                    {
                        try
                        {
                            System.IO.File.Delete(path);
                        }
                        catch (Exception e)
                        {
                            //Debug.WriteLine(e.Message);
                        }
                    }

                    string fileName  = Path.GetFileNameWithoutExtension(mv.file.FileName);
                    string extension = Path.GetExtension(mv.file.FileName);
                    fileName = "L" + mv.manufacturer_id + extension;
                    fileName = fileName.Replace(" ", "-");

                    path = fileName;

                    string savePath = Server.MapPath("~/AppFiles/manufacturer/");
                    mv.file.SaveAs(Path.Combine(savePath, fileName));
                    mt.logo = path;
                }
                else
                {
                    mt.logo = mv.logo;
                }

                db.Entry(mt).State = EntityState.Modified;
                db.SaveChanges();
                message = "ManuFacturer Updated Successfully";
                status  = true;
            }
            else
            {
                message = "There Are Some Problems, Try Again";
            }

            TempData["Message"] = message;
            TempData["Status"]  = status;
            return(RedirectToAction("manufacture"));
        }
コード例 #2
0
        public ActionResult manufacture(manufacture_vm mf)
        {
            string path;

            if (ModelState.IsValid)
            {
                manufacturer_tbl mt = new manufacturer_tbl();

                mt.brand_name = mf.brand_name;
                mt.sort_order = mf.sort_order;
                db.manufacturer_tbl.Add(mt);
                db.SaveChanges();

                var id = db.manufacturer_tbl.Find(mt.manufacturer_id);

                //save the logo

                if (mf.file != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(mf.file.FileName);
                    string extension = Path.GetExtension(mf.file.FileName);
                    fileName = "L" + id.manufacturer_id + extension;
                    fileName = fileName.Replace(" ", "-");

                    path = fileName;

                    string savePath = Server.MapPath("~/AppFiles/manufacturer/");
                    mf.file.SaveAs(Path.Combine(savePath, fileName));
                    mt.logo = path;
                    db.SaveChanges();
                }

                message = "Menufacture  Create Successfully";
                status  = true;
            }
            else
            {
                message = "There have Some Problems";
            }

            TempData["Message"] = message;
            TempData["Status"]  = status;
            return(RedirectToAction("manufacture"));
        }
コード例 #3
0
        public ActionResult editmanufacturer(int?id)
        {
            string         surl = Request.Url.GetLeftPart(UriPartial.Authority);
            manufacture_vm mv   = new manufacture_vm();

            if (id != null)
            {
                var m = db.manufacturer_tbl.Find(id);
                mv.brand_name      = m.brand_name;
                mv.logo            = m.logo;
                mv.manufacturer_id = m.manufacturer_id;
                mv.sort_order      = m.sort_order;
                ViewBag.url        = surl;
                return(PartialView(mv));
            }
            message             = "There have Some Problem. Try agin";
            TempData["Message"] = message;
            return(RedirectToAction("manufacture"));
            //return PartialView();
        }