Exemplo n.º 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);
        }
        public HttpResponseMessage GetListCustomerWantToUse(CardUploadAPI listUpload)
        {
            //Lấy người dùng hiện tại
            var user = listUpload.CurrentUser;

            var model = new SelectListModelCardUploadReturn();

            model.ListSelfHost = listUpload.ListSelfHost;

            model.ListController = listUpload.ListController;

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

            model.IsUseNewDate = listUpload.ListFilter.isusenewdate;

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

                model.ListCustomer = _tblCustomerService.GetAllByFirst(listUpload.ListFilter.key, "", customergroups, "", "", listUpload.ListFilter.accesslevelids);
            }
            else
            {
                model.ListCustomer = _tblCustomerService.GetAllActiveByListIdForUpload(listUpload.ListCustomerId).ToList();
            }

            if (model.ListCustomer.Any())
            {
                foreach (var itemCustomer in model.ListCustomer)
                {
                    foreach (var itemController in model.ListController)
                    {
                        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.VerifyTypeID = 0;

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

                        model.ListEmployee.Add(map);
                    }
                }
            }

            var content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");

            return(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK, Content = content, RequestMessage = Request
            });
        }