Esempio n. 1
0
 public void ActionApply(SysPageModel model)
 {
     if (ValidSave(model))
     {
         ApplyRedirect(model.RecordID, _item.ID);
     }
 }
Esempio n. 2
0
 public void ActionSaveNew(SysPageModel model)
 {
     if (ValidSave(model))
     {
         SaveNewRedirect(model.RecordID, _item.ID);
     }
 }
Esempio n. 3
0
        public void ActionAdd(SysPageModel model)
        {
            if (model.RecordID > 0)
            {
                _item = SysPageService.Instance.GetByID(model.RecordID);

                //khoi tao gia tri mac dinh khi update
                if (_item.Updated <= DateTime.MinValue)
                {
                    _item.Updated = DateTime.Now;
                }
            }
            else
            {
                _item = new SysPageEntity
                {
                    ParentID = model.ParentID,
                    LangID   = model.LangID,
                    Created  = DateTime.Now,
                    Updated  = DateTime.Now,
                    Order    = GetMaxOrder(model),
                    Activity = true
                };

                //khoi tao gia tri mac dinh khi insert
            }

            ViewBag.Data  = _item;
            ViewBag.Model = model;
        }
Esempio n. 4
0
 public void ActionSave(SysPageModel model)
 {
     if (ValidSave(model))
     {
         SaveRedirect();
     }
 }
Esempio n. 5
0
 private static int GetMaxOrder(SysPageModel model)
 {
     return(SysPageService.Instance.CreateQuery()
            .Where(o => o.LangID == model.LangID && o.ParentID == model.ParentID)
            .Max(o => o.Order)
            .ToValue().ToInt(0) + 1);
 }
Esempio n. 6
0
        public void ActionIndex(SysPageModel model)
        {
            //sap xep tu dong
            var orderBy = AutoSort(model.Sort, "[Order]");

            //tao danh sach
            var dbQuery = SysPageService.Instance.CreateQuery()
                          .Where(o => o.ParentID == model.ParentID && o.LangID == model.LangID)
                          .Take(model.PageSize)
                          .OrderBy(orderBy)
                          .Skip(model.PageIndex * model.PageSize);

            ViewBag.Data      = dbQuery.ToList();
            model.TotalRecord = dbQuery.TotalRecord;
            ViewBag.Model     = model;
        }
Esempio n. 7
0
        private bool ValidSave(SysPageModel model)
        {
            if (!string.IsNullOrEmpty(model.Value))
            {
                foreach (var t in model.Value.Split('\n'))
                {
                    if (string.IsNullOrEmpty(t.Trim()) || t.StartsWith("//"))
                    {
                        continue;
                    }

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

                    //khoi tao gia tri mac dinh khi insert

                    var menu = WebMenuService.Instance.CreateQuery()
                               .Where(o => o.Url == _item.Url)
                               .ToSingle();

                    if (menu != null)
                    {
                        _item.MenuID     = menu.ID;
                        _item.ModuleCode = "M" + (string.IsNullOrEmpty(model.Type) ? menu.Type : model.Type);

                        var template = SysTemplateService.Instance.CreateQuery()
                                       .Where(o => o.Name == menu.Type && o.LangID == menu.LangID)
                                       .ToSingle() ?? SysTemplateService.Instance.CreateQuery().Where(o => o.LangID == menu.LangID).Take(1).ToSingle();

                        if (template != null)
                        {
                            _item.TemplateID = template.ID;
                        }
                    }

                    _item.ParentID   = model.ParentID;
                    _item.LangID     = model.LangID;
                    _item.TemplateID = model.TeamplateID;
                    _item.Created    = DateTime.Now;
                    _item.Updated    = DateTime.Now;
                    _item.Order      = GetMaxOrder(model);
                    _item.Activity   = true;
                    _item.Levels     = _item.Parent.Levels + "-" + _item.ID;

                    SysPageService.Instance.Save(_item);

                    //update url
                    ModCleanURLService.Instance.InsertOrUpdate(_item.Url, "Page", _item.ID, _item.MenuID, model.LangID);
                }

                return(true);
            }

            TryUpdateModel(_item);

            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 trang.");
            }

            if (ModCleanURLService.Instance.CheckUrl(_item.Url, "Page", _item.ID, model.LangID))
            {
                CPViewPage.Message.ListMessage.Add("Mã đã tồn tại. Vui lòng chọn mã khá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);
            }

            //neu di chuyen thi cap nhat lai Order
            if (model.RecordID > 0 && _item.ParentID != model.ParentID)
            {
                _item.Order = GetMaxOrder(model);
            }

            //cap nhat state
            _item.State = GetState(model.ArrState);

            try
            {
                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)
                {
                    SysPageService.Instance.Save(_item);
                    _item.Levels = !string.IsNullOrEmpty(_item.Parent.Levels) ? _item.Parent.Levels + "-" + _item.ID : _item.ID.ToString();
                }
                //save
                SysPageService.Instance.Save(_item);

                //update url
                ModCleanURLService.Instance.InsertOrUpdate(_item.Url, "Page", _item.ID, _item.MenuID, model.LangID);
            }
            catch (Exception ex)
            {
                Error.Write(ex);
                CPViewPage.Message.ListMessage.Add(ex.Message);
                return(false);
            }

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