Ejemplo n.º 1
0
        /// <summary>更新品牌的LOGO的处理
        /// </summary>
        /// <returns>更新品牌的LOGO的结果View</returns>
        public ActionResult UpdateLogo(int id)
        {
            HttpPostedFileBase file = Request.Files[0];

            if (!file.ContentType.Contains("image") || file.ContentLength > 65535)
            {
                return(Content("error"));
            }

            //如果获取该ID的品牌信息失败,返回错误
            BrandItem brand = BrandManager.GetBrandByID(id);

            if (brand == null)
            {
                return(Content("error"));
            }

            //上传的LOGO图片必须是100*50的大小
            string        mimetype = file.ContentType;
            BitmapDecoder decoder  = BitmapDecoder.Create(file.InputStream, BitmapCreateOptions.None, BitmapCacheOption.Default);

            if (decoder.Frames[0].PixelWidth != 100 || decoder.Frames[0].PixelHeight != 50)
            {
                return(Content("error - must be 100*50 dimension"));
            }

            string logo_filename = BrandManager.GetLogoFileName(brand, mimetype);

            file.SaveAs(HttpContext.Server.MapPath("~/Images/logo/" + logo_filename));

            BrandManager.UpdateBrandItem(null);
            return(Content("ok-" + logo_filename));
        }