protected void Page_Load(object sender, EventArgs e)
    {
        var pooledClientManager = new PooledRedisClientManager("localhost");
        var client = pooledClientManager.GetClient();
        var blogRedis = new BlogRedis(client);
        var memberRedis = new MemberRedis(client);

        var Id = Request["ID"];
        var idNull = string.IsNullOrEmpty(Id);
        Item = new Member();
        using (var con = DAL.con())
        {
            if (!idNull)
            {
                var blog = blogRedis.GetById(Convert.ToInt64(Id));

                Item = memberRedis.GetByUsername(blog.NguoiTao);
                //blog.Anhs = AnhDal.SelectByPId(con, blog.RowId.ToString(), 20);
                //blog.Profile = Item;
                ViewForProfile.Xes = Item.GetXe(client);
                ViewForProfile.Nhoms = Item.GetNhom(client);
                ViewForProfile.Pager = BinhLuanDal.PagerByPRowId(con, "", true, blog.RowId.ToString(), 20);
                ViewForProfile.Blog = blog;
                ViewForProfile.Item = Item;
            }
        }
    }
Beispiel #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     var u = Request["u"];
     var pooledClientManager = new PooledRedisClientManager("localhost");
     var client = pooledClientManager.GetClient();
     var memberRedis = new MemberRedis(client);
     var user = memberRedis.GetByUsername(u);
     Item = user;
     profile.Item = user;
     profile.Xes = user.GetXe(client);
     profile.Nhoms = user.GetNhom(client);
     profile.List = user.GetBlogs(client);
 }
Beispiel #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var pooledClientManager = new PooledRedisClientManager("localhost");
        var client = pooledClientManager.GetClient();
        var Ten = Request["Ten"];
        var PID_ID = Request["PID_ID"];
        var Loai = Request["Loai"];
        var Id = Request["Id"];
        var cUrl = Request["cUrl"];
        var rowId = Request["RowId"];
        var noiDung = Request["NoiDung"];
        var approved = Request["approved"];
        var logged = Security.IsAuthenticated();
        var idNull = string.IsNullOrEmpty(Id) || Id == "0";
        var blogRedis = new BlogRedis(client);
        var memberRedis = new MemberRedis(client);
        var nhomRedis = new NhomRedis(client);
        var xeRedis = new XeRedis(client);
        switch (subAct)
        {
            case "save":
                #region save blog
                if (logged && !string.IsNullOrEmpty(PID_ID) && !string.IsNullOrEmpty(Loai))
                {
                    var item = idNull ? new Blog() : BlogDal.SelectById(Convert.ToInt64(Id));
                    var member = new Member();
                    var xe = new Xe();
                    var nhom = new Nhom();
                    var nguoiTao = new Member();
                    item.NoiDung = noiDung;
                    item.Ten = Ten;
                    if (!string.IsNullOrEmpty(Loai))
                    {
                        item.Loai = Convert.ToInt32(Loai);
                    }
                    if (!string.IsNullOrEmpty(PID_ID))
                    {
                        item.PID_ID = new Guid(PID_ID);
                    }
                    if (!string.IsNullOrEmpty(rowId))
                    {
                        item.RowId = new Guid(rowId);
                    }

                    item.MoTa = Lib.Rutgon(Lib.NoHtml(item.NoiDung), 400);
                    var anhs = AnhDal.SelectByPId(DAL.con(), item.RowId.ToString(), 20).OrderByDescending(x => x.AnhBia).ToList();

                    if (anhs.Count > 0)
                    {
                        var sb = new StringBuilder();
                        foreach (var anhItem in anhs)
                        {
                            sb.AppendFormat(@"<a href=""{1}""><img alt=""{0}"" src=""/lib/up/car/{0}?w=75"" /></a>" , anhItem.FileAnh, item.Url);
                            item.AnhList.Add(anhItem.Id);
                        }
                        item.AnhStr = sb.ToString();

                    }
                    switch (item.Loai)
                    {
                        case 1:
                            member = memberRedis.GetByRowId(item.PID_ID);
                            break;
                        case 2:
                            xe = xeRedis.GetByRowId(item.PID_ID);
                            break;
                        case 3:
                        case 4:
                        case 5:
                            //item.Nhom = NhomDal.SelectByRowId(DAL.con(), item.PID_ID, Security.Username);
                            nhom = nhomRedis.GetByRowId(item.PID_ID);
                            break;
                    }
                    if (idNull)
                    {
                        item.NguoiTao = Security.Username;
                        item.NgayTao = DateTime.Now;
                        var insert = BlogDal.Insert(item);
                        item.Id = insert.Id;
                        item.NguoiThich.Insert(0, item.NguoiTao);
                        nguoiTao = memberRedis.GetByUsername(item.NguoiTao);
                        switch (item.Loai)
                        {
                            case 1:
                                if(member!= null)
                                {
                                    member.TotalBlog += 1;
                                    member.BlogIds.Insert(0, item.Id);
                                    memberRedis.Save(member);
                                    MemberDal.Update(member);
                                }
                                break;
                            case 2:
                                if (xe != null)
                                {
                                    xe.BlogIds.Insert(0, item.Id);
                                    xe.TotalBlog += 1;
                                    xeRedis.Save(xe);
                                    XeDal.Update(xe);
                                }
                                CacheHelper.Remove(string.Format(XeDal.CacheItemKey,item.Id));
                                systemMessageDal.Insert(new systemMessage()
                                {
                                    NoiDung = string.Format("<strong>{0}</strong> viết bài mới", nguoiTao.Ten)
                                    ,
                                    HeThong = false
                                    ,
                                    Id = Guid.NewGuid()
                                    ,
                                    PRowId = item.PID_ID
                                    ,
                                    NgayTao = DateTime.Now
                                    ,
                                    Active = true
                                    ,
                                    Loai = 1
                                    ,
                                    Url = string.Format("{0}", item.Url)
                                    ,
                                    Ten = string.Empty
                                    ,
                                    ThanhVienMoi = false
                                    ,
                                    Username = Security.Username
                                    ,
                                    ThuTu = 0
                                });
                                break;
                            case 3:
                            case 4:
                            case 5:
                                nhom.TotalBlog += 1;
                                if(item.Loai==3)
                                {
                                    nhom.BlogIds.Insert(0, item.Id);
                                }
                                else
                                {
                                    nhom.ForumBlogIds.Insert(0, item.Id);
                                }
                                nhomRedis.Save(nhom);
                                if (nhom.NhomMo)
                                {
                                    item.Publish = true;
                                }
                                systemMessageDal.Insert(new systemMessage()
                                {
                                    NoiDung = string.Format("<strong>{0}</strong> viết bài mới", nguoiTao.Ten)
                                    ,
                                    HeThong = false
                                    ,
                                    Id = Guid.NewGuid()
                                    ,
                                    PRowId = item.PID_ID
                                    ,
                                    NgayTao = DateTime.Now
                                    ,
                                    Active = true
                                    ,
                                    Loai = 1
                                    ,
                                    Url = string.Format("{0}", item.Url)
                                    ,
                                    Ten = string.Empty
                                    ,
                                    ThanhVienMoi = false
                                    ,
                                    Username = Security.Username
                                    ,
                                    ThuTu = 0
                                });
                                NhomDal.Update(nhom);
                                BlogDal.Update(item);
                                break;
                        }
                        ObjMemberDal.Insert(new ObjMember()
                        {
                            PRowId = item.RowId
                            ,
                            Username = Security.Username
                            ,
                            Owner = true
                            ,
                            NgayTao = DateTime.Now
                            ,
                            RowId = Guid.NewGuid()
                        });
                        var obj = ObjDal.Insert(new Obj()
                        {
                            Id = Guid.NewGuid()
                            ,
                            Kieu = typeof(Blog).FullName
                            ,
                            NgayTao = DateTime.Now
                            ,
                            RowId = item.RowId
                            ,
                            Url = string.Format("{0}", item.Url)
                            ,
                            Username = Security.Username
                        });

                    }
                    else
                    {
                        nguoiTao = memberRedis.GetByUsername(item.NguoiTao);
                        BlogDal.Update(item);

                    }
                    switch (item.Loai)
                    {
                        case 1:
                            if (member != null)
                            {
                                item.Url = string.Format("{0}/blogs/{1}/", member.Url, item.Id);
                                item.UrlEdit = string.Format("{0}/blogs/edit/{1}/", member.Url, item.Id);
                            }
                            break;
                        case 2:
                            if (xe != null)
                            {
                                item.Url = string.Format("{0}blogs/{1}/", xe.XeUrl, item.Id);
                                item.UrlEdit = string.Format("{0}blogs/edit/{1}/", xe.XeUrl, item.Id);
                            }
                            break;
                        case 3:
                            if (nhom != null)
                            {
                                item.Url = string.Format("{0}blogs/{1}/", nhom.Url, item.Id);
                                item.UrlEdit = string.Format("{0}blogs/edit/{1}/", nhom.Url, item.Id);
                            }
                            break;
                        case 4:
                            if (nhom != null)
                            {
                                item.Url = string.Format("{0}forum/{1}/", nhom.Url, item.Id);
                                item.UrlEdit = string.Format("{0}blogs/edit/{1}/", nhom.Url, item.Id);
                            }
                            break;
                        case 5:
                            if (nhom != null)
                            {
                                item.Url = string.Format("{0}qa/{1}/", nhom.Url, item.Id);
                                item.UrlEdit = string.Format("{0}blogs/edit/{1}/", nhom.Url, item.Id);
                            }
                            break;
                    }
                    blogRedis.Save(item);
                    SearchManager.Add(item.Ten, string.Format("{0} {1}", item.Ten, item.NoiDung), string.Empty, item.RowId.ToString(), item.Url, typeof(Blog).Name);
                    rendertext(item.Url);
                }
                rendertext("0");
                break;
                #endregion
            case "remove":
                #region remove blog
                if(!string.IsNullOrEmpty(Id) && logged)
                {
                    var item = BlogDal.SelectById(Convert.ToInt64(Id));
                    if(item.NguoiTao==Security.Username)
                    {
                        SearchManager.Remove(item.RowId);
                        ObjDal.DeleteByRowId(item.RowId);
                        ObjMemberDal.DeleteByPRowId(item.RowId.ToString());
                        ThichDal.DeleteByPId(item.RowId);
                        CacheHelper.Remove(string.Format(BlogDal.CacheItemKey, item.Id));
                        BlogDal.DeleteById(item.Id);
                        blogRedis.Remove(item.Id);
                        rendertext("1");
                    }
                }
                break;
                #endregion
            case "nhomDuyetBlog":
                #region duyet blog of Nhom
                if (!string.IsNullOrEmpty(Id) && logged && !string.IsNullOrEmpty(approved))
                {
                    var Approved = approved == "1";

                    var item = blogRedis.GetById(Convert.ToInt64(Id));
                    if(Approved)
                    {
                        item.Publish = true;
                        BlogDal.Update(item);
                        blogRedis.Save(item);
                    }
                    else
                    {
                        blogRedis.Save(item);
                        BlogDal.DeleteById(item.Id);
                    }

                }
                break;
                #endregion
        }
    }