Beispiel #1
0
        public JsonResult GetImgInfos(int userid, string firstimgurl)
        {
            // 首先要判断进来的这张 是不是头像。 不是头像就要删除一张
            //再加到最前
            var imglists = new List <Iamgbox>();
            var imgs     = LoveDb.IamgAll().Where(n => n.UserId == userid).OrderByDescending(n => n.Id).ToList();
            var user     = LoveDb.One((User u) => u.UserId == userid);
            var fisrtone = imgs.Find(n => n.ImgUrl == firstimgurl);

            if (fisrtone != null)
            {
                imgs.Remove(fisrtone);
            }
            else
            {
                fisrtone = new Iamgbox
                {
                    ActionTime  = DateTime.Now,
                    BoxName     = "1",//特殊图片... 特殊处理吧
                    ImgUrl      = firstimgurl,
                    UserId      = user.UserId,
                    Id          = 0,
                    PraiseCount = 0,
                    Remark      = "我的图片",
                    VisitCount  = 0,
                };
            }
            imglists.Add(fisrtone);
            imglists.AddRange(imgs);
            return(Json(imglists));
        }
Beispiel #2
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            var user = db.One((User u) => u.UserId == CheckValid());

            if (user != null)
            {
                var path      = Path.Combine("../../", Image1.ImageUrl);
                var dictinary = new Dictionary <string, object>
                {
                    { "ImgUrl", path }
                };
                db.Update <User>(user.UserId, dictinary);
                var box = new Iamgbox
                {
                    ActionTime  = DateTime.Now,
                    BoxName     = user.UserName,
                    ImgUrl      = path,
                    IsValid     = true, //默认是正规合适的图片 不合适在检举
                    PraiseCount = 0,
                    Remark      = "我的头像",
                    UserId      = user.UserId,
                    VisitCount  = 0,
                };
                db.Add(box);
                var state = new State
                {
                    UserId     = user.UserId,
                    ActionTime = box.ActionTime,
                    Content    = "我刚刚更换了头像:<br/><div class='imgtigger'><img src='" + path + "' /></div>",
                    StateType  = StateType.Image.ToString(),
                };
                db.Add(state);
            }
            Response.Redirect("/User/Index");
        }
Beispiel #3
0
        /// <summary>
        /// 存头像
        /// </summary>
        /// <returns></returns>
        public int SaveImg()
        {
            var uid = CheckValid();

            if (_uName == null)
            {
                _uName = GetUserNameById(uid);
            }
            //先创建文件夹目录
            string path = Path.Combine(HttpContext.Server.MapPath("../Content/UploadFiles/"), _uName, "Photos", "Portrait");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            var list = Session["Imgscr"] as List <string>;

            if (list == null)
            {
                return(0);                                                           //失败
            }
            var scrtemp  = list[0];                                                  //图片在临时文件夹的地址
            var scrtemp1 = Server.MapPath(scrtemp.Substring(3, scrtemp.Length - 3)); //去掉第一个../
            var img      = new FileInfo(scrtemp1);

            if (!img.Exists)
            {
                return(0);             //失败
            }
            var image          = GetExtensionName(img.Name);
            var imgname        = string.Format("{0:yyyMMdd}", DateTime.Now).Replace("/", "") + DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture).Substring(7, 11) + image;
            var scrdestination = Path.Combine(HttpContext.Server.MapPath("../Content/UploadFiles/"), _uName, "Photos", "Portrait", imgname);
            var scrshow        = Path.Combine(("../../Content/UploadFiles/"), _uName, "Photos", "Portrait", imgname);

            img.MoveTo(scrdestination);
            var dictinary = new Dictionary <string, object>
            {
                { "ImgUrl", scrshow }
            };

            LoveDb.Update <User>(uid, dictinary);

            var imgbox = new Iamgbox
            {
                UserId     = uid,
                ActionTime = DateTime.Now,
                BoxName    = _uName,
                ImgUrl     = scrshow,
                Remark     = "我的头像",
                IsValid    = true,
            };

            LoveDb.Add(imgbox);

            var state = new State
            {
                UserId     = uid,
                ActionTime = imgbox.ActionTime,
                Content    = "我刚刚更换了头像:<br/><div class='imgtigger'><img src='" + scrshow + "' /></div>",
                StateType  = StateType.Image.ToString(),
            };

            LoveDb.Add(state);


            // 图片消息还没有处理呢。先放在这
            return(1);//成功
        }
Beispiel #4
0
        public JsonResult SaveImgs(string content)
        {
            var uid = CheckValid();

            if (_uName == null)
            {
                _uName = GetUserNameById(uid);
            }

            string path = Path.Combine(HttpContext.Server.MapPath("../Content/UploadFiles/"), _uName, "Photos", "ImgBox");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            var list      = Session["Imgscr"] as List <string>;
            var finallist = new List <string>();

            if (list == null)
            {
                return(Json(0));
            }
            foreach (var str in list)
            {
                var scrtemp1 = Server.MapPath(str.Substring(3, str.Length - 3));//去掉第一个../
                var img      = new FileInfo(scrtemp1);
                if (img.Exists)
                {
                    var image = GetExtensionName(img.Name);
                    //处理照片名称
                    var imgname        = string.Format("{0:yyyMMdd}", DateTime.Now).Replace("/", "") + DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture).Substring(7, 11) + image;
                    var scrdestination = Path.Combine(HttpContext.Server.MapPath("../Content/UploadFiles/"), _uName, "Photos", "ImgBox", imgname);

                    var scrshow = Path.Combine(("../../Content/UploadFiles/"), _uName, "Photos", "ImgBox", imgname);
                    finallist.Add(scrshow);
                    //移动照片
                    img.MoveTo(scrdestination);
                    //存入imgbox
                    var box = new Iamgbox
                    {
                        ActionTime  = DateTime.Now,
                        BoxName     = _uName,
                        ImgUrl      = scrshow,
                        IsValid     = true, //默认是正规合适的图片 不合适在检举
                        PraiseCount = 0,
                        Remark      = content,
                        UserId      = uid,
                        VisitCount  = 0,
                    };
                    LoveDb.Add(box);
                }
                ;
            }
            if (finallist.Count() != 0)
            {
                var sbstr = new StringBuilder("<br/><div class='imgtigger'>");
                foreach (var str in finallist)
                {
                    sbstr.Append("<img src='" + str + "' />");
                }
                sbstr.Append("</div>");
                var state = new State
                {
                    ActionTime  = DateTime.Now,
                    Content     = (content == "" ? string.Format("刚刚上传了{0}张照片:", finallist.Count) : content) + sbstr,
                    PraiseCount = 0,
                    StateType   = StateType.Image.ToString(),
                    UserId      = uid
                };
                LoveDb.Add(state);
                Session.Remove("Imgscr");
                Session.Remove("ImgServerscr");
            }


            return(Json(1));
        }