Пример #1
0
        public JsonResult GetListCustomerWantToUse(SelectListModelCardUpload obj)
        {
            var totalPage = 0;
            var totalItem = 0;
            var pageSize  = 0;

            var dtg = new List <AccessUploadMultiDevice>();

            //Lấy người dùng hiện tại
            var user = GetCurrentUser.GetUser();

            var model = new SelectListModelCardUploadReturn();

            model.ListSelfHost   = GetSetFromSessionSelfHost(null);
            model.ListController = GetSetFromSessionController(null);
            model.ListEmployee   = new List <Employee>();
            model.IsUseNewDate   = obj.isusenewdate;

            if (obj.isall)
            {
                var customergroups = GetListChild("", obj.customergroupid);

                var list      = _tblCustomerService.GetAllPagingByFirstForUpload(obj.key, "", customergroups, "", "", obj.pageIndex, obj.pageSize, obj.accesslevelids);
                var gridModel = PageModelCustom <tblCustomerExtend> .GetPage(list, obj.pageIndex, obj.pageSize);

                totalPage = gridModel.TotalPage;
                totalItem = gridModel.TotalItem;
                pageSize  = gridModel.PageSize;

                model.ListCustomer = gridModel.Data.ToList();

                //var customergroups = GetListChild("", obj.customergroupid);

                //model.ListCustomer = _tblCustomerService.GetAllByFirst(obj.key, "", customergroups, "", "", obj.accesslevelids);

                //totalPage = model.ListCustomer.Count / 10;
            }
            else
            {
                var models = GetSetFromSessionCustomer(null);
                model.ListCustomer = _tblCustomerService.GetAllByFirst(models);
            }

            if (model.ListCustomer.Any())
            {
                foreach (var item in model.ListSelfHost)
                {
                    var ko = new AccessUploadMultiDevice()
                    {
                        Address   = item.Address,
                        pageIndex = obj.pageIndex,
                        totalPage = totalPage,
                        totalItem = totalItem,
                        pageSize  = pageSize
                    };

                    var lines = _tblAccessLineService.GetAllActiveByListPC(item.PCID);

                    var ControllerByPC = model.ListController.Where(n => lines.Any(m => m.LineID.ToString() == n.LineID)).ToList();

                    model.ListEmployee = new List <Employee>();

                    ko.totalItem       = ko.totalItem * ControllerByPC.Count;
                    ko.totalController = ControllerByPC.Count;

                    foreach (var itemCustomer in model.ListCustomer)
                    {
                        foreach (var itemController in ControllerByPC)
                        {
                            var map = new Employee();

                            map.CardNumber = "0";

                            map.AccessLevelID = itemCustomer.AccessLevelID.Trim();

                            map.ControllerIDs = itemController.ControllerID.ToString();

                            map.UserID = user.Id;

                            map.UserIDofFinger = itemCustomer.UserIDofFinger;

                            map.Fingers1 = itemCustomer.Finger1;

                            map.Fingers2 = itemCustomer.Finger2;

                            map.Passwords = itemCustomer.Password;

                            map.VerifyTypeID = 0;

                            if (obj.isusenewdate)
                            {
                                map.ExpireDate = Convert.ToDateTime(obj.newdateexpire).ToString("yyyyMMdd").Trim();
                            }
                            else
                            {
                                map.ExpireDate = Convert.ToDateTime(itemCustomer.AccessExpireDate).ToString("yyyyMMdd").Trim();
                            }

                            model.ListEmployee.Add(map);
                        }
                    }

                    ko.DataSend = model.ListEmployee;

                    dtg.Add(ko);
                }
            }

            var t = new SelectListModelCardUploadReturn2()
            {
                ListEmployee = model.ListEmployee,
                ListSelfHost = model.ListSelfHost
            };

            //var red = JsonConvert.SerializeObject(t);

            var a = new JsonResult {
                Data = dtg, MaxJsonLength = Int32.MaxValue
            };

            return(a);

            //return Json(model, JsonRequestBehavior.AllowGet);
        }
Пример #2
0
        public JsonResult GetListCardWantToUse(SelectListModelCardUpload obj)
        {
            var totalPage = 0;
            var totalItem = 0;
            var pageSize  = 0;

            var dtg = new List <AccessUploadMultiDevice>();

            //Lấy người dùng hiện tại
            var user = GetCurrentUser.GetUser();

            var model = new SelectListModelCardUploadReturn();

            model.ListSelfHost   = GetSetFromSessionSelfHost(null);
            model.ListController = GetSetFromSessionController(null);


            if (obj.isall)
            {
                var customergroups = GetListChild("", obj.customergroupid);

                var list      = _tblCardService.GetAllPagingByFirstForUpload(obj.key, "", obj.cardgroupids, customergroups, "", "", obj.pageIndex, obj.pageSize, obj.accesslevelids, "", "");
                var gridModel = PageModelCustom <tblCardExtend> .GetPage(list, obj.pageIndex, obj.pageSize);

                totalPage = gridModel.TotalPage;
                totalItem = gridModel.TotalItem;
                pageSize  = gridModel.PageSize;

                model.ListCard = gridModel.Data.ToList();
            }
            else
            {
                model.ListCard = GetSetFromSessionCard(null);

                model.ListCard = _tblCardService.GetAllByFirst_v2(model.ListCard);
            }

            var listCustomerId = new List <string>();

            foreach (var item in model.ListCard)
            {
                if (!string.IsNullOrWhiteSpace(item.CustomerId))
                {
                    listCustomerId.Add(item.CustomerId);
                }
            }

            //Danh sách khách hàng
            var ListCustomer = _tblCustomerService.GetAllByListId(listCustomerId);

            if (model.ListCard.Any())
            {
                foreach (var item in model.ListSelfHost)
                {
                    var ko = new AccessUploadMultiDevice()
                    {
                        Address   = item.Address,
                        pageIndex = obj.pageIndex,
                        totalPage = totalPage,
                        totalItem = totalItem,
                        pageSize  = pageSize
                    };

                    var lines = _tblAccessLineService.GetAllActiveByListPC(item.PCID);

                    var ControllerByPC = model.ListController.Where(n => lines.Any(m => m.LineID.ToString() == n.LineID)).ToList();

                    model.ListEmployee = new List <Employee>();

                    //
                    ko.totalItem       = ko.totalItem * ControllerByPC.Count;
                    ko.totalController = ControllerByPC.Count;

                    foreach (var itemCard in model.ListCard)
                    {
                        foreach (var itemController in ControllerByPC)
                        {
                            var map = new Employee();

                            map.CardNumber = itemCard.CardNumber.Trim();

                            map.AccessLevelID = itemCard.AccessLevelID.Trim();

                            map.ControllerIDs = itemController.ControllerID.ToString();

                            map.UserID = user.Id;

                            //Lấy khách hàng
                            if (!string.IsNullOrWhiteSpace(itemCard.CustomerId))
                            {
                                var objCustomer = ListCustomer.FirstOrDefault(n => n.CustomerID.ToString() == itemCard.CustomerId);
                                if (objCustomer != null)
                                {
                                    map.UserIDofFinger = objCustomer.UserIDofFinger;

                                    map.Passwords = objCustomer.Password;
                                }
                                else
                                {
                                    map.UserIDofFinger = 0;

                                    map.Passwords = "";
                                }
                            }
                            else
                            {
                                map.UserIDofFinger = 0;

                                map.Passwords = "";
                            }

                            if (obj.isusenewdate)
                            {
                                map.ExpireDate = Convert.ToDateTime(obj.newdateexpire).ToString("yyyyMMdd").Trim();
                            }
                            else
                            {
                                map.ExpireDate = Convert.ToDateTime(itemCard.AccessExpireDate).ToString("yyyyMMdd").Trim();
                            }

                            model.ListEmployee.Add(map);
                        }
                    }

                    ko.DataSend = model.ListEmployee;

                    dtg.Add(ko);
                }
            }

            //var t = new SelectListModelCardUploadReturn2()
            //{
            //    ListEmployee = model.ListEmployee,
            //    ListSelfHost = model.ListSelfHost
            //};

            //var red = JsonConvert.SerializeObject(t);

            var a = new JsonResult {
                Data = dtg, MaxJsonLength = Int32.MaxValue
            };

            return(a);
        }