Exemplo n.º 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     var logged = Security.IsAuthenticated();
     var dic = Server.MapPath("~/lib/up/users/");
     var Ten = Request["Ten"];
     var MoTa = Request["MoTa"];
     var Mobile = Request["Mobile"];
     var Tinh_ID = Request["Tinh_ID"];
     var Alias = Request["Alias"];
     var rowId = Request["RowId"];
     switch (subAct)
     {
         case "changeAvatar":
             #region change avatar
             if(logged)
             {
                 if(Request.Files.Count > 0)
                 {
                     var img = new ImageProcess(Request.Files[0].InputStream, Guid.NewGuid().ToString());
                     if(img.Width > img.Heigth)
                     {
                         img.ResizeHeight(180);
                     }
                     else
                     {
                         img.Resize(180);
                     }
                     img.Crop(180, 180);
                     var user = MemberDal.SelectByUser(Security.Username);
                     var anh = dic + user.Anh;
                     if(!string.IsNullOrEmpty(anh))
                     {
                         if(File.Exists(anh))
                             File.Delete(anh);
                     }
                     var anhNew = string.Format("{0}{1}", user.Id, img.Ext);
                     img.Save(dic + anhNew);
                     MemberDal.UpdateAnh(Security.Username,anhNew);
                     rendertext(anhNew);
                 }
             }
             rendertext("0");
             break;
             #endregion
         case "validateAlias":
             #region validate object alias
             if (logged && !string.IsNullOrEmpty(rowId) && !string.IsNullOrEmpty(Alias))
             {
                 var RowId = new Guid(rowId);
                 var obj = ObjDal.SelectByAlias(Alias);
                 if(obj.Id == Guid.Empty)
                 {
                     rendertext("1");
                 }
                 else
                 {
                     if (obj.RowId == RowId)
                     {
                         rendertext("1");
                     }
                     else
                     {
                         rendertext("0");
                     }
                 }
                 rendertext("0");
             }
             rendertext("0");
             break;
             #endregion
         case "saveAlias":
             #region validate object alias
             if (logged && !string.IsNullOrEmpty(rowId) && !string.IsNullOrEmpty(Alias))
             {
                 var RowId = new Guid(rowId);
                 var obj = ObjDal.SelectByAlias(Alias);
                 if (obj.Id == Guid.Empty)
                 {
                     obj = ObjDal.SelectByRowId(RowId);
                     obj.Alias = Alias;
                     ObjDal.Update(obj);
                     rendertext("1");
                 }
                 else
                 {
                     if (obj.RowId == RowId)
                     {
                         rendertext("1");
                     }
                     else
                     {
                         rendertext("0");
                     }
                 }
                 rendertext("0");
             }
             rendertext("0");
             break;
             #endregion
         case "GetVcard":
             #region change avatar
             vcard.Visible = true;
             break;
             #endregion
         case "saveInformation":
             #region Store information
             if (logged && !string.IsNullOrEmpty(Ten))
             {
                 var user = MemberDal.SelectByUser(Security.Username);
                 if(!string.IsNullOrEmpty(Tinh_ID))
                 {
                     user.Tinh = new Guid(Tinh_ID);
                 }
                 user.Ten = Ten;
                 user.Mota = MoTa;
                 user.Mobile = Mobile;
                 user.NgayCapNhat = DateTime.Now;
                 user = MemberDal.Update(user);
                 Security.Login(user.Username, "true");
                 MemberDal.UpdateVcard(DAL.con(), user.Username);
                 rendertext("1");
             }
             rendertext("0");
             break;
             #endregion
     }
 }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var ten = Request["Ten"];
        var moTa = Request["MoTa"];
        var id = Request["Id"];
        var cUrl = Request["cUrl"];
        var gioiThieu = Request["GioiThieu"];
        var anh = Request["Anh"];
        var duyet = Request["Duyet"];
        var active = Request["Active"];
        var logged = Security.IsAuthenticated();
        var idNull = string.IsNullOrEmpty(id) || id == "0";
        var adminKey = Request["AdminKey"];
        var dic = Server.MapPath("~/lib/up/nhom/");
        var joined = Request["Joined"];
        var approved = Request["approved"];
        var loai = Request["loai"];

        switch (subAct)
        {
            case "save":
                #region save Nhom
                if (logged && !string.IsNullOrEmpty(ten))
                {
                    var item = idNull ? new Nhom() : NhomDal.SelectById(Convert.ToInt32(id));
                    item.Ten = ten;
                    item.MoTa = moTa;
                    item.GioiThieu = gioiThieu;
                    item.Anh = anh;
                    item.NgayCapNhat = DateTime.Now;
                    if (!string.IsNullOrEmpty(duyet))
                    {
                        duyet = !string.IsNullOrEmpty(duyet) ? "true" : "false";
                        item.Duyet = Convert.ToBoolean(duyet);
                        item.NguoiDuyet = Security.Username;
                        item.NgayDuyet = DateTime.Now;
                    }
                    if (!string.IsNullOrEmpty(active))
                    {
                        active = !string.IsNullOrEmpty(active) ? "true" : "false";
                        item.Active = Convert.ToBoolean(active);
                    }
                    if (idNull)
                    {
                        item.NguoiTao = Security.Username;
                        item.NgayTao = DateTime.Now;

                        item.RowId = Guid.NewGuid();
                        item = NhomDal.Insert(item);

                        NhomThanhVienDal.Insert(new NhomThanhVien()
                                                    {
                                                        NHOM_ID = item.Id
                                                        , Accepted = true
                                                        ,AcceptedDate = DateTime.Now
                                                        , Admin = true
                                                        , Approved = true
                                                        , ApprovedDate = DateTime.Now
                                                        , ID = Guid.NewGuid()
                                                        , NgayTao = DateTime.Now
                                                        , NguoiTao = Security.Username
                                                        , Username = Security.Username
                                                        ,
                                                        IsMod = true
                                                        ,
                                                        ModLoai = 5
                                                    });

                        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(Nhom).FullName
                            ,
                            NgayTao = DateTime.Now
                            ,
                            RowId = item.RowId
                            ,
                            Ten = item.Ten
                            ,
                            Url = string.Format("{0}", item.Url)
                            ,
                            Username = Security.Username
                        });
                    }
                    else
                    {
                        item.NguoiCapNhat = Security.Username;
                        item = NhomDal.Update(item);
                    }
                    rendertext(item.Url);
                }
                rendertext("0");
                break;
                #endregion
            case "remove":
                #region remove Nhom
                if (!string.IsNullOrEmpty(id) && logged)
                {
                    var item = NhomDal.SelectById(Convert.ToInt32(id));
                    if (item.NguoiTao == Security.Username || !string.IsNullOrEmpty(adminKey))
                    {
                        ObjDal.DeleteByRowId(item.RowId);
                        ObjMemberDal.DeleteByPRowId(item.RowId.ToString());
                        ThichDal.DeleteByPId(item.RowId);
                        NhomDal.DeleteById(item.Id);
                    }
                }
                break;
                #endregion
            case "join":
                #region Tham gia nhom
                if (!string.IsNullOrEmpty(id) && logged)
                {
                    var item = NhomDal.SelectById(DAL.con(), Convert.ToInt32(id), Security.Username);
                    var isJoined = joined == "1";
                    var itemTv = NhomThanhVienDal.SelectByNhomIdUsername(id, Security.Username);
                    if (isJoined && itemTv.ID != Guid.Empty && !itemTv.Admin) // remove
                    {
                        NhomThanhVienDal.DeleteById(itemTv.ID);
                    }
                    else // add
                    {
                        NhomThanhVienDal.Insert(new NhomThanhVien()
                                                    {
                                                        Accepted = true
                                                        , AcceptedDate = DateTime.Now
                                                        , Admin = false
                                                        , Approved = false
                                                        , ID = Guid.NewGuid()
                                                        , NgayTao = DateTime.Now
                                                        , NguoiTao = Security.Username
                                                        , NHOM_ID = item.Id
                                                        , Username = Security.Username
                                                        , IsMod = false
                                                        , ModLoai = 0
                                                    });
                    }
                }
                break;
                #endregion
            case "duyetThanhVien":
                #region Duyệt thành viên tham gia nhóm
                if (!string.IsNullOrEmpty(id) && logged)
                {
                    var nhomTv = NhomThanhVienDal.SelectById(new Guid(id));
                    var mem = Security.Username;
                    var memTv = NhomThanhVienDal.SelectByNhomIdUsername(nhomTv.NHOM_ID.ToString(), mem);
                    var nhom = NhomDal.SelectById(nhomTv.NHOM_ID);
                    var Approved = approved == "1";
                    if(memTv.ModLoai==5 )
                    {
                        if(Approved)
                        {
                            nhomTv.Approved = true;
                            nhomTv.ApprovedDate = DateTime.Now;
                            NhomThanhVienDal.Update(nhomTv);

                            ObjMemberDal.Insert(new ObjMember()
                            {
                                PRowId = nhom.RowId
                                ,
                                Username = nhomTv.Username
                                ,
                                Owner = false
                                ,
                                NgayTao = DateTime.Now
                                ,
                                RowId = Guid.NewGuid()
                            });
                        }
                        else
                        {
                            NhomThanhVienDal.DeleteById(nhomTv.ID);
                            ObjMemberDal.DeleteByPRowIdUsername(nhom.RowId.ToString(), nhomTv.Username);
                        }
                        rendertext("1");
                    }
                    rendertext("0");
                }
                break;
                #endregion
            case "phanQuyenThanhVien":
                #region Phân quyền thành viên
                if (!string.IsNullOrEmpty(id) && logged)
                {
                    var nhomTv = NhomThanhVienDal.SelectById(new Guid(id));
                    var mem = Security.Username;
                    var memTv = NhomThanhVienDal.SelectByNhomIdUsername(nhomTv.NHOM_ID.ToString(), mem);
                    if (memTv.ModLoai == 5)
                    {
                        nhomTv.ModLoai = Convert.ToInt32(loai);
                        nhomTv.IsMod = nhomTv.ModLoai != 0;
                        if(!nhomTv.Approved)
                        {
                            nhomTv.Approved = true;
                            nhomTv.ApprovedDate = DateTime.Now;
                        }
                        NhomThanhVienDal.Update(nhomTv);
                        rendertext("1");
                    }
                    rendertext("0");
                }
                break;
                #endregion
            case "changeAvatar":
                #region change avatar
                if (logged)
                {
                    if (Request.Files.Count > 0)
                    {
                        var img = new ImageProcess(Request.Files[0].InputStream, Guid.NewGuid().ToString());
                        if (img.Width > img.Heigth)
                        {
                            img.ResizeHeight(180);
                        }
                        else
                        {
                            img.Resize(180);
                        }
                        img.Crop(180, 180);
                        var anhNew = string.Format("{0}{1}", Guid.NewGuid().ToString(), img.Ext);
                        img.Save(dic + anhNew);
                        rendertext(anhNew);
                    }
                }
                rendertext("0");
                break;
                #endregion
        }
    }
Exemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        var x = Request["x"];
        var y = Request["y"];
        var x1 = Request["x1"];
        var y1 = Request["y1"];
        var w = Request["w"];
        var h = Request["h"];
        var Key = Request["key"];
        var Id = Request["Id"];
        var dic = Server.MapPath("~/lib/up/crop/");
        var newDic = Server.MapPath("~/lib/up/car/");
        var DM_PID = Request["DM_PID"];
        var logged = Security.IsAuthenticated();
        var js = new JavaScriptSerializer();

        switch (subAct)
        {
            case "upload":
                #region upload image
                if (!string.IsNullOrEmpty(Id))
                {
                    Response.ContentType = "text/plain";//"application/json";
                    var r = new List<ViewDataUploadFilesResult>();
                    foreach (string file in Request.Files)
                    {
                        var hpf = Request.Files[file] as HttpPostedFile;
                        var key = Guid.NewGuid().ToString();
                        var img = new ImageProcess(hpf.InputStream, key);
                        var fileName = key + img.Ext;
                        img.Resize(960);
                        img.Save(dic + key + "full" + img.Ext);
                        img.Save(dic + key + img.Ext);

                        var anh = new Anh()
                        {
                            Id = Guid.NewGuid()
                            ,
                            P_ID = new Guid(Id)
                            ,
                            FileAnh = fileName
                            ,
                            NgayTao = DateTime.Now
                        };
                        anh = AnhDal.Insert(anh);
                        r.Add(new ViewDataUploadFilesResult()
                        {
                            Id = anh.Id.ToString(),
                            Thumbnail_url = key + img.Ext,
                            Name = key + "full" + img.Ext,
                            Length = hpf.ContentLength,
                            Type = hpf.ContentType
                        });
                        var uploadedFiles = new
                        {
                            files = r.ToArray()
                        };
                        var jsonObj = js.Serialize(uploadedFiles);
                        rendertext(jsonObj);
                    }
                }
                rendertext("Id is missing", HttpStatusCode.BadRequest);
                break;
                #endregion
            case "GetImage":
                #region get image
                if (Key != null)
                {
                    var fileName = dic + Lib.imgSize(Key, "full");
                    var src = new Bitmap(fileName);
                    var cropRect = new Rectangle(Convert.ToInt32(x), Convert.ToInt32(y), Convert.ToInt32(w), Convert.ToInt32(h));
                    var cropted = Lib.CropBitmap(src, cropRect);
                    var img = new ImageProcess(cropted, Key);
                    File.Delete(dic + Key);
                    if (img.Width < 960)
                        img.Resize(960);
                    Response.ClearContent();
                    Response.ContentType = img.Mime;
                    img.Save(newDic + Key);
                    img.Save();
                    Response.End();
                }
                break;
                #endregion
            case "RemoveImage":
                #region remove image
                if (Id != null)
                {
                    var item = AnhDal.SelectById(new Guid(Id));
                    var file = newDic + item.FileAnh;
                    if (File.Exists(file))
                    {
                        File.Delete(newDic + item.FileAnh);
                    }
                    AnhDal.DeleteById(item.Id);
                }
                break;
                #endregion
            case "SetAnhChinh":
                #region Set Anh Chinh
                if (Id != null)
                {
                    var item = AnhDal.SelectById(new Guid(Id));
                    AnhDal.UpdateAnhBia(item.Id);
                    var xe = XeDal.SelectByRowId(item.P_ID);
                    if (xe.Id != 0)
                    {
                        xe.Anh = item.FileAnh;
                        XeDal.Update(xe);
                    }
                    var blog = BlogDal.SelectByRowId(item.P_ID);
                    if (blog.Id != 0)
                    {
                        blog.Anh = item.FileAnh;
                        BlogDal.Update(blog);
                    }
                }
                break;
                #endregion
            case "GetImageMobile":
                #region get image in mobile
                if (Key != null)
                {
                    var fileName = dic + Lib.imgSize(Key, "full");
                    var img = new ImageProcess(fileName, Key);
                    File.Delete(dic + Key);
                    if (img.Heigth < 540)
                        img.ResizeHeight(540);
                    img.Crop(960, 540);
                    Response.ClearContent();
                    Response.ContentType = img.Mime;
                    img.Save(newDic + Key);
                    if(!string.IsNullOrEmpty(w))
                    {
                        img.Resize(Convert.ToInt32(w));
                        if(!string.IsNullOrEmpty(h))
                        {
                            img.Crop(Convert.ToInt32(w), Convert.ToInt32(h));
                        }
                    }
                    img.Save();
                    Response.End();
                }
                break;
                #endregion
        }
    }