Пример #1
0
        public void ActionAdd(ModHSThanhVienUCSCModel model)
        {
            if (model.RecordID > 0)
            {
                entity = ModHSThanhVienUCSCService.Instance.GetByID(model.RecordID);

                // khoi tao gia tri mac dinh khi update
                entity.UserID1 = Lib.Global.CPLogin.UserID;

                entityDM = ModDauMoiUCSCService.Instance.CreateQuery()
                           .Where(o => o.Activity == true && o.HSThanhVienUCSCID == model.RecordID)
                           .ToSingle();
                entityHTTT = ModHeThongThongTinService.Instance.CreateQuery()
                             .Where(o => o.Activity == true && o.DauMoiUCSCID == entityDM.ID)
                             .ToList();
            }
            else
            {
                entity     = new ModHSThanhVienUCSCEntity();
                entityDM   = new ModDauMoiUCSCEntity();
                entityHTTT = new List <ModHeThongThongTinEntity>();

                // khoi tao gia tri mac dinh khi insert
                entity.MenuID    = model.MenuID;
                entity.UserID    = Lib.Global.CPLogin.UserID;
                entity.Published = DateTime.Now;
                entity.Activity  = CPViewPage.UserPermissions.Approve;
                entity.Order     = GetMaxOrder(model);
            }

            ViewBag.DauMoi = entityDM;
            ViewBag.HTTT   = entityHTTT;
            ViewBag.Data   = entity;
            ViewBag.Model  = model;
        }
Пример #2
0
 public void ActionSaveNew(ModHSThanhVienUCSCModel model, ModDauMoiUCSCEntity entityDm, MAppend append)
 {
     if (ValidSave(model, entityDm, append))
     {
         SaveNewRedirect(model.RecordID, entity.ID);
     }
 }
Пример #3
0
 public void ActionSave(ModHSThanhVienUCSCModel model, ModDauMoiUCSCEntity entityDm, MAppend append)
 {
     if (ValidSave(model, entityDm, append))
     {
         SaveRedirect();
     }
 }
Пример #4
0
        private bool ValidSave(ModHSThanhVienUCSCModel model, ModDauMoiUCSCEntity entityDm, MAppend append)
        {
            TryUpdateModel(entity);

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

            ViewBag.Data  = entity;
            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 (entity.Name.Trim() == string.Empty)
            {
                CPViewPage.Message.ListMessage.Add("Nhập tên.");
            }

            //kiem tra chuyen muc
            //if (entity.MenuID < 1)
            //    CPViewPage.Message.ListMessage.Add("Chọn chuyên mục.");

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

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

                //save
                int id = ModHSThanhVienUCSCService.Instance.Save(entity);
                if (model.RecordID > 0)
                {
                    UpdateOther(entity, entityDm, append);
                }
                else
                {
                    SaveOther(id, entityDm, append);
                }

                return(true);
            }

            return(false);
        }
Пример #5
0
        public void ActionIndex(ModHSThanhVienUCSCModel model)
        {
            // sap xep tu dong
            string orderBy = AutoSort(model.Sort);

            // tao danh sach
            var dbQuery = ModHSThanhVienUCSCService.Instance.CreateQuery()
                          .Where(!string.IsNullOrEmpty(model.SearchText), o => o.Name.Contains(model.SearchText))
                          .Where(model.State > 0, o => (o.State & model.State) == model.State)
                          .WhereIn(o => o.MenuID, WebMenuService.Instance.GetChildIDForCP("HSThanhVienUCSC", model.MenuID, model.LangID))
                          .Take(model.PageSize)
                          .OrderBy(orderBy)
                          .Skip(model.PageIndex * model.PageSize);

            ViewBag.Data      = dbQuery.ToList();
            model.TotalRecord = dbQuery.TotalRecord;
            ViewBag.Model     = model;
        }
Пример #6
0
 private int GetMaxOrder(ModHSThanhVienUCSCModel model)
 {
     return(ModHSThanhVienUCSCService.Instance.CreateQuery()
            .Max(o => o.Order)
            .ToValue().ToInt(0) + 1);
 }