public void ActionAdd(ModProduct_CustomersModel model) { if (model.RecordID > 0) { item = ModProduct_CustomersService.Instance.GetByID(model.RecordID); // khoi tao gia tri mac dinh khi update } else { item = new ModProduct_CustomersEntity(); // khoi tao gia tri mac dinh khi insert item.Activity = CPViewPage.UserPermissions.Approve; item.PointTotal = 1; item.CreateDate = DateTime.Now; } if (item.ID > 0) { model.NewPassword = "******"; } ViewBag.Data = item; ViewBag.Model = model; // Khởi tạo danh sách nhóm khách hàng item.CustomGroupInId = ModProduct_CustomersGroupsService.Instance.GetListIdCustomersGroups_By_CustomerId(item.ID, true); item.CustomGroupOutId = ModProduct_CustomersGroupsService.Instance.GetListIdCustomersGroups_By_CustomerId(item.ID, false); ViewBag.GetListCustomersGroupsOut = GetListCustomersGroupsByCustomerId(item, false); ViewBag.GetListCustomersGroupsIn = GetListCustomersGroupsByCustomerId(item, true); }
/// <summary> /// Cập nhật lại danh sách: Khách hàng - Nhóm khách hàng /// </summary> /// <param name="sArrGroupsId">Danh sách nhóm khách hàng</param> /// <param name="itemCustomer">Khách hàng Id</param> private void Customer_Groups_Save(string sArrGroupsId, ModProduct_CustomersEntity itemCustomer) { string sQueryDelete = "[CustomersId]=" + itemCustomer.ID; string[] ArrGroupsId = null; // Xóa dữ liệu cũ đi ModProduct_Customers_GroupsService.Instance.Delete(sQueryDelete); // Thêm dữ liệu cập nhật if (string.IsNullOrEmpty(sArrGroupsId)) { return; } ArrGroupsId = sArrGroupsId.Split(','); if (ArrGroupsId == null || ArrGroupsId.Length <= 0) { return; } ModProduct_Customers_GroupsEntity objCustomers_Groups = null; foreach (string itemId in ArrGroupsId) { objCustomers_Groups = new ModProduct_Customers_GroupsEntity(); objCustomers_Groups.CustomersGroupsId = Convert.ToInt32(itemId); objCustomers_Groups.CustomersId = Convert.ToInt32(itemCustomer.ID); objCustomers_Groups.CreateDate = DateTime.Now; objCustomers_Groups.Activity = true; // Cập nhật, lưu lại thông tin ModProduct_Customers_GroupsService.Instance.Save(objCustomers_Groups); } }
/// <summary> /// Lấy danh sách nhóm khách hàng theo Khách hàng Id /// CanTV 2012/09/24 Tạo mới /// </summary> /// <param name="CustomerId">CustomerId: Id khách hàng</param> /// <param name="WhereIn">WhereIn = True nếu lấy danh sách nhóm Khách hàng chứa khách hàng | False: Nếu lấy DS Nhóm khách hàng không chứa khách hàng này</param> /// <returns></returns> public List <ModProduct_CustomersGroupsEntity> GetListCustomersGroupsByCustomerId(ModProduct_CustomersEntity objCustomerEntity, bool WhereIn) { List <ModProduct_CustomersGroupsEntity> lstCustomersGroups = null; if (objCustomerEntity.ID > 0) { if (WhereIn) { if (!string.IsNullOrEmpty(objCustomerEntity.CustomGroupInId)) { lstCustomersGroups = ModProduct_CustomersGroupsService.Instance.CreateQuery() .WhereIn(o => o.ID, objCustomerEntity.CustomGroupInId).ToList(); } } else { if (!string.IsNullOrEmpty(objCustomerEntity.CustomGroupOutId)) { lstCustomersGroups = ModProduct_CustomersGroupsService.Instance.CreateQuery() .WhereIn(o => o.ID, objCustomerEntity.CustomGroupOutId).ToList(); } } } // Lấy tất cả danh sách nếu Id = 0 else if (!WhereIn) { lstCustomersGroups = ModProduct_CustomersGroupsService.Instance.CreateQuery().ToList(); } // Nếu trong trường tạo mới, danh sách các Nhóm KH chứa khách hàng sẽ = Null return(lstCustomersGroups); }