Exemple #1
0
        public ActionResult ShowMikrotikUserByMikrotikIDForSynchronize(int MikrotikID)
        {
            // Initialization.
            JsonResult result = new JsonResult();

            try
            {
                Mikrotik mikrotik = db.Mikrotik.Find(MikrotikID);

                ITikConnection connection;
                ITikCommand    userCmd;
                ITikCommand    PackageCmd;
                try
                {
                    List <MikrotikUserList> lstMikrotikUserList = new List <MikrotikUserList>();
                    connection = ConnectionFactory.OpenConnection(TikConnectionType.Api, mikrotik.RealIP, mikrotik.MikUserName, mikrotik.MikPassword);//mikrotik.APIPort,

                    List <MikrotikUserList>      lstUserFromMikrotik    = MikrotikLB.GetUserListFromMikrotik(connection, mikrotik);
                    List <MikrotikUserList>      lstActiveUserList      = MikrotikLB.GetActiveUserListFromMikrotik(connection, mikrotik);
                    IEnumerable <ITikReSentence> lstPackageFromMikrotik = MikrotikLB.GetPackageListFromMikrotik(connection);

                    List <string> lstUserFromSystem = db.ClientDetails.Select(x => x.LoginName).ToList();
                    lstUserFromMikrotik = lstUserFromMikrotik.Where(z => !lstUserFromSystem.Contains(z.UserName)).ToList();
                    return(Json(new { Success = true, lstUserFromMikrotik = lstUserFromMikrotik, MikrotikConnectionFailed = true }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { Success = false, MikrotikConnectionFailed = true }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                // Info
                Console.Write(ex);
            }
            // Return info.
            return(result);
        }
Exemple #2
0
        public ActionResult GetAllMikrotikUserAJAXData()
        {
            // Initialization.
            JsonResult result = new JsonResult();

            try
            {
                int zoneFromDDL = 0;
                // Initialization.
                string search     = Request.Form.GetValues("search[value]")[0];
                string draw       = Request.Form.GetValues("draw")[0];
                string order      = Request.Form.GetValues("order[0][column]")[0];
                string orderDir   = Request.Form.GetValues("order[0][dir]")[0];
                int    startRec   = Convert.ToInt32(Request.Form.GetValues("start")[0]);
                int    pageSize   = Convert.ToInt32(Request.Form.GetValues("length")[0]);
                var    Mikrotik   = Request.Form.Get("lstMikrotiks");
                int    MikrotikID = 0;
                if (!String.IsNullOrEmpty(Mikrotik))
                {
                    MikrotikID = int.Parse(Mikrotik);
                }
                // Loading.

                Mikrotik mikrotik = db.Mikrotik.Find(MikrotikID);

                ITikConnection connection;
                ITikCommand    userCmd;
                ITikCommand    PackageCmd;
                try
                {
                    List <MikrotikUserList> lstMikrotikUserList = new List <MikrotikUserList>();
                    connection = ConnectionFactory.OpenConnection(TikConnectionType.Api, mikrotik.RealIP, mikrotik.MikUserName, mikrotik.MikPassword);//mikrotik.APIPort,

                    List <MikrotikUserList>      lstUserFromMikrotik    = MikrotikLB.GetUserListFromMikrotik(connection, mikrotik);
                    List <MikrotikUserList>      lstActiveUserList      = MikrotikLB.GetActiveUserListFromMikrotik(connection, mikrotik);
                    IEnumerable <ITikReSentence> lstPackageFromMikrotik = MikrotikLB.GetPackageListFromMikrotik(connection);

                    //userCmd.ExecuteList();
                    //var a = MikrotikLB.GetUserListFromMikrotik(userCmd);

                    //PackageCmd = connection.CreateCommand("/ppp/profile/print");
                    //IEnumerable<ITikReSentence> lstPackageFromMikrotik = PackageCmd.ExecuteList();


                    List <string> lstUserFromSystem = db.ClientDetails.Select(x => x.LoginName).ToList();
                    lstUserFromMikrotik = lstUserFromMikrotik.Where(z => !lstUserFromSystem.Contains(z.UserName)).ToList();
                    //s => lstStockDetailsListFromClient.Contains(s.StockDetailsID)
                    return(Json(new { Success = true, lstUserFromMikrotik = lstUserFromMikrotik, MikrotikConnectionFailed = true }, JsonRequestBehavior.AllowGet));
                }
                catch (Exception ex)
                {
                    return(Json(new { Success = false, MikrotikConnectionFailed = true }, JsonRequestBehavior.AllowGet));
                }


                //// Apply pagination.
                ////data = data.Skip(startRec).Take(pageSize).ToList();
                //var clientDetails = !string.IsNullOrEmpty(Mikrotik) ? db.ClientDetails.Where(s => s.MikrotikID.Value == MikrotikID && s.IsNewClient != AppUtils.isNewClient).AsEnumerable() : db.ClientDetails.Where(s => s.IsNewClient != AppUtils.isNewClient).AsEnumerable();

                //int ifSearch = 0;
                //if (!string.IsNullOrEmpty(search) &&
                //    !string.IsNullOrWhiteSpace(search))
                //{

                //    ifSearch = (clientDetails.Any()) ? clientDetails.Where(p => p.Name.ToString().ToLower().Contains(search.ToLower()) || p.Package.PackageName.ToString().ToLower().Contains(search.ToLower()) ||
                //                                              p.Zone.ZoneName.ToString().ToLower().Contains(search.ToLower()) || p.ContactNumber.ToString().ToLower().Contains(search.ToLower()) ||
                //                                              p.LoginName.ToString().ToLower().Contains(search.ToLower())).Count() : 0;

                //    //Apply search
                //    clientDetails = clientDetails.Where(p => p.Name.ToString().ToLower().Contains(search.ToLower()) || p.Package.PackageName.ToString().ToLower().Contains(search.ToLower()) ||
                //                                             p.Zone.ZoneName.ToString().ToLower().Contains(search.ToLower()) || p.ContactNumber.ToString().ToLower().Contains(search.ToLower()) ||
                //                                             p.LoginName.ToString().ToLower().Contains(search.ToLower())

                //    ).AsEnumerable();
                //}
                //List<MikrotikUserCutomModel> data =
                //    clientDetails.Any() ? clientDetails.Skip(startRec).Take(pageSize).AsEnumerable()
                //        //.Select new {ss=>ss. }
                //        .Select(
                //            s => new MikrotikUserCutomModel
                //            {
                //                ClientDetailsID = s.ClientDetailsID,
                //                MikrotikID = (s.Mikrotik != null) ? s.MikrotikID.Value : 0,
                //                ClientName = s.Name,
                //                LoginName = s.LoginName.ToString(),
                //                PackageName = s.Package.PackageName,
                //                Zone = s.Zone.ZoneName,
                //                ContactNumber = s.ContactNumber,
                //                MikrotikName = (s.Mikrotik != null) ? s.Mikrotik.MikName : "",
                //                LocalAddress = s.Package.LocalAddress,
                //                PoolName = s.Package.IpPool != null ? s.Package.IpPool.PoolName : "",
                //                UpdateMikrotikUserInformation = ISP_ManagementSystemModel.AppUtils.HasAccessInTheList(ISP_ManagementSystemModel.AppUtils.Update_Client) ? true : false,
                //            })
                //        .ToList() : new List<MikrotikUserCutomModel>();
                //// Verification.

                //// Sorting.
                //data = this.SortByColumnWithOrder(order, orderDir, data);
                //// Total record count.
                //int totalRecords = clientDetails.AsEnumerable().Count();//(!string.IsNullOrEmpty(search) &&  !string.IsNullOrWhiteSpace(search))? data.AsEnumerable().Count():
                //// Filter record count.
                //int recFilter = (!string.IsNullOrEmpty(search) && !string.IsNullOrWhiteSpace(search)) ? ifSearch : clientDetails.AsEnumerable().Count();

                //////////////////////////////////////


                //// Loading drop down lists.
                //result = this.Json(new
                //{
                //    draw = Convert.ToInt32(draw),
                //    recordsTotal = totalRecords,
                //    recordsFiltered = recFilter,
                //    data = data
                //}, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                // Info
                Console.Write(ex);
            }
            // Return info.
            return(result);
        }