public IActionResult Index()
        {
            var model = new DistributorViewModel()
            {
                Distributors = DistributorDB.GetInstance().GetAllDistributors(userObj),
                //Companies = CompanyDB.GetInstance().GetCompanyList(userObj),
                CompanyPartners = CompanyPartnerDB.GetInstance().GetAllCompanyPartners()
            };

            return(View(model));
        }
        public IActionResult Index()
        {
            //CompanyList = CompanyDB.Instance.GetCompanyList(),
            var returnModel = new CompanyViewModel()
            {
                CompanyTypeList = CompanyTypeDB.GetInstance().GetAllCompanyTypes(),
                CompanyList     = CompanyDB.GetInstance().GetAllCompaniesForAdminPanel(userObj),
                Platforms       = PlatformDB.GetInstance().GetAllPlatforms(),
                Sectors         = SectorDB.GetInstance().GetAllSectors(),
                /*Users = UserDB.GetInstance().GetAllUsers(),*/
                Distributors    = DistributorDB.GetInstance().GetAllDistributors(userObj),
                CompanyPartners = CompanyPartnerDB.GetInstance().GetAllCompanyPartners()
            };

            return(View(returnModel));
        }
        public JsonResult ImportFile(string _excelData)
        {
            _excelData = HttpUtility.HtmlDecode(_excelData);
            var list2 = JsonConvert.DeserializeObject <List <CompanyExcelObject> >(_excelData);

            try
            {
                foreach (var item in list2)
                {
                    Company company = new Company()
                    {
                        CompanyCode        = item.SirketKodu,
                        CompanyDescription = item.SirketKodu,
                        MobileCount        = item.MobilSayisi,
                        Address1           = item.Adres1,
                        Address2           = item.Adres2,
                        Phone             = item.Telefon,
                        Fax               = item.Fax,
                        PersonInCharge    = item.YetkiliKisi,
                        CompanyPartnerId  = !string.IsNullOrEmpty(item.IsOrtagi) ? CompanyPartnerDB.GetInstance().GetCompanyPartnerByNameOrInsert(item.IsOrtagi).Id : 0,
                        DistributorId     = DistributorDB.GetInstance().GetDistributorIdByName(item.BayiAdi),
                        PlatformId        = !string.IsNullOrEmpty(item.Platform) ? PlatformDB.GetInstance().GetPlatformByNameOrInsert(item.Platform).Id : 0,
                        SectorId          = !string.IsNullOrEmpty(item.Sektor) ? SectorDB.GetInstance().GetSectorByNameOrInsert(item.Sektor).Id : 0,
                        LoginUrl          = item.LoginUrl,
                        BaseMap           = item.BaseMap,
                        TechnicalReport   = item.TeknikRapor == "Aktif" ? true : false,
                        TaxAdministration = item.VergiDairesi,
                        TaxNumber         = item.VergiNo,
                        EntranceDate      = GetExcelDateTime(item.GirisZamani),
                        ExitDate          = GetExcelDateTime(item.CikisZamani),
                        AlarmSms          = item.AlarmSms == "Aktif" ? true : false,
                        PasswordControl   = item.SifreKontrol == "Aktif" ? true : false,
                        InfoSense         = item.InfoSense == "Aktif" ? true : false,
                        AccountingCode    = item.MuhasebeHesKodu,
                        Status            = 1,
                        CompanyStatus     = true,
                        CreationDate      = DateTime.Now,
                        UserStatus        = true
                    };
                    var  companyAdmin = ConvertToEngStandarts(company.CompanyCode);
                    bool isUserExist  = UserDB.GetInstance().CheckIfUserExist(companyAdmin);
                    if (isUserExist)
                    {
                        continue;
                    }
                    CompanyDB.GetInstance().AddNewCompany(company);
                    if (!isUserExist)
                    {
                        if (companyAdmin != "")
                        {
                            User user = new User()
                            {
                                UserTypeId = 1,
                                UserCode   = companyAdmin,
                                Password   = "******",
                                Status     = 1
                            };
                            UserDB.GetInstance().AddNewUser(user);
                            CompanyUser companyUser = new CompanyUser()
                            {
                                CompanyId      = company.Id,
                                IsCompanyAdmin = true,
                                Status         = 1,
                                UserId         = user.Id
                            };
                            CompanyUserDB.GetInstance().AddNewCompanyUser(companyUser);
                        }
                    }
                }
                return(Json(true));
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
        public JsonResult UploadFile(IFormFile file)
        {
            if (file == null)
            {
                return(Json(false));
            }

            if (file.FileName.EndsWith(".xlsx") || file.FileName.EndsWith(".xls"))
            {
                var fileName = Path.Combine(_env.WebRootPath, "Content", "TempUploads", Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName));

                try
                {
                    using (var fileStream = new FileStream(fileName, FileMode.Create))
                    {
                        var task = file.CopyToAsync(fileStream);
                        task.Wait();
                    }

                    Workbook workbook = new Workbook();
                    workbook.LoadFromFile(fileName);
                    Worksheet sheet = workbook.Worksheets[0];
                    var       dt    = sheet.ExportDataTable();

                    foreach (DataRow dr in dt.Rows)
                    {
                        var companyCode        = dr["Şirket Kodu"].ToString();
                        var companyDescription = dr["Şirket"].ToString().Trim();
                        var mobileCount        = dr["Mobil Sayısı"].ToString().Trim();
                        var address1           = dr["Adres 1"].ToString().Trim();
                        var address2           = dr["Adres 2"].ToString().Trim();
                        var phone             = dr["Telefon"].ToString().Trim();
                        var fax               = dr["Fax"].ToString().Trim();
                        var personInCharge    = dr["Yetkili Kişi"].ToString().Trim();
                        var companyPartner    = dr["İş Ortağı"].ToString().Trim();
                        var distributorName   = dr["Bayi Adı"].ToString().Trim();
                        var platform          = dr["Platform"].ToString().Trim();
                        var sector            = dr["Sektör"].ToString().Trim();
                        var loginUrl          = dr["Login Url"].ToString().Trim();
                        var baseMap           = dr["BaseMap"].ToString().Trim();
                        var technicalReport   = dr["Teknik Rapor"].ToString().Trim();
                        var companyStatus     = dr["Kullanım Durumu"].ToString().Trim();
                        var taxAdministration = dr["Vergi Dairesi"].ToString().Trim();
                        var taxNumber         = dr["Vergi No"].ToString().Trim();
                        var entranceDate      = dr["Giriş Zamanı"].ToString().Trim();
                        var exitDate          = dr["Çıkış Zamanı"].ToString().Trim();
                        var alarmSms          = dr["Alarm Sms"].ToString().Trim();
                        var passwordControl   = dr["Şifre Kontrol"].ToString().Trim();
                        var infoSense         = dr["InfoSense"].ToString().Trim();
                        var accountingCode    = dr["Muhasebe Hes Kodu"].ToString().Trim();


                        //USER INFORMATİONSS NEEDED???????????


                        var company = new Company()
                        {
                            CompanyCode        = companyCode,
                            CompanyDescription = companyDescription,
                            MobileCount        = Convert.ToInt32(mobileCount),
                            Address1           = address1,
                            Address2           = address2,
                            Phone = phone,
                            Fax   = fax,
                            //PersonInCharge = personInCharge, //buradaki yetkili kişi userdaki yetkili kişi ??
                            CompanyPartnerId  = CompanyPartnerDB.GetInstance().GetCompanyPartnerByNameOrInsert(companyPartner).Id,
                            DistributorId     = DistributorDB.GetInstance().GetDistributorIdByName(distributorName),
                            PlatformId        = PlatformDB.GetInstance().GetPlatformByNameOrInsert(platform).Id,
                            SectorId          = SectorDB.GetInstance().GetSectorByNameOrInsert(sector).Id,
                            LoginUrl          = loginUrl,
                            BaseMap           = baseMap,
                            TechnicalReport   = technicalReport == "Aktif" ? true : false,
                            CompanyStatus     = companyStatus == "Aktif" ? true : false,
                            TaxAdministration = taxAdministration,
                            TaxNumber         = taxNumber,
                            EntranceDate      = GetExcelDateTime(entranceDate),
                            ExitDate          = GetExcelDateTime(exitDate),
                            AlarmSms          = alarmSms == "Aktif" ? true : false,
                            PasswordControl   = passwordControl == "Aktif" ? true : false,
                            InfoSense         = infoSense == "Aktif" ? true : false,
                            AccountingCode    = accountingCode
                        };

                        var result = CompanyDB.GetInstance().AddNewCompany(company);
                    }

                    if (System.IO.File.Exists(fileName))
                    {
                        System.IO.File.Delete(fileName);
                    }

                    return(Json(true));
                }
                catch (Exception exc)
                {
                    if (System.IO.File.Exists(fileName))
                    {
                        System.IO.File.Delete(fileName);
                    }

                    return(Json(exc.Message));
                }
            }

            else
            {
                return(Json(false));
            }
        }