Exemplo n.º 1
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");
 }
Exemplo n.º 2
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,
                    };
                    PrivateDb.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
                };
                PrivateDb.Add(state);
                Session.Remove("Imgscr");
                Session.Remove("ImgServerscr");
            }

            return Json(1);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 发布状态
        /// </summary>
        /// <param name="content"></param>
        /// <returns>返回0 说明发布时间太快,不过3分钟</returns>
        public JsonResult SendPersonalState(string content)
        {
            // 检查最后一条状态,不准发的太频繁。第一次更新状态不判断
            var laststate = PrivateDb.LastOne((State s) => s.UserId == CheckValid());
            if (laststate != null)
            {
                var min = PrivateDb.DiffMinute(laststate.ActionTime, DateTime.Now);

                if (min <= 1)
                {
                    return Json(0);

                }
            }

            var state = new State
            {
                ActionTime = DateTime.Now,
                UserId = CheckValid(),
                Content = content,
                PraiseCount = 0,
                StateType = StateType.Personal.ToString(),
            };
            PrivateDb.Add(state);
            return Json(content);
        }
Exemplo n.º 4
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}
                };
            PrivateDb.Update<User>(uid, dictinary);

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

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

            return 1;//成功
        }