Esempio n. 1
0
 public void ActionApply(SysMenuModel model)
 {
     if (ValidSave(model))
     {
         ApplyRedirect(model.RecordID, _item.ID);
     }
 }
Esempio n. 2
0
 public void ActionSaveNew(SysMenuModel model)
 {
     if (ValidSave(model))
     {
         SaveNewRedirect(model.RecordID, _item.ID);
     }
 }
Esempio n. 3
0
 private static int GetMaxOrder(SysMenuModel model)
 {
     return(WebMenuService.Instance.CreateQuery()
            .Where(o => o.LangID == model.LangID && o.ParentID == model.ParentID)
            .Max(o => o.Order)
            .ToValue().ToInt(0) + 1);
 }
Esempio n. 4
0
 public void ActionSave(SysMenuModel model)
 {
     if (ValidSave(model))
     {
         SaveRedirect();
     }
 }
Esempio n. 5
0
        public void ActionIndex(SysMenuModel model)
        {
            //sap xep tu dong
            var orderBy = AutoSort(model.Sort, "[Order]");

            //tao danh sach
            var dbQuery = WebMenuService.Instance.CreateQuery()
                          .Where(!string.IsNullOrEmpty(model.SearchText), o => (o.Name.Contains(model.SearchText) || o.Url.Contains(model.SearchText)))
                          .Where(o => o.ParentID == model.ParentID && o.LangID == model.LangID)
                          .Take(model.PageSize)
                          .Skip(model.PageIndex * model.PageSize)
                          .OrderBy(orderBy);

            ViewBag.Data      = dbQuery.ToList();
            model.TotalRecord = dbQuery.TotalRecord;
            ViewBag.Model     = model;
        }
Esempio n. 6
0
        public void ActionAdd(SysMenuModel model)
        {
            if (model.RecordID > 0)
            {
                _item = WebMenuService.Instance.GetByID(model.RecordID);

                //khoi tao gia tri mac dinh khi update
            }
            else
            {
                //khoi tao gia tri mac dinh khi insert
                _item = new WebMenuEntity
                {
                    LangID   = model.LangID,
                    ParentID = model.ParentID,
                    Type     = model.ParentID > 0 ? WebMenuService.Instance.GetByID(model.ParentID).Type : "News",
                    Order    = GetMaxOrder(model),
                    Activity = true
                };
            }

            ViewBag.Data  = _item;
            ViewBag.Model = model;
        }
Esempio n. 7
0
        private bool ValidSave(SysMenuModel model)
        {
            if (!string.IsNullOrEmpty(model.Value))
            {
                var parent = WebMenuService.Instance.GetByID(model.ParentID);
                if (parent == null)
                {
                    return(false);
                }

                var ArrItem = model.Value.Split('\n');

                foreach (var t in ArrItem)
                {
                    if (string.IsNullOrEmpty(t.Trim()) || t.StartsWith("//"))
                    {
                        continue;
                    }

                    _item = new WebMenuEntity {
                        Name = t.Trim(), Url = Data.GetCode(t.Trim())
                    };

                    var exists = WebMenuService.Instance.CreateQuery()
                                 .Where(o => o.Url == _item.Url && o.Type == parent.Type && o.LangID == parent.LangID)
                                 .Count()
                                 .ToValue()
                                 .ToBool();

                    if (exists)
                    {
                        continue;
                    }

                    _item.Type = parent.Type;

                    _item.ParentID = model.ParentID;
                    _item.LangID   = parent.LangID;
                    if (!exists)
                    {
                        WebMenuService.Instance.Save(_item);
                    }
                    _item.Levels = _item.Parent.Levels + "-" + _item.ID;

                    _item.Order    = GetMaxOrder(model);
                    _item.Activity = true;


                    WebMenuService.Instance.Save(_item);
                }

                return(true);
            }
            else
            {
                TryUpdateModel(_item);

                _item.ID = model.RecordID;

                ViewBag.Data  = _item;
                ViewBag.Model = model;

                CPViewPage.Message.MessageType = Message.MessageTypeEnum.Error;

                //kiem tra ten
                if (_item.Name.Trim() == string.Empty)
                {
                    CPViewPage.Message.ListMessage.Add("Nhập tên chuyên mục.");
                }

                if (CPViewPage.Message.ListMessage.Count != 0)
                {
                    return(false);
                }

                //neu code khong duoc nhap -> tu dong tao ra khi them moi
                if (_item.Url == string.Empty)
                {
                    _item.Url = Data.GetCode(_item.Name);
                }


                try
                {
                    //neu di chuyen thi cap nhat lai Type va Order
                    if (model.RecordID > 0 && _item.ParentID != model.ParentID)
                    {
                        //cap nhat Type
                        if (_item.ParentID != 0)
                        {
                            _item.Type = WebMenuService.Instance.GetByID(_item.ParentID).Type;
                        }

                        //cap nhat Order
                        _item.Order = GetMaxOrder(model);
                    }
                    if (_item.ParentID > 0 && _item.ID > 0)
                    {
                        _item.Levels = !string.IsNullOrEmpty(_item.Parent.Levels) ? _item.Parent.Levels + "-" + _item.ID : _item.ID.ToString();
                    }
                    else if (_item.ID < 1)
                    {
                        WebMenuService.Instance.Save(_item);
                        _item.Levels = !string.IsNullOrEmpty(_item.Parent.Levels) ? _item.Parent.Levels + "-" + _item.ID : _item.ID.ToString();
                    }
                    //save
                    WebMenuService.Instance.Save(_item);

                    //neu di chuyen thi cap nhat lai Type cua chuyen muc con
                    if (model.RecordID > 0 && _item.ParentID != model.ParentID && _item.ParentID != 0)
                    {
                        //lay danh sach chuyen muc con
                        var list = new List <int>();
                        GetMenuIDChild(ref list, model.RecordID);

                        //cap nhat Type cho danh sach chuyen muc con
                        if (list.Count > 1)
                        {
                            WebMenuService.Instance.Update("[ID] IN (" + Core.Global.Array.ToString(list.ToArray()) + ")",
                                                           "@Type", WebMenuService.Instance.GetByID(_item.ParentID).Type);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Error.Write(ex);
                    CPViewPage.Message.ListMessage.Add(ex.Message);
                    return(false);
                }

                return(true);
            }
        }
Esempio n. 8
0
 public void ActionImport(SysMenuModel model)
 {
     ViewBag.Model = model;
 }
Esempio n. 9
0
 public void ActionUpload(SysMenuModel model)
 {
     CPViewPage.Script("Redirect", "REDDEVILRedirect('Import')");
 }