コード例 #1
0
 public void ActionSaveNew(ModProduct_SurveyGroup_DetailModel model)
 {
     if (ValidSave(model))
     {
         SaveNewRedirect(model.RecordID, item.ID);
     }
 }
コード例 #2
0
 public void ActionSave(ModProduct_SurveyGroup_DetailModel model)
 {
     if (ValidSave(model))
     {
         SaveRedirect();
     }
 }
コード例 #3
0
        public void ActionIndex(ModProduct_SurveyGroup_DetailModel model)
        {
            // sap xep tu dong
            string orderBy = string.Empty;

            if (model.Sort != null)
            {
                orderBy = AutoSort(model.Sort);
            }
            else
            {
                orderBy = "[SurveyGroupId],[Order] ASC";
            }

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

            ViewBag.Data      = dbQuery.ToList();
            model.TotalRecord = dbQuery.TotalRecord;
            ViewBag.Model     = model;
        }
コード例 #4
0
        private bool ValidSave(ModProduct_SurveyGroup_DetailModel model)
        {
            TryUpdateModel(item);

            //chong hack
            item.ID = model.RecordID;

            ViewBag.Data  = item;
            ViewBag.Model = model;

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

            //kiem tra quyen han
            if ((model.RecordID < 1 && !CPViewPage.UserPermissions.Add) || (model.RecordID > 0 && !CPViewPage.UserPermissions.Edit))
            {
                CPViewPage.Message.ListMessage.Add("Quyền hạn chế.");
            }

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

            if (CPViewPage.Message.ListMessage.Count == 0)
            {
                //neu khong nhap code -> tu sinh
                if (item.Code.Trim() == string.Empty)
                {
                    item.Code = Data.GetCode(item.Name);
                }

                if (item.Vote < 0)
                {
                    item.Vote = 0;
                }

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

                return(true);
            }

            return(false);
        }
コード例 #5
0
        public void ActionAdd(ModProduct_SurveyGroup_DetailModel model)
        {
            if (model.RecordID > 0)
            {
                item = ModProduct_SurveyGroup_DetailService.Instance.GetByID(model.RecordID);

                // khoi tao gia tri mac dinh khi update
            }
            else
            {
                item = new ModProduct_SurveyGroup_DetailEntity();

                // khoi tao gia tri mac dinh khi insert
                item.Order    = GetMaxOrder(model);
                item.Activity = CPViewPage.UserPermissions.Approve;
            }

            ViewBag.Data  = item;
            ViewBag.Model = model;
        }
コード例 #6
0
 private int GetMaxOrder(ModProduct_SurveyGroup_DetailModel model)
 {
     return(ModProduct_SurveyGroup_DetailService.Instance.CreateQuery()
            .Max(o => o.Order)
            .ToValue().ToInt(0) + 1);
 }