Esempio n. 1
0
        /// <summary>
        /// Gets the list image album.
        /// </summary>
        /// <param name="albumId">The album identifier.</param>
        /// <returns>list image album</returns>
        public ActionResult GetListImageAlbum(int albumId)
        {
            GalleryModels           sv   = new GalleryModels();
            List <ImageAlbum>       list = new List <ImageAlbum>();
            List <ImageSlideObject> objs = new List <ImageSlideObject>();

            if (albumId > 0)
            {
                list = sv.GetListImagebyCategory(albumId);
                if (list.Count > 0)
                {
                    foreach (var it in list)
                    {
                        ImageSlideObject ia = new ImageSlideObject();
                        ia.url     = it.ImagesFull;
                        ia.caption = it.ImagesName;
                        objs.Add(ia);
                    }
                }
            }
            else
            {
            }

            var jsonSerialiser = new JavaScriptSerializer();
            var json           = jsonSerialiser.Serialize(objs);
            var results        = json;

            return(this.Json(results));
        }
 public int update(GalleryModels item)
 {
     int rs = 0;
     StringBuilder sqlBuilder = new StringBuilder();
     sqlBuilder.Append("UPDATE ");
     sqlBuilder.Append("gov_gallery ");
     sqlBuilder.Append("SET ");
     sqlBuilder.Append("title = @2, ");
     sqlBuilder.Append("total_view = @3, ");
     sqlBuilder.Append("avatar = @4, ");
     sqlBuilder.Append("attach_filepath = @5, ");
     sqlBuilder.Append("update_username = @6, ");
     sqlBuilder.Append("update_datetime = @7 ");
     sqlBuilder.Append("WHERE ");
     sqlBuilder.Append("id=@8");
     this.Sql = sqlBuilder.ToString();
     MySqlCommand objCmd = new MySqlCommand(Sql, getConnection());
     objCmd.Parameters.AddWithValue("@2", item.Title);
     objCmd.Parameters.AddWithValue("@3", item.TotalView);
     objCmd.Parameters.AddWithValue("@4", item.Avatar);
     objCmd.Parameters.AddWithValue("@5", item.AttachFilepath);
     objCmd.Parameters.AddWithValue("@6", item.UpdateUsername);
     objCmd.Parameters.AddWithValue("@7", item.UpdateDatetime);
     objCmd.Parameters.AddWithValue("@8", item.Id);
     rs = objCmd.ExecuteNonQuery();
     return rs;
 }
 public int insert(GalleryModels item) {
     int rs = 0;
     StringBuilder sqlBuilder = new StringBuilder();
     sqlBuilder.Append("INSERT ");
     sqlBuilder.Append("INTO ");
     sqlBuilder.Append("gov_gallery ");
     sqlBuilder.Append("( ");
     sqlBuilder.Append("title, ");
     sqlBuilder.Append("total_view, ");
     sqlBuilder.Append("avatar, ");
     sqlBuilder.Append("attach_filepath, ");
     sqlBuilder.Append("update_username, ");
     sqlBuilder.Append("update_datetime");
     sqlBuilder.Append(") ");
     sqlBuilder.Append("values(");
     sqlBuilder.Append("@2, @3, @4, @5, @6, @7");
     sqlBuilder.Append(")");
     this.Sql = sqlBuilder.ToString();
     MySqlCommand objCmd = new MySqlCommand(Sql, getConnection());
     objCmd.Parameters.AddWithValue("@2", item.Title);
     objCmd.Parameters.AddWithValue("@3", item.TotalView);
     objCmd.Parameters.AddWithValue("@4", item.Avatar);
     objCmd.Parameters.AddWithValue("@5", item.AttachFilepath);
     objCmd.Parameters.AddWithValue("@6", item.UpdateUsername);
     objCmd.Parameters.AddWithValue("@7", item.UpdateDatetime);
     rs = objCmd.ExecuteNonQuery();
     return rs;
 }
Esempio n. 4
0
        /// <summary>
        /// Posts the specified identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="cate_id">The cate identifier.</param>
        /// <param name="cate_type">Type of the cate.</param>
        /// <returns>Posts the specified</returns>
        public ActionResult LookbookDetail(int?id, string cate_type)
        {
            /////lookbook detail
            GalleryModels sv         = new GalleryModels();
            CatalogModels cateModels = new CatalogModels();
            C_Catalog     cateItem   = new C_Catalog();

            id = RouteData.Values["id"] != null?Convert.ToInt16(RouteData.Values["id"].ToString()) : 0;

            var link = RouteData.Values["Link"] != null ? RouteData.Values["Link"].ToString() : string.Empty;

            if (string.IsNullOrEmpty(cate_type))
            {
                cate_type = CommonGlobal.CateGallery;
            }

            if (id == 0)
            {
                return(this.HttpNotFound());
            }
            else
            {
                cateItem = cateModels.GetbyID((int)id);

                if (cateItem.CatalogID == 0)
                {
                    return(this.HttpNotFound());
                }

                ViewBag.Title = cateItem.CategoryName + " | " + GeneralModels.GetContent(CommonGlobal.PageName, this.Lang);

                ////breadcrumbs
                string strbreadcrumbs = string.Empty;

                strbreadcrumbs = string.Format("<li><a href=\"" + Url.Action("lookbook", "gallery") + "\">" + App_GlobalResources.Lang.mnuGallery + "</a></li>");
                if (cateItem != null)
                {
                    strbreadcrumbs   += string.Format("<li><a href=\"" + Url.RouteUrl("_lookbook", new { controller = "gallery", action = "LookbookDetail", id = id, Link = cateItem.Link != null ? cateItem.Link : string.Empty, cate_type = cate_type }) + "\">" + cateItem.CategoryName + "</a></li>");
                    ViewBag.cate_name = cateItem.CategoryName;
                }

                strbreadcrumbs += string.Format("<li>" + cateItem.CategoryName + "</li>");

                ViewBag.str_breadcrumbs = strbreadcrumbs;
                ViewBag.back_link       = Url.RouteUrl("_lookbook", new { controller = "gallery", action = "LookbookDetail", id = id, Link = cateItem.Link != null ? cateItem.Link : string.Empty, cate_type = cate_type });
                ViewBag.heading         = cateItem.CategoryName;

                this.AddMeta(CommonGlobal.Keyword, cateItem.CategoryName);
                this.AddMeta(CommonGlobal.Description, this.ClearHtml(HttpUtility.HtmlDecode(cateItem.Description)));
                ViewBag.id        = id;
                ViewBag.cate_id   = id;
                ViewBag.cate_type = cate_type;
                ViewBag.ImagePath = cateItem.ImagePath;
                ViewBag.MoreInfo  = cateItem.MoreInfo;

                return(this.PartialView("../page/lookbookDetail"));
            }
        }
Esempio n. 5
0
        public ActionResult IndexGallery(int?page, int TypeId = 0)
        {
            int             defautPagesize   = 10;
            int             total            = 0;
            int             currentPageIndex = page.HasValue ? page.Value - 1 : 0;
            IGalleryService gallerySrv       = IoC.Resolve <IGalleryService>();
            GalleryModels   model            = new GalleryModels();

            model.GalleryTypes = galleryTypeSrv.Query.OrderBy(p => p.TitleVNI).ToList();
            model.TypeID       = TypeId == 0 ? model.GalleryTypes.FirstOrDefault().Id : TypeId;
            var lst = gallerySrv.GetbyType(TypeId, currentPageIndex, defautPagesize, out total);

            model.Galleries = new PagedList <Gallery>(lst, currentPageIndex, defautPagesize, total);
            return(View(model));
        }
        public List<GalleryModels> select(int page, int limit)
        {
            int offset = (page - 1) * limit;
            StringBuilder sqlBuilder = new StringBuilder();
            sqlBuilder.Append("SELECT ");
            sqlBuilder.Append("* ");
            sqlBuilder.Append("FROM ");
            sqlBuilder.Append("gov_gallery gglr ");
            sqlBuilder.Append(getBaseSQL());
            if (page > 0 && limit > 0)
            {
                sqlBuilder.Append(" LIMIT @limit ");
                sqlBuilder.Append(" OFFSET @offset ");
            }
            this.Sql = sqlBuilder.ToString();

            MySqlCommand objCmd = new MySqlCommand(Sql, getConnection());
            if (page > 0 && limit > 0)
            {
                objCmd.Parameters.AddWithValue("@limit", limit);
                objCmd.Parameters.AddWithValue("@offset", offset);
            }

            MySqlDataReader dataReader = objCmd.ExecuteReader();
            List<GalleryModels> lstMenu = new List<GalleryModels>();
            GalleryModels item;
            while (dataReader.Read())
            {
                item = new GalleryModels();
                item.Id = Convert.ToInt32(dataReader["id"]);
                item.Title = dataReader["title"].ToString();
                item.TotalView = Convert.ToInt32(dataReader["total_view"]);
                item.Avatar = dataReader["avatar"].ToString();
                item.AttachFilepath = dataReader["attach_filepath"].ToString();
                item.UpdateUsername = dataReader["update_username"].ToString();
                item.UpdateDatetime = Convert.ToDateTime(dataReader["update_datetime"]);
                lstMenu.Add(item);
            }
            getConnection().Close();
            return lstMenu;
        }
        public ActionResult List_album_images(FormCollection collection)
        {
            CatalogModels         cateModels          = new CatalogModels();
            GalleryModels         galleryModels       = new GalleryModels();
            C_Catalog             cate                = new C_Catalog();
            ImageAlbum            imgPro              = new ImageAlbum();
            StringBuilder         sb                  = new StringBuilder();
            List <SelectListItem> list_select_catalog = new List <SelectListItem>();
            var list_album_images_view                = new Web.Areas.Admin.ViewModels.List_album_images_view();

            this.TryUpdateModel(list_album_images_view);
            int  total_record = 0;
            int  level        = 0;
            bool rt           = true;
            bool is_valid     = true;

            list_album_images_view.Cate_type = CommonGlobal.GetCatalogTypeName(list_album_images_view.Type);
            ////tab
            sb.Append("<li class=\"active\"><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_catalog", ctrl = "adminCatalog", type = list_album_images_view.Type, page = "1", parent = list_album_images_view.Parent }) + "\"><span><span>Danh sách " + CommonGlobal.GetCatalogTypeName(list_album_images_view.Type) + "</span></span></a></li>");
            list_album_images_view.Html_link_tab = sb.ToString();
            ////list page size and paging
            list_album_images_view.List_page_size = this.GetSizePagingPublic(list_album_images_view.Page_size);
            ////acton and parent action
            list_album_images_view.Act               = "list_album_images";
            list_album_images_view.Ctrl              = "adminLink";
            list_album_images_view.Parent_action     = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();
            list_album_images_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();
            ////delete image
            if (list_album_images_view.Id > 0 && list_album_images_view.Type_act == CommonGlobal.Delete)
            {
                ////check permission delete
                if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, list_album_images_view.Act, list_album_images_view.Ctrl, list_album_images_view.Type_act, list_album_images_view.Type))
                {
                    imgPro = galleryModels.GetImageById(list_album_images_view.Id);
                    if (imgPro != null)
                    {
                        ////delete old image
                        if (!string.IsNullOrEmpty(imgPro.Images))
                        {
                            string strImg = imgPro.Images;
                            strImg = "~" + strImg;
                            string fileDelete = Server.MapPath(strImg);
                            if (System.IO.File.Exists(fileDelete))
                            {
                                System.IO.File.Delete(fileDelete);
                            }

                            string fileDelete2 = Server.MapPath(strImg.Replace("sc_small_", "sc_full_"));
                            if (System.IO.File.Exists(fileDelete2))
                            {
                                System.IO.File.Delete(fileDelete2);
                            }
                        }
                        ////delete image product
                        rt = galleryModels.Delete_Images(list_album_images_view.Id);

                        if (rt)
                        {
                            list_album_images_view.Message = "Bạn đã xóa ảnh " + list_album_images_view.Id;
                        }
                        else
                        {
                            list_album_images_view.Message = "Xóa không thành công";
                        }
                    }
                    else
                    {
                        list_album_images_view.Message = "Không tìm thấy ảnh : " + list_album_images_view.Id;
                    }
                }
                else
                {
                    list_album_images_view.Message = " Bạn không có quyền thực thi hành động xóa.";
                }
            }
            else
            {
                if (list_album_images_view.Type_act == CommonGlobal.Add)
                {
                    ////check permission add
                    if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, list_album_images_view.Act, list_album_images_view.Ctrl, list_album_images_view.Type_act, list_album_images_view.Type))
                    {
                        ////validation server
                        if (list_album_images_view.Album == 0)
                        {
                            is_valid = false;
                            list_album_images_view.Message = "Bạn cần lựa chọn album";
                        }

                        if (list_album_images_view.File_image == null)
                        {
                            is_valid = false;
                            list_album_images_view.Message = "Bạn cần chọn ảnh";
                        }

                        var max_length = 1024 * 1024 * 10; ////10MB
                        var length_all = 0;
                        foreach (HttpPostedFileBase fi in list_album_images_view.File_image)
                        {
                            if (fi != null)
                            {
                                length_all = length_all + fi.ContentLength;
                            }
                        }

                        if (length_all == 0)
                        {
                            is_valid = false;
                        }

                        if (length_all > max_length)
                        {
                            is_valid = false;
                            list_album_images_view.Message = "Bạn đã không thể đăng quá nhiều ảnh (Tổng dung lượng tối đa 10MB)";
                        }

                        if (is_valid)
                        {
                            ////upload multi images
                            foreach (HttpPostedFileBase fi in list_album_images_view.File_image)
                            {
                                if (fi != null && fi.ContentLength > 0 && CommonGlobal.IsImage(fi) == true)
                                {
                                    ////add new image
                                    var imgPathTemp = "images/photogallery/" +
                                                      DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/";
                                    var name_time = DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Ticks + string.Empty;

                                    imgPro = new ImageAlbum();
                                    string image_small = imgPathTemp + "sc_small_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(fi.FileName);
                                    string image_lager = imgPathTemp + "sc_full_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(fi.FileName);
                                    //////save images for multi file
                                    this.Savephoto(null, fi, imgPathTemp, image_small, image_lager);

                                    imgPro.Images     = "/" + image_small;
                                    imgPro.ImagesFull = "/" + image_lager;
                                    imgPro.CatalogID  = list_album_images_view.Album;
                                    list_album_images_view.ImagePath = "/" + image_small;
                                    rt = galleryModels.Add_Images(imgPro);

                                    if (rt)
                                    {
                                        list_album_images_view.Message = "Bạn đã thêm ảnh thành công!";
                                    }
                                    else
                                    {
                                        if (list_album_images_view.Message != string.Empty)
                                        {
                                            list_album_images_view.Message = "updload ảnh không thành công: " + CommonGlobal.CompleteNamefileImages(fi.FileName);
                                        }
                                        else
                                        {
                                            list_album_images_view.Message += "; " + CommonGlobal.CompleteNamefileImages(fi.FileName);
                                        }
                                    }

                                    list_album_images_view.File_image = null;
                                }
                            }
                        }
                    }
                    else
                    {
                        list_album_images_view.Message = " Bạn không có quyền thực thi thêm ảnh cho album ";
                    }
                }
                else
                {
                    list_album_images_view.Message = string.Empty;
                }
            }

            ////list language
            list_album_images_view.List_language = this.List_select_language(list_album_images_view.Lang);
            ////list category
            cateModels.List_catalog_parent(0, level, list_album_images_view.Parent, list_album_images_view.Type, list_album_images_view.Lang, ref list_select_catalog);
            list_album_images_view.List_parent = list_select_catalog;
            ////get list product
            list_album_images_view.Page_list_image = galleryModels.AdminGetAllImageGallery(list_album_images_view.Parent, list_album_images_view.Type, list_album_images_view.Lang, list_album_images_view.Page, list_album_images_view.Page_size, list_album_images_view.Order_by, list_album_images_view.Order_type, out total_record);
            list_album_images_view.Total_record    = total_record;
            list_album_images_view.Order_by        = list_album_images_view.Order_by;
            list_album_images_view.Order_type      = list_album_images_view.Order_type;


            return(this.PartialView("../control/list_album_images", list_album_images_view));
        }
        public ActionResult List_album_images(int?parent, int?id, string type, string act, string ctrl, string type_act, string lang, string search, int?page, int?page_size, string order_by, string order_type)
        {
            CatalogModels         cateModels          = new CatalogModels();
            GalleryModels         galleryModels       = new GalleryModels();
            C_Catalog             cate                = new C_Catalog();
            ImageAlbum            img                 = new ImageAlbum();
            StringBuilder         sb                  = new StringBuilder();
            List <SelectListItem> list_select_catalog = new List <SelectListItem>();
            var list_album_images_view                = new Web.Areas.Admin.ViewModels.List_album_images_view();
            int total_record = 0;
            int level        = 0;

            /////type is get type catalog
            /////ex   : LB - Lookbook
            /////     : GL - Gallery
            /////parent is array parent id
            if (string.IsNullOrEmpty(type))
            {
                type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.CateLookBook;
            }

            if (string.IsNullOrEmpty(act))
            {
                act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "list_album_images";
            }

            if (string.IsNullOrEmpty(ctrl))
            {
                ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminLink";
            }

            if (page == null || page == 0)
            {
                page = Request.QueryString["page"] != null?Convert.ToInt32(Request.QueryString["page"].ToString()) : 1;
            }

            if (page_size == null)
            {
                page_size = int.Parse(Util.GetConfigValue("NumberPageSizeAdmin", "30"));
            }

            if (parent == null)
            {
                parent = Request.QueryString["parent"] != null?Convert.ToInt32(Request.QueryString["parent"].ToString()) : 0;
            }

            if (string.IsNullOrEmpty(lang))
            {
                lang = LanguageModels.ActiveLanguage().LangCultureName;
            }

            if (id != null && type_act != null && type_act == CommonGlobal.Delete)
            {
                ////check permission delete
                if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, act, ctrl, type_act, type))
                {
                    img = galleryModels.GetImageById((int)id);
                    if (img != null)
                    {
                        ////delete old image
                        if (!string.IsNullOrEmpty(img.Images))
                        {
                            string strImg = img.Images;
                            strImg = "~" + strImg;
                            string fileDelete = Server.MapPath(strImg);
                            if (System.IO.File.Exists(fileDelete))
                            {
                                System.IO.File.Delete(fileDelete);
                            }

                            string fileDelete2 = Server.MapPath(strImg.Replace("sc_small_", "sc_full_"));
                            if (System.IO.File.Exists(fileDelete2))
                            {
                                System.IO.File.Delete(fileDelete2);
                            }
                        }
                        ////delete imgage album
                        bool rt = galleryModels.Delete_Images((int)id);
                        if (rt)
                        {
                            list_album_images_view.Message = "Bạn đã xóa ảnh " + id;
                        }
                        else
                        {
                            list_album_images_view.Message = "Xóa không thành công";
                        }
                    }
                    else
                    {
                        list_album_images_view.Message = "Không tìm thấy ảnh : " + id;
                    }
                }
                else
                {
                    list_album_images_view.Message = " Bạn không có quyền thực thi hành động xóa.";
                }
            }

            if (string.IsNullOrEmpty(order_by) || string.IsNullOrEmpty(order_type))
            {
                order_by   = "ID";
                order_type = "asc";
            }

            if (parent != 0)
            {
                cate = cateModels.GetbyID((int)parent);
                list_album_images_view.Category_name = cate.CategoryName;
            }

            list_album_images_view.Type      = type;
            list_album_images_view.Cate_type = CommonGlobal.GetCatalogTypeName(type);
            list_album_images_view.Parent    = (int)parent;
            list_album_images_view.Lang      = lang;
            list_album_images_view.Type_act  = type_act;
            ////tab
            sb.Append("<li class=\"active\"><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_catalog", ctrl = "adminCatalog", type = type, page = "1", parent = parent }) + "\"><span><span>Danh sách " + CommonGlobal.GetCatalogTypeName(type) + "</span></span></a></li>");
            list_album_images_view.Html_link_tab = sb.ToString();
            ////list language
            list_album_images_view.List_language = this.List_select_language(this.Lang);
            ////list category for filter
            cateModels.List_catalog_parent(0, level, (int)parent, type, lang, ref list_select_catalog);
            list_album_images_view.List_parent = list_select_catalog;
            ////list page size and paging
            list_album_images_view.List_page_size = this.GetSizePagingPublic((int)page_size);
            list_album_images_view.Page           = (int)page;
            list_album_images_view.Page_size      = (int)page_size;
            ////list product
            list_album_images_view.Page_list_image = galleryModels.AdminGetAllImageGallery((int)parent, type, lang, (int)page, (int)page_size, order_by, order_type, out total_record);
            list_album_images_view.Order_by        = order_by;
            list_album_images_view.Order_type      = order_type;
            list_album_images_view.Total_record    = total_record;
            ////acton and parent action
            list_album_images_view.Act               = act;
            list_album_images_view.Ctrl              = ctrl;
            list_album_images_view.Parent_action     = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();
            list_album_images_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();

            return(this.PartialView("../control/list_album_images", list_album_images_view));
        }