public void ActionSaveNew(SysTemplateModel model)
 {
     if (ValidSave(model))
     {
         SaveNewRedirect(model.RecordID, _item.ID);
     }
 }
        private bool ValidSave(SysTemplateModel model)
        {
            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 mẫu giao diện.");
            }

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

            try
            {
                //save
                SysTemplateService.Instance.Save(_item);
            }
            catch (Exception ex)
            {
                Error.Write(ex);
                CPViewPage.Message.ListMessage.Add(ex.Message);
                return(false);
            }

            return(true);
        }
 public void ActionApply(SysTemplateModel model)
 {
     if (ValidSave(model))
     {
         ApplyRedirect(model.RecordID, _item.ID);
     }
 }
 public void ActionSave(SysTemplateModel model)
 {
     if (ValidSave(model))
     {
         SaveRedirect();
     }
 }
 private static int GetMaxOrder(SysTemplateModel model)
 {
     return(SysTemplateService.Instance.CreateQuery()
            .Where(o => o.LangID == model.LangID)
            .Max(o => o.Order)
            .ToValue().ToInt(0) + 1);
 }
        public void ActionAdd(SysTemplateModel model)
        {
            _item = model.RecordID > 0 ? SysTemplateService.Instance.GetByID(model.RecordID) : new SysTemplateEntity {
                LangID = model.LangID, Order = GetMaxOrder(model)
            };

            ViewBag.Data  = _item;
            ViewBag.Model = model;
        }
        public void ActionIndex(SysTemplateModel model)
        {
            //sap xep tu dong
            var orderBy = AutoSort(model.Sort, "[Order]");

            //tao danh sach
            var dbQuery = SysTemplateService.Instance.CreateQuery()
                          .Where(o => 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;
        }