public void ActionSaveNew(FormBaoCaoBanDauSuCoModel model, MInfoMagicModelForm modelInfo, MAppendForm append)
 {
     if (ValidSave(model, modelInfo, append))
     {
         SaveNewRedirect(model.RecordID, entity.ID);
     }
 }
 public void ActionSave(FormBaoCaoBanDauSuCoModel model, MInfoMagicModelForm modelInfo, MAppendForm append)
 {
     if (ValidSave(model, modelInfo, append))
     {
         SaveRedirect();
     }
 }
        private bool ValidSave(FormBaoCaoBanDauSuCoModel model, MInfoMagicModelForm modelInfo, MAppendForm 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 = ModBaoCaoBanDauSuCoService.Instance.Save(entity);
                if (model.RecordID > 0)
                {
                    UpdateOther(entity, modelInfo, append);
                }
                else
                {
                    SaveOther(id, modelInfo, append);
                }

                return(true);
            }

            return(false);
        }
        public void ActionAdd(FormBaoCaoBanDauSuCoModel model)
        {
            if (model.RecordID > 0)
            {
                entity = ModBaoCaoBanDauSuCoService.Instance.GetByID(model.RecordID);

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

                ViewBag.CachThuc = ModInfoMagicService.Instance.CreateQuery()
                                   .Where(o => o.Activity == true && o.BaoCaoBanDauSuCoID == entity.ID)
                                   .WhereIn(o => o.MenuID, WebMenuService.Instance.GetChildIDForWeb_Cache("CachThuc", model.MenuID, model.LangID))
                                   .ToList();

                ViewBag.ThongBao = ModInfoMagicService.Instance.CreateQuery()
                                   .Where(o => o.Activity == true && o.BaoCaoBanDauSuCoID == entity.ID)
                                   .WhereIn(o => o.MenuID, WebMenuService.Instance.GetChildIDForWeb_Cache("GuiThongBaoSuCo", model.MenuID, model.LangID))
                                   .ToList();

                ViewBag.DichVu = ModInfoMagicService.Instance.CreateQuery()
                                 .Where(o => o.Activity == true && o.BaoCaoBanDauSuCoID == entity.ID)
                                 .WhereIn(o => o.MenuID, WebMenuService.Instance.GetChildIDForWeb_Cache("DichVu", model.MenuID, model.LangID))
                                 .ToList();

                ViewBag.BienPhap = ModInfoMagicService.Instance.CreateQuery()
                                   .Where(o => o.Activity == true && o.BaoCaoBanDauSuCoID == entity.ID)
                                   .WhereIn(o => o.MenuID, WebMenuService.Instance.GetChildIDForWeb_Cache("BienPhapATTT", model.MenuID, model.LangID))
                                   .ToList();

                ViewBag.ThongTinGuiKem = ModInfoMagicService.Instance.CreateQuery()
                                         .Where(o => o.Activity == true && o.BaoCaoBanDauSuCoID == entity.ID)
                                         .WhereIn(o => o.MenuID, WebMenuService.Instance.GetChildIDForWeb_Cache("ThongTinGuiKem", model.MenuID, model.LangID))
                                         .ToList();
            }
            else
            {
                entity = new ModBaoCaoBanDauSuCoEntity();

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

            ViewBag.Data  = entity;
            ViewBag.Model = model;
        }
        public void ActionIndex(FormBaoCaoBanDauSuCoModel model)
        {
            // sap xep tu dong
            string orderBy = AutoSort(model.Sort);

            // tao danh sach
            var dbQuery = ModBaoCaoBanDauSuCoService.Instance.CreateQuery()
                          .Where(!string.IsNullOrEmpty(model.SearchText), o => o.Name.Contains(model.SearchText))
                          .Where(model.State > 0, o => (o.State & model.State) == model.State)
                          .Where(o => o.BaoCaoSuCoID == model.BaoCaoSuCoID)
                          .WhereIn(o => o.MenuID, WebMenuService.Instance.GetChildIDForCP("BaoCaoBanDauSuCo", 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;
        }
 private int GetMaxOrder(FormBaoCaoBanDauSuCoModel model)
 {
     return(ModBaoCaoBanDauSuCoService.Instance.CreateQuery()
            .Max(o => o.Order)
            .ToValue().ToInt(0) + 1);
 }