public IActionResult Index(string query = null)
        {
            var model = new CompaniesViewModel
            {
                Companies = _companyData.GetAll(query),
                Query     = query
            };

            return(View(model));
        }
Exemple #2
0
        public IActionResult Index(string QueryByName, string QueryByAddress, string currentName, string currentAddress)
        {
            //ViewBag.NameSortParm = String.IsNullOrEmpty
            //to do: I have to do something so the search box doesn't clear and remembers the input
            var companies = from c in _companyData.GetAll()
                            select c;

            //companies = companies.OrderBy(c => c.Name);

            if (QueryByName == null)
            {
                QueryByName = currentName;
            }

            if (QueryByAddress == null)
            {
                QueryByAddress = currentAddress;
            }

            ViewBag.CurrentName    = QueryByName;
            ViewBag.CurrentAddress = QueryByAddress;

            if (!string.IsNullOrEmpty(QueryByName) && string.IsNullOrEmpty(QueryByAddress))
            {//search by name
                companies = companies.Where(s => s.Name.ToLowerInvariant().Contains(QueryByName.ToLowerInvariant()));
            }
            else if (string.IsNullOrEmpty(QueryByName) && !string.IsNullOrEmpty(QueryByAddress))
            {//search by adress
                companies = companies.Where(s => s.MainAddress.ToLowerInvariant().Contains(QueryByAddress.ToLowerInvariant()));
            }
            else if (!string.IsNullOrEmpty(QueryByName) && !string.IsNullOrEmpty(QueryByAddress))
            {//search by all
                companies = companies.Where(s => s.Name.ToLowerInvariant().Contains(QueryByName.ToLowerInvariant()) && s.MainAddress.ToLowerInvariant().Contains(QueryByAddress.ToLowerInvariant()));
            }



            companies = companies.OrderBy(c => c.Name);

            return(View(companies));
        }
Exemple #3
0
 public IActionResult Index()
 {
     return(View(_companyData.GetAll()));
 }
Exemple #4
0
        private static async Task SeedUsers(UserManager <User> userManager, ICompanyData companyData)
        {
            var companies = companyData.GetAll(null).ToArray();

            var existingUser = await userManager.FindByNameAsync("Mili");

            if (existingUser == null)
            {
                var user = new User
                {
                    UserName  = "******",
                    CompanyId = companies[0].Id,
                    Email     = "*****@*****.**"
                };

                var userCreateResult = await userManager.CreateAsync(user, Password);

                // TODO: log result
                if (userCreateResult.Succeeded)
                {
                    user = await userManager.FindByNameAsync("Mili");

                    var roleAddResult = await userManager.AddToRoleAsync(user, AuthConstants.AdminRole);

                    // TODO: log result

                    var claimResult = await userManager.AddClaimsAsync(user, new List <Claim>
                    {
                        new Claim(AuthConstants.CompanyClaim, user.CompanyId.ToString())
                    });

                    // TODO: log result

                    claimResult = await userManager.AddClaimsAsync(user, new List <Claim>
                    {
                        new Claim(AuthConstants.UserTypeClaim, AuthConstants.AdministratorClaimType)
                    });

                    // TODO: log result
                }
            }

            existingUser = await userManager.FindByNameAsync("CRoberts");

            if (existingUser == null)
            {
                var user = new User
                {
                    UserName  = "******",
                    CompanyId = companies[1].Id,
                    Email     = "*****@*****.**"
                };

                var userCreateResult = await userManager.CreateAsync(user, Password);

                // TODO: log result
                if (userCreateResult.Succeeded)
                {
                    user = await userManager.FindByNameAsync("CRoberts");

                    var claimResult = await userManager.AddClaimsAsync(user, new List <Claim>
                    {
                        new Claim(AuthConstants.CompanyClaim, user.CompanyId.ToString())
                    });

                    // TODO: log result
                }
            }

            existingUser = await userManager.FindByNameAsync("Gigel");

            if (existingUser == null)
            {
                var user = new User
                {
                    UserName  = "******",
                    CompanyId = companies[0].Id,
                    Email     = "*****@*****.**"
                };

                var userCreateResult = await userManager.CreateAsync(user, Password);

                // TODO: log result
                if (userCreateResult.Succeeded)
                {
                    user = await userManager.FindByNameAsync("Gigel");

                    var claimResult = await userManager.AddClaimsAsync(user, new List <Claim>
                    {
                        new Claim(AuthConstants.CompanyClaim, user.CompanyId.ToString())
                    });

                    // TODO: log result
                }
            }
        }
Exemple #5
0
 public void OnGet()
 {
     Message   = config["Mesage"];
     Companies = companyData.GetAll();
 }