コード例 #1
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));
        }