示例#1
0
        public ActionResult Addproduct(product obj)
        {
            int adminid = Convert.ToInt32(Session["adminid"]);
            Dal obj1    = new Dal();
            var uname   = "6c26fab6-21eb-4483-9242-7a18c2b52104.jpg";

            if (Request.Files["picture"] != null)
            {
                var file = Request.Files["picture"];
                if (file.FileName != "")
                {
                    var ext = System.IO.Path.GetExtension(file.FileName);
                    uname = Guid.NewGuid().ToString() + ext;
                    var rootpath = Server.MapPath(Url.Content("~/Content/Images"));
                    var savpath  = System.IO.Path.Combine(rootpath, uname);
                    file.SaveAs(savpath);
                }
            }
            obj.picture = uname;
            obj1.AddProducttobatabse(obj, adminid);
            return(Redirect(Url.Content("~/Product/ProductView")));
        }