Exemple #1
0
        /// <summary> Danh sách sản phẩm nhận bán
        /// </summary>
        /// <returns></returns>
        public ActionResult ProductReceiveSelling(int userId = 0, int viewType = 0)
        {
            if (userId == 0)
            {
                userId = int.Parse(CookieHelper.Get(AdminConfigs.COOKIES_USER_ID));
            }

            // Get Product Receive selling
            ViewBag.ActionSubMenu = "ProductReceiveSelling";

            // Lấy vùng của người dùng.
            UserInRegionService          userInRegionService = new UserInRegionService();
            List <Entities.UserInRegion> lst = userInRegionService.GetListByUser(userId);

            int[] regionIds = lst.Where(x => x.Status).Select(x => x.RegionId).ToArray();

            // Lấy ID sản phẩm chứa vùng.
            List <int> listProductId = productService.ListProductByRegions(regionIds);

            List <Entities.Product> lstEntity = productService.GetByIds(listProductId);
            int totalRecord = 0;

            // Add list product
            ViewBag.ListProduct = lstEntity;
            ViewBag.NumberItem  = lstEntity.Count;
            totalRecord         = lstEntity.Count;

            // Get Max of role by user.
            RoleService roleService = new RoleService();

            Entities.Role maxRole = roleService.GetMaxRolesOfUser(userId);
            ViewBag.MaxRole = maxRole;

            Paging(Page, totalRecord);
            ViewBag.BoxTitle = "Danh sách nhà nhận bán";
            if (viewType == 1)
            {
                return(PartialView("ListProduct2"));
            }
            return(PartialView("Index"));
        }
        private List <Entities.UserInRegion> GetListUserInRegion(int userId, int regionNum, int type)
        {
            List <Entities.UserInRegion> result = new List <Entities.UserInRegion>();

            Entities.UserInRegion model         = new Entities.UserInRegion();
            UserInRegionService   _service      = new UserInRegionService();
            PlaceService          placeService  = new PlaceService();
            RegionService         regionService = new RegionService();

            // Lấy danh sách vùng theo người dùng và kiểu vùng.
            var lst = _service.GetListByUser(userId, type);

            if (lst != null && lst.Count > 0)
            {
                foreach (Entities.UserInRegion e in lst)
                {
                    model = new Entities.UserInRegion();

                    model.CityId     = e.CityId;
                    model.DistrictId = e.DistrictId;
                    model.WardId     = e.WardId;
                    model.UserId     = e.UserId;
                    model.RegionId   = e.RegionId;

                    model.ListCity = placeService.ListPlaceItemByParent(0);

                    if (model.CityId > 0)
                    {
                        model.ListDistrict = placeService.ListPlaceItemByParent(model.CityId);
                    }
                    else
                    {
                        model.ListDistrict = new List <Entities.Item>();
                    }

                    if (model.DistrictId > 0)
                    {
                        model.ListWard = placeService.ListPlaceItemByParent(model.DistrictId);
                    }
                    else
                    {
                        model.ListWard = new List <Entities.Item>();
                    }

                    if (model.RegionId > 0)
                    {
                        model.RegionText = regionService.GetById(model.RegionId).Text;
                    }

                    result.Add(model);
                }
            }

            if (lst.Count < regionNum)
            {
                int addMore = regionNum - lst.Count;
                for (int i = 0; i < addMore; i++)
                {
                    model            = new Entities.UserInRegion();
                    model.CityId     = -1;
                    model.DistrictId = -1;
                    model.WardId     = -1;
                    model.RegionId   = -1;
                    model.RegionText = "";

                    model.ListCity     = placeService.ListPlaceItemByParent(0);
                    model.ListDistrict = new List <Entities.Item>();
                    model.ListWard     = new List <Entities.Item>();

                    result.Add(model);
                }
            }

            return(result);
        }