コード例 #1
0
 public ActionResult ThemMoi(Anh anh, HttpPostedFileBase fileUpload)
 {
     ViewBag.MaCD = new SelectList(db.ChuDes.ToList().OrderBy(n => n.TenChuDe), "MaCD", "TenChuDe");
     ViewBag.MaNS = new SelectList(db.NgheSis.ToList().OrderBy(n => n.TenNS), "MaCD", "TenNS");
     //Kiểm tra đường dẫn ảnh
     if (fileUpload == null)
     {
         ViewBag.ThongBao = "Chọn hình ảnh";
         return(View());
     }
     //Thêm vào CSDL
     if (ModelState.IsValid)
     {
         //Lưu tên của file
         var fileName = Path.GetFileName(fileUpload.FileName);
         //Lưu đường dẫn của file
         var path = Path.Combine(Server.MapPath("~/HinhAnhCĐ/AnhCĐ"), fileName);
         //Kiểm tra hình ảnh đã tồn tại chưa
         if (System.IO.File.Exists(path))
         {
             ViewBag.ThongBao = "Hình ảnh đã tồn tại";
         }
         else
         {
             fileUpload.SaveAs(path);
         }
         anh.HinhAnh = fileUpload.FileName;
         db.Anhs.Add(anh);
         db.SaveChanges();
     }
     return(View());
 }
コード例 #2
0
        //
        // GET: /ThuVien/

        public ActionResult DanhSach()
        {
            List <Album> l_Album = new Album().GetList("");
            List <Anh>   l_Anh   = new Anh().GetList(2, 0);
            ViewModels   vm      = new ViewModels();

            vm.l_Album = l_Album;
            vm.l_Anh   = l_Anh;
            return(View(vm));
        }
コード例 #3
0
 public ActionResult ChinhSua(Anh anh, FormCollection f)
 {
     if (ModelState.IsValid)
     {
         db.Entry(anh).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     ViewBag.MaAnh = anh.MaA;
     ViewBag.MaCD  = new SelectList(db.ChuDes.ToList().OrderBy(n => n.TenChuDe), "MaCD", "TenChuDe", anh.MaCD);
     ViewBag.MaNS  = new SelectList(db.NgheSis.ToList().OrderBy(n => n.TenNS), "MaCD", "TenNS", anh.MaNS);
     return(RedirectToAction("Index"));
 }
コード例 #4
0
 public string[] GetThumbnails()
 {
     if (Anh != null && Anh.Length > 0)
     {
         var arr = Anh.Split(',');
         if (arr.Length > 0)
         {
             return(arr);
         }
     }
     return(new string[0]);
 }
コード例 #5
0
 public string GetDefautThumbnail()
 {
     if (Anh != null && Anh.Length > 0)
     {
         var arr = Anh.Split(',');
         if (arr.Length > 0)
         {
             return(ConfigurationManager.AppSettings["CloudinaryPrefix"] + arr[0]);
         }
     }
     return(ConfigurationManager.AppSettings["DefautImage"]);
 }
コード例 #6
0
 public List <Anhs> AddLinhKien(User admin, Anhs lk)
 {
     if (admin.chucNang == "admin")
     {
         var anh = new Anh();
         anh.maLinhKien = lk.maLinhKien;
         anh.img        = lk.Img;
         model.Anhs.Add(anh);
         model.SaveChanges();
     }
     return(GetListAnh(lk.maLinhKien));
 }
コード例 #7
0
        public ActionResult Chinhsua(int MaAnh)
        {
            //Lấy đối tượng ảnh theo mã
            Anh anh = db.Anhs.SingleOrDefault(n => n.MaA == MaAnh);

            if (anh == null)
            {
                Response.StatusCode = 404;
                return(null);
            }
            ViewBag.MaCD = new SelectList(db.ChuDes.ToList().OrderBy(n => n.TenChuDe), "MaCD", "TenChuDe", anh.MaCD);
            ViewBag.MaNS = new SelectList(db.NgheSis.ToList().OrderBy(n => n.TenNS), "MaCD", "TenNS", anh.MaNS);
            return(View(anh));
        }
コード例 #8
0
        public JsonResult giaovien_xoa(string param)
        {
            if (param.Length > 0)
            {
                List <string> l_path = new Anh().GetPath3(param);
                if (new GiaoVien().Delete(param) > 0)
                {
                    deleteFiles(l_path);

                    List <GiaoVien> l_GiaoVien = new GiaoVien().GetList("", 0);
                    return(Json(l_GiaoVien, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #9
0
        public JsonResult anh_xoa(string param)
        {
            if (param.Length > 0)
            {
                List <string> l_path = new Anh().GetPath(param);
                if (new Anh().Delete(param) > 0)
                {
                    deleteFiles(l_path);

                    List <Anh> l_Anh = new Anh().GetList(0, 0);
                    return(Json(l_Anh, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #10
0
        public JsonResult baiviet_xoa(string param)
        {
            if (param.Length > 0)
            {
                List <string> l_path = new Anh().GetPath2(param);
                if (new BaiViet().Delete(param) > 0)
                {
                    deleteFiles(l_path);

                    List <BaiViet> l_BaiViet = new BaiViet().GetList("", "", "", 0);
                    return(Json(l_BaiViet, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #11
0
ファイル: ItemSlot.cs プロジェクト: Witcher47/TEST_NAME
 public ItemSlot(Anh anh)
 {
     Anh = anh;
 }
コード例 #12
0
ファイル: Default.aspx.cs プロジェクト: nhatkycon/nkc-v3
    protected void Page_Load(object sender, EventArgs e)
    {
        var ID = Request["ID"];
        var P_ID = Request["P_ID"];
        var Ten = Request["Ten"];
        var location = Server.MapPath("~/lib/up/anh/");
        CapNhat Item;
        switch (subAct)
        {
            case "upload":
                #region upload anh
                Response.ContentType = "text/plain";//"application/json";
                var r = new List<ViewDataUploadFilesResult>();
                var js = new JavaScriptSerializer();
                foreach (string file in Request.Files)
                {

                    var hpf = Request.Files[file] as HttpPostedFile;
                    var key = Guid.NewGuid().ToString();

                    var img = new linh.controls.ImageProcess(hpf.InputStream, key);
                    var fileName = key + img.Ext;

                    var item = new Anh();
                    if(!string.IsNullOrEmpty(ID))
                    {
                        item.AB_ID = new Guid(ID);
                    }
                    item.FileAnh = fileName;
                    item.ID = Guid.NewGuid();
                    item.NgayTao = DateTime.Now;
                    if(!string.IsNullOrEmpty(P_ID))
                    {
                        item.P_ID = new Guid(P_ID);
                    }
                    item = AnhDal.Insert(item);

                    if(img.Width > 1000)
                    {
                        img.Resize(1000);
                    }
                    img.Save(location + key + "full" + img.Ext);

                    img.Resize(520);
                    img.Save(location + key + img.Ext);
                    r.Add(new ViewDataUploadFilesResult()
                    {
                        Id = item.ID.ToString(),
                        Thumbnail_url = key + img.Ext,
                        Name = key,
                        Length = hpf.ContentLength,
                        Type = hpf.ContentType
                    });
                    var uploadedFiles = new
                    {
                        files = r.ToArray()
                    };
                    var jsonObj = js.Serialize(uploadedFiles);
                    Response.Write( jsonObj.ToString());
                }
                ;
                break;
                #endregion
            case "xoaAnh":
                #region Xoa anh
                if (Security.IsAuthenticated())
                {
                    var item = AnhDal.SelectById(new Guid(ID));
                    AnhDal.DeleteById(new Guid(ID));
                    try
                    {
                        File.Delete(location + item.FileAnh);
                        File.Delete(location + Lib.imgSize(item.FileAnh,"full"));
                    }
                    catch
                    {

                    }
                }
                break;
                #endregion
            case "editCaption":
                #region Sua tieu de
                if (Security.IsAuthenticated())
                {
                    var item = AnhDal.SelectById(new Guid(ID));
                    item.Ten = Ten;
                    AnhDal.Update(item);
                }
                break;
                #endregion
            case "addAlbum":
                #region Them moi album
                if (Security.IsAuthenticated())
                {
                    var item = new Album();
                    item.ID = new Guid(ID);
                    item.Ten = Ten;
                    item.NgayTao = DateTime.Now;
                    item.NguoiTao = Security.Username;
                    item.P_RowId = new Guid(P_ID);
                    item.Active = true;
                    item = AlbumDal.Insert(item);

                    Item = new CapNhat();
                    Item.ID = Guid.NewGuid();
                    Item.Ten = Ten;
                    Item.NgayTao = DateTime.Now;
                    Item.Username = Security.Username;
                    Item.NgayViet = DateTime.Now;
                    if (!string.IsNullOrEmpty(P_ID))
                    {
                        Item.P_ID = new Guid(P_ID);
                    }

                    Item.Loai = 4;// Album
                    Item.AB_ID = item.ID;
                    Item = CapNhatDal.Insert(Item);
                    rendertext(Item.ID.ToString());
                }
                break;
                #endregion
            case "updateAlbum":
                #region Cap nhat album
                if (Security.IsAuthenticated())
                {
                    var item = AlbumDal.SelectById(new Guid(ID));
                    item.Ten = Ten;
                    item = AlbumDal.Update(item);
                }
                break;
                #endregion
            case "xoaAlbum":
                #region Cap nhat album
                if (Security.IsAuthenticated())
                {
                    AlbumDal.DeleteById(new Guid(ID));
                }
                break;
                #endregion
            default:
                Response.Write("s");
                break;
        }
    }
コード例 #13
0
        public JsonResult anh_search(short AlbumID)
        {
            List <Anh> l_Anh = new Anh().GetList(0, AlbumID);

            return(Json(l_Anh, JsonRequestBehavior.AllowGet));
        }
コード例 #14
0
        //
        // GET: /ThuVien/
        #region Danh sách ảnh thư viện
        public ActionResult DanhSachAnh()
        {
            List <Anh> l_Anh = new Anh().GetList(0, 0);

            return(View(l_Anh));
        }
コード例 #15
0
 public Anhs(Anh item)
 {
     Img        = item.img;
     MaAnh      = item.maAnh;
     maLinhKien = item.maLinhKien;
 }
コード例 #16
0
ファイル: Default.aspx.cs プロジェクト: nhatkycon/xetui
    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
        }
    }