예제 #1
0
        public AjaxMessage SetThemeTitle(int imgId, int hotelId)
        {
            AjaxMessage ajax = new AjaxMessage();

            ajax.IsSuccess = false;
            ajax.Message   = "";

            //前封面图片
            CommonImages image = _imgService.GetTitleImg(hotelId);

            if (image != null)
            {
                image.State = 0;
                _imgService.Update(image);
            }

            //封面图片
            CommonImages uimage = _imgService.GetByID(imgId);

            uimage.State = 1;
            int result = _imgService.Update(uimage);

            if (result > 0)
            {
                //修改酒店封面图片
                FD_Hotel hotel = _hotelService.GetByID(hotelId);
                hotel.HotelThemeImage = uimage.ImgUrl;
                _hotelService.Update(hotel);
                ajax.IsSuccess = true;
                ajax.Message   = "设置成功";
            }

            return(ajax);
        }
예제 #2
0
        public AjaxMessage DeleteImgById(int imgId)
        {
            AjaxMessage ajax = new AjaxMessage();

            ajax.IsSuccess = false;
            ajax.Message   = "";

            CommonImages image = _imgService.GetByID(imgId);

            if (image != null)
            {
                int result = _imgService.Delete(image);
                if (result > 0)
                {
                    ajax.IsSuccess = true;
                    ajax.Message   = "删除成功";
                }
            }

            return(ajax);
        }
예제 #3
0
        /// <summary>
        /// 文件保存操作
        /// </summary>
        /// <param name="basePath"></param>
        private void SaveFile(HttpContext context, string basePath = "/Files/")
        {
            HttpServerUtility  server  = context.Server;
            HttpRequest        request = context.Request;
            HttpFileCollection files   = System.Web.HttpContext.Current.Request.Files;

            string path = basePath;
            string type = string.Empty;

            if (!string.IsNullOrEmpty(request["isType"]))       //跟路径
            {
                type     = request["isType"].ToString();
                basePath = ConfigurationManager.AppSettings[type].ToString();
                path     = server.MapPath(basePath);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }

            if (!string.IsNullOrEmpty(request["isName"]))           //子路径
            {
                string fname = request["isName"].ToString();
                path     = path + fname;
                basePath = basePath + fname;
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }

            //后缀名
            var suffix = files[0].ContentType.Split('/')[1];
            //原始图片名称
            //var _temp = System.Web.HttpContext.Current.Request["name"];
            //图片名称
            Random rand = new Random(24 * (int)DateTime.Now.Ticks);
            string name = rand.Next() + "." + suffix;

            //保存全路径
            string normalPath = basePath + "/" + name;
            string fullPath   = path + "/" + name;

            //添加到数据库
            CommonImageService _imgService = new CommonImageService();

            if (type == "hotelUrl")
            {
                CommonImages commonImg = new CommonImages();
                commonImg.ImgName    = name;
                commonImg.ImgUrl     = normalPath;
                commonImg.TypeId     = 1;                         //1.代表酒店
                commonImg.CommonId   = request["isId"].ToInt32(); //酒店Id
                commonImg.CreateDate = DateTime.Now;
                commonImg.State      = 0;

                _imgService.Insert(commonImg);
            }

            files[0].SaveAs(fullPath);
        }