Ejemplo n.º 1
0
        public bool DeleteBrand(int BrandId)
        {
            ProductsDS.BrandsRow brand = this.GetBrand(BrandId);

            string path = WebContext.Server.MapPath(WebContext.Root + lw.CTE.Folders.BrandsImages);

            BrandsAdp adp = new BrandsAdp();

            adp.DeleteBrand(BrandId);

            if (brand.Image != "")
            {
                if (GetBrands("Image='" + brand.Image + "' and BrandId<>" + BrandId.ToString()).Count == 0)
                {
                    if (System.IO.File.Exists(path + "/" + brand.Image))
                    {
                        System.IO.File.Delete(path + "/" + brand.Image);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public int UpdateBrand(int BrandId, string Title, bool DeleteImage,
                               System.Web.HttpPostedFile Image)
        {
            ProductsDS _ds = new ProductsDS();

            if (GetBrands(string.Format("Title='{0}' and BrandId <> {1}", Title, BrandId)).Count > 0)
            {
                return(-1);
            }

            ProductsDS.BrandsRow row = GetBrand(BrandId);


            row.Title        = Title;
            row.LastModified = DateTime.Now;

            string path = WebContext.Server.MapPath(WebContext.Root + lw.CTE.Folders.BrandsImages);

            if (DeleteImage && row.Image != "")
            {
                if (GetBrands("Image='" + row.Image + "' and BrandId<>" + BrandId.ToString()).Count == 0)
                {
                    if (System.IO.File.Exists(path + "/" + row.Image))
                    {
                        System.IO.File.Delete(path + "/" + row.Image);
                    }
                }
                row.Image = "";
            }

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

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

            if (Image != null && Image.ContentLength > 0)
            {
                if (!DeleteImage)
                {
                    if (GetBrands("Image='" + row.Image + "' and BrandId<>" + BrandId.ToString()).Count == 0)
                    {
                        if (System.IO.File.Exists(path + "/" + row.Image))
                        {
                            System.IO.File.Delete(path + "/" + row.Image);
                        }
                    }
                }

                string extension = lw.Utils.StringUtils.GetFileExtension(Image.FileName);
                string ImageName = PartName + "_" + row.BrandId + "." + extension;
                string Large     = path + "/" + 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);
                }

                row.Image = ImageName;
            }

            BrandsAdp adp = new BrandsAdp();

            adp.Update(row);

            return(BrandId);
        }