コード例 #1
0
        public int AddBrand(string Title, System.Web.HttpPostedFile Image)
        {
            BrandsAdp adp = new BrandsAdp();

            adp.Insert(Title, "", DateTime.Now, DateTime.Now);

            int BrandId = GetBrand(Title).BrandId;

            string PartName = lw.Utils.StringUtils.ToURL(Title);

            if (PartName.Length >= 35)
            {
                PartName = PartName.Substring(0, 35);
            }

            if (Image != null && Image.ContentLength > 0)
            {
                string pathTo = WebContext.Root + lw.CTE.Folders.BrandsImages;
                pathTo = WebContext.Server.MapPath(pathTo);

                string extension = lw.Utils.StringUtils.GetFileExtension(Image.FileName);
                string ImageName = PartName + "_" + BrandId + "." + extension;
                string Large     = pathTo + "/" + ImageName;

                Image.SaveAs(Large);

                Config    cfg = new Config();
                Dimension dim = new Dimension(cfg.GetKey(Settings.BrandsImagesSize));
                if (dim.Valid)
                {
                    lw.GraphicUtils.ImageUtils.Resize(Large, Large, dim.IntWidth, dim.IntHeight);
                }
                adp.UpdateImage(ImageName, BrandId);
            }

            return(BrandId);
        }