コード例 #1
0
        public void ActionAdd(ModProduct_GroupsModel model)
        {
            if (model.RecordID > 0)
            {
                item = ModProduct_GroupsService.Instance.GetByID(model.RecordID);

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

                // khoi tao gia tri mac dinh khi insert
                item.Activity   = CPViewPage.UserPermissions.Approve;
                item.CreateDate = DateTime.Now;
                item.ParentId   = 0;
            }

            string sPropertiesGroupsInId  = string.Empty;
            string sPropertiesGroupsOutId = string.Empty;

            ViewBag.GetListPropertiesGroupsIn  = GetListPropertiesGroupByProductId(item, true, ref sPropertiesGroupsInId);
            ViewBag.GetListPropertiesGroupsOut = GetListPropertiesGroupByProductId(item, false, ref sPropertiesGroupsOutId);

            // Khởi tạo danh sách thuộc tính

            model.PropertiesGroupsInId  = sPropertiesGroupsInId;
            model.PropertiesGroupsOutId = sPropertiesGroupsOutId;


            ViewBag.Data  = item;
            ViewBag.Model = model;
        }
コード例 #2
0
        /// <summary>
        ///  Lấy danh sách NHóm thuộc tính theo  Id Product Info: Not in hoặc In
        ///  CanTV      2012/09/24      Tạo mới
        /// </summary>
        /// <param name="objProductGroupEntity">objPropertiesGroups: Thuộc tính Id</param>
        /// <param name="WhereIn">WhereIn = True nếu lấy IN | False: Nếu lấy  Not in</param>
        /// <returns></returns>
        public List <ModProduct_PropertiesGroupsEntity> GetListPropertiesGroupByProductId(
            ModProduct_GroupsEntity objProductGroupEntity,
            bool WhereIn,
            ref string sPropertiesGroupsId)
        {
            List <ModProduct_Groups_PropertiesGroupsEntity> lstGroupsList = null;
            List <ModProduct_PropertiesGroupsEntity>        lstReturnList = null;

            if (objProductGroupEntity.ID > 0)
            {
                if (WhereIn)
                {
                    lstGroupsList = ModProduct_Groups_PropertiesGroupsService.Instance.CreateQuery()
                                    .Where(o => o.ProductGroupsId == objProductGroupEntity.ID).ToList();
                }
                else
                {
                    // Lấy những nhóm chứa
                    GetListPropertiesGroupByProductId(objProductGroupEntity, true, ref sPropertiesGroupsId);

                    //Lấy những nhóm không chứa (Not in)
                    lstReturnList = ModProduct_PropertiesGroupsService.Instance.CreateQuery()
                                    .WhereNotIn(o => o.ID, string.IsNullOrEmpty(sPropertiesGroupsId) ? "0" : sPropertiesGroupsId)
                                    .ToList();
                }
            }

            // Lấy tất cả danh sách nếu Id = 0
            else
            if (!WhereIn)
            {
                // Lấy toàn bộ các Nhóm
                lstReturnList = ModProduct_PropertiesGroupsService.Instance
                                .CreateQuery()
                                .ToList();
            }

            if (lstGroupsList == null)
            {
                if (lstReturnList == null)
                {
                    return(null);
                }

                else
                {
                    // Lấy danh sách chuỗi
                    foreach (ModProduct_PropertiesGroupsEntity item in lstReturnList)
                    {
                        if (string.IsNullOrEmpty(sPropertiesGroupsId))
                        {
                            sPropertiesGroupsId = item.ID.ToString();
                        }
                        else
                        {
                            sPropertiesGroupsId = sPropertiesGroupsId + "," + item.ID.ToString();
                        }
                    }
                }
            }
            else
            {
                // Lấy danh sách chuỗi
                foreach (ModProduct_Groups_PropertiesGroupsEntity item in lstGroupsList)
                {
                    if (string.IsNullOrEmpty(sPropertiesGroupsId))
                    {
                        sPropertiesGroupsId = item.PropertiesGroupsId.ToString();
                    }
                    else
                    {
                        sPropertiesGroupsId = sPropertiesGroupsId + "," + item.PropertiesGroupsId.ToString();
                    }
                }

                // Lấy nhóm theo danh sách
                if (WhereIn)
                {
                    lstReturnList = ModProduct_PropertiesGroupsService.Instance.CreateQuery()
                                    .WhereIn(o => o.ID, sPropertiesGroupsId)
                                    .ToList();
                }
                else
                {
                    lstReturnList = ModProduct_PropertiesGroupsService.Instance.CreateQuery()
                                    .WhereNotIn(o => o.ID, sPropertiesGroupsId)
                                    .ToList();
                }
            }
            // Nếu trong trường tạo mới, danh sách các chứa sẽ = Null
            return(lstReturnList);
        }