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 JsonResult GetDistributorByIdForDisplaying(int _id)
 {
     try
     {
         var distributor = DistributorDB.GetInstance().GetDistributorByIdForDisplaying(_id);
         return(Json(distributor));
     }
     catch (Exception)
     {
         throw;
     }
 }
 public JsonResult DeleteDistributor(int _id)
 {
     try
     {
         DistributorDB.GetInstance().DeleteDistributor(_id);
         return(Json(true));
     }
     catch (Exception)
     {
         throw;
     }
     return(Json(false));
 }
 public IActionResult GetDistributorList(string _bayiAdi)
 {
     try
     {
         _bayiAdi = _bayiAdi == null ? "" : _bayiAdi;
         var distributorList = DistributorDB.GetInstance().GetAllDistributors(userObj, _bayiAdi);
         return(PartialView("_DistributorList", distributorList));
     }
     catch (Exception)
     {
         throw;
     }
 }
        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));
            }
        }
        public JsonResult SaveDistributor(int _id, string _name, int _companyPartnerId, string _entranceDate,
                                          string _exitDate, int _activity, string _phone1, string _phone2, string _fax, string _city, string _personInCharge,
                                          string _code, string _address, string _userCode, string _userPassword, string _userName, string _userSurname, string _userEmail, string _userPhone, int _userId)
        {
            try
            {
                if (_id == 0)
                {
                    var user = new User()
                    {
                        Name       = _userName,
                        Surname    = _userSurname,
                        UserCode   = _userCode,
                        Telephone  = _userPhone,
                        Mail       = _userEmail,
                        Password   = _userPassword,
                        UserTypeId = 2,
                        Status     = 1
                    };

                    UserDB.GetInstance().AddNewUser(user);

                    Distributor distributor = new Distributor()
                    {
                        Name             = _name,
                        UserId           = user.Id,
                        CompanyPartnerId = _companyPartnerId,
                        EntranceDate     = String.IsNullOrEmpty(_entranceDate) ? null : (DateTime?)DateTime.ParseExact(_entranceDate, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                        ExitDate         = String.IsNullOrEmpty(_exitDate) ? null : (DateTime?)DateTime.ParseExact(_entranceDate, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                        Activity         = _activity == 1,
                        Phone1           = _phone1,
                        Phone2           = _phone2,
                        Fax            = _fax,
                        City           = _city,
                        PersonInCharge = _personInCharge,
                        Code           = _code,
                        Address        = _address,
                        CreationDate   = DateTime.Now,
                        Status         = 1
                    };

                    var result = DistributorDB.GetInstance().AddNewDistributor(distributor);
                    return(Json(result != null));
                }
                else
                {
                    var user = UserDB.GetInstance().GetUserById(_userId);
                    user.Name      = _userName;
                    user.Surname   = _userSurname;
                    user.UserCode  = _userCode;
                    user.Mail      = _userEmail;
                    user.Telephone = _userPhone;
                    var isPasswordGoingToBeDifferent = 0;
                    if (user.Password.Trim().ToLower() == _userPassword.Trim().ToLower())
                    {
                        isPasswordGoingToBeDifferent = 0;
                    }
                    if (user.Password.Trim().ToLower() != _userPassword.Trim().ToLower())
                    {
                        user.Password = _userPassword;
                        isPasswordGoingToBeDifferent = 1;
                    }
                    UserDB.GetInstance().UpdateUser(user, isPasswordGoingToBeDifferent);

                    Distributor distributor = new Distributor()
                    {
                        Id               = _id,
                        Name             = _name,
                        CompanyPartnerId = _companyPartnerId,
                        EntranceDate     = String.IsNullOrEmpty(_entranceDate) ? null : (DateTime?)DateTime.ParseExact(_entranceDate, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                        ExitDate         = String.IsNullOrEmpty(_exitDate) ? null : (DateTime?)DateTime.ParseExact(_exitDate, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                        Activity         = _activity == 1,
                        Phone1           = _phone1,
                        Phone2           = _phone2,
                        Fax              = _fax,
                        City             = _city,
                        PersonInCharge   = _personInCharge,
                        Code             = _code,
                        Address          = _address,
                        CreationDate     = DateTime.Now,
                        Status           = 1,
                        UserId           = user.Id
                    };
                    var result = DistributorDB.GetInstance().UpdateDistributor(distributor);
                    return(Json(result != null));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }