private bool ValidSave(ModDT_KyModel model) { TryUpdateModel(item); bool bolThemMoi = false; if (model.RecordID <= 0) { bolThemMoi = true; } //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); } try { //save ModDT_KyService.Instance.Save(item); #region Chỉ thực hiện khi thêm mới if (bolThemMoi) { // Lấy danh sách Đại lý giới thiệu List <ModDT_DaiLyEntity> lstModDT_DaiLyEntity = ModDT_DaiLyService.Instance.CreateQuery() .Where(o => o.Activity == ConvertTool.ConvertToBoolean((int)EnumValue.Activity.TRUE)).ToList(); if (lstModDT_DaiLyEntity != null && lstModDT_DaiLyEntity.Count > 0) { List <ModDT_Ky_DaiLyEntity> lstModDT_Ky_DaiLyEntity = new List <ModDT_Ky_DaiLyEntity>(); foreach (var itemModDT_DaiLy in lstModDT_DaiLyEntity) { ModDT_Ky_DaiLyEntity objModDT_Ky_DaiLyEntity = new ModDT_Ky_DaiLyEntity(); objModDT_Ky_DaiLyEntity.ModDtKyId = item.ID; if (itemModDT_DaiLy.ModProductAgentParentId != 0) { objModDT_Ky_DaiLyEntity.ModProductAgentParentId = itemModDT_DaiLy.ModProductAgentParentId; } objModDT_Ky_DaiLyEntity.ModProductAgentId = itemModDT_DaiLy.ModProductAgentId; objModDT_Ky_DaiLyEntity.Code = itemModDT_DaiLy.Code; objModDT_Ky_DaiLyEntity.Name = itemModDT_DaiLy.Name; //objModDT_Ky_DaiLyEntity.Type = itemModDT_DaiLy.Type; //objModDT_Ky_DaiLyEntity.Value = itemModDT_DaiLy.Value; //objModDT_Ky_DaiLyEntity.TotalFirst = itemModDT_DaiLy.TotalFirst; //objModDT_Ky_DaiLyEntity.TotalLast = itemModDT_DaiLy.TotalLast; objModDT_Ky_DaiLyEntity.ModLoaiDaiLyCode = itemModDT_DaiLy.ModLoaiDaiLyCode; objModDT_Ky_DaiLyEntity.ModLoaiDaiLyName = itemModDT_DaiLy.ModLoaiDaiLyName; objModDT_Ky_DaiLyEntity.ModLoaiDaiLyType = itemModDT_DaiLy.ModLoaiDaiLyType; objModDT_Ky_DaiLyEntity.ModLoaiDaiLyValue = itemModDT_DaiLy.ModLoaiDaiLyValue; objModDT_Ky_DaiLyEntity.Activity = true; objModDT_Ky_DaiLyEntity.CreateDate = DateTime.Now; lstModDT_Ky_DaiLyEntity.Add(objModDT_Ky_DaiLyEntity); } // Insert ModDT_Ky_DaiLyService.Instance.Save(lstModDT_Ky_DaiLyEntity); } } #endregion } catch (Exception ex) { Global.Error.Write(ex); CPViewPage.Message.ListMessage.Add(ex.Message); return(false); } return(true); } return(false); }