Ejemplo n.º 1
0
        public ActionResult Change_link(int?id, string type, string act, string ctrl, string lang, string type_act)
        {
            LinkModels    linkModels = new LinkModels();
            C_Link        clink      = new C_Link();
            StringBuilder sb         = new StringBuilder();
            var           link_view  = new Web.Areas.Admin.ViewModels.Link_view();

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

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

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

            if (id == null)
            {
                id = RouteData.Values["id"] != null?Convert.ToInt32(RouteData.Values["id"].ToString()) : 0;
            }

            if (string.IsNullOrEmpty(type_act))
            {
                type_act = Request.QueryString["type_act"] != null ? Request.QueryString["type_act"].ToString() : CommonGlobal.Add;
                if (id == 0)
                {
                    type_act = CommonGlobal.Add;
                }
                else
                {
                    type_act = CommonGlobal.Edit;
                }
            }

            if (type_act == CommonGlobal.Edit)
            {
                clink = linkModels.GetByID((int)id);
                sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_link", ctrl = "adminLink", type_act = CommonGlobal.Add, type = type, page = "1" }) + "\"><span><span>Danh sách " + CommonGlobal.GetLinkADTypeName(type) + "</span></span></a></li>");
                sb.Append("<li class=\"active\"><a href=\"#\"><span><span>" + clink.Title + "</span></span></a></li>");
                link_view.Lang          = clink.Lang ?? lang;
                link_view.Id            = clink.ID;
                link_view.Title         = clink.Title;
                link_view.ImagePath     = clink.ImagePath;
                link_view.LinkContent   = clink.LinkContent;
                link_view.Link_url      = clink.Link;
                link_view.Summary       = clink.Summary;
                link_view.OrderDisplay  = clink.OrderDisplay ?? 0;
                link_view.List_language = this.List_select_language(clink.Lang ?? this.Lang);
            }
            else
            {
                sb.Append("<li><a href=\"" + Url.Action("index", "dashboard", new { act = "list_link", ctrl = "adminLink", type_act = CommonGlobal.Add, type = type, page = "1" }) + "\"><span><span>Danh sách " + CommonGlobal.GetLinkADTypeName(type) + "</span></span></a></li>");
                sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm mới</span></span></a></li>");
                link_view.Lang          = lang;
                link_view.List_language = this.List_select_language(this.Lang);
                link_view.OrderDisplay  = linkModels.GetMaxOrderDisplay(type);
            }

            link_view.Html_link_tab = sb.ToString();
            link_view.Type          = type;
            link_view.Type_act      = type_act;
            ////action and parent action
            link_view.Act               = act;
            link_view.Ctrl              = ctrl;
            link_view.Parent_action     = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();
            link_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();

            return(this.PartialView("../control/change_link", link_view));
        }
Ejemplo n.º 2
0
        public ActionResult Change_link(FormCollection collection)
        {
            LinkModels    linkModels = new LinkModels();
            C_Link        clink      = new C_Link();
            StringBuilder sb         = new StringBuilder();
            var           link_view  = new Web.Areas.Admin.ViewModels.Link_view();

            this.TryUpdateModel(link_view);
            int  rt       = 0;
            bool is_valid = true;

            if (link_view.Id > 0)
            {
                clink = linkModels.GetByID(link_view.Id);
            }

            ////validation server
            if (string.IsNullOrEmpty(link_view.Title))
            {
                is_valid          = false;
                link_view.Message = "Bạn cần nhập tiêu đề";
            }

            ////action
            link_view.Parent_action     = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString();
            link_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString();
            ////Link tab
            var link_dashboard = Url.Action("index", "dashboard", new { act = "list_link", ctrl = "adminLink", type_act = CommonGlobal.Add, type = link_view.Type, page = "1" });

            sb.Append("<li><a href=\"" + link_dashboard + "\"><span><span>Danh sách " + CommonGlobal.GetLinkADTypeName(link_view.Type) + "</span></span></a></li>");
            if (link_view.Id != 0 && link_view.Type_act == CommonGlobal.Edit)
            {
                sb.Append("<li class=\"active\"><a href=\"#\"><span><span>" + clink.Title + "</span></span></a></li>");
                link_view.List_language = this.List_select_language(clink.Lang);
            }
            else
            {
                sb.Append("<li class=\"active\"><a href=\"#\"><span><span>Thêm mới</span></span></a></li>");
                link_view.List_language = this.List_select_language(link_view.Lang);
            }

            link_view.Html_link_tab = sb.ToString();
            if (!is_valid)
            {
                return(this.PartialView("../control/change_link", link_view));
            }

            clink.Title       = link_view.Title;
            clink.Summary     = string.IsNullOrEmpty(link_view.Summary) == false ? link_view.Summary : string.Empty;
            clink.LinkContent = string.IsNullOrEmpty(link_view.LinkContent) == false ? link_view.LinkContent : string.Empty;
            clink.Link        = string.IsNullOrEmpty(link_view.Link_url) == false ? link_view.Link_url : string.Empty;
            clink.Lang        = link_view.Lang;
            clink.Type        = link_view.Type;

            var imgPathTemp = "images/link/" + 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 + string.Empty;

            if (link_view.File_image != null && link_view.File_image.ContentLength > 0 && CommonGlobal.IsImageOrVideo(link_view.File_image) == true)
            {
                string image_name = imgPathTemp + "sc_original_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(link_view.File_image.FileName);

                ////save image and delete old file
                this.SavephotoOriginal(clink.ImagePath, link_view.File_image, imgPathTemp, image_name);

                ////set image thumb to link catalog
                clink.ImagePath     = "/" + image_name;
                link_view.ImagePath = "/" + image_name;
            }
            else if (string.IsNullOrEmpty(clink.ImagePath))
            {
                clink.ImagePath = "0";
            }
            else
            {
                clink.ImagePath = link_view.ImagePath;
            }

            clink.OrderDisplay = link_view.OrderDisplay;

            if (link_view.Id != 0 && link_view.Type_act == CommonGlobal.Edit)
            {
                rt = linkModels.Update(clink);
            }
            else
            {
                rt = linkModels.Add(clink);
            }

            if (rt > 0)
            {
                linkModels.ClearCache(CommonGlobal.Slide);
                link_view.Message  = "Cập nhật thành công!";
                link_view.Id       = rt;
                link_view.Type_act = CommonGlobal.Edit;
            }
            else
            {
                link_view.Message = "Cập nhật không thành công!";
            }

            // return this.PartialView("../control/change_link", link_view);

            string return_url = Url.Action("index", "dashboard", new { act = "list_link", ctrl = "adminLink", type = link_view.Type, type_act = Web.Models.CommonGlobal.Edit, page = 1, parent = 0 });

            return(this.PartialView("../control/redirect", return_url));
        }