public async Task <IActionResult> Index() { var user = await _userManager.GetUserAsync(User); Users currentUser = new Users(); if (user != null) { currentUser = user; var currentProfile = db.Profile.FirstOrDefault(p => p.UsersId == currentUser.Id); if (currentProfile.Disabled) { return(RedirectToAction("Ban", new { currentProfile.id })); } } else { currentUser = null; } var model = new PortSearchVM() { Portfolios = db.Portfolio.Where(p => p.Profile.Disabled == false).ToList(), Users = db.Users.ToList(), CurrentUser = currentUser, PortfolioImages = db.PortfolioImages.ToList(), Profiles = db.Profile.Where(p => p.Disabled == false).ToList() }; bool isAjaxCall = Request.Headers["x-requested-with"] == "XMLHttpRequest"; if (isAjaxCall) { return(PartialView("_indexPortfolio", model)); } else { return(View(model)); } }
// Sorting portfolio public async Task <IActionResult> GetPorts(string sort) { var currentUser = await _userManager.GetUserAsync(User); List <Portfolio> Portfolios = new List <Portfolio>(); switch (sort) { case "all": Portfolios = db.Portfolio.Where(p => p.Profile.Disabled == false).ToList(); break; case "topview": Portfolios = db.Portfolio.Where(p => p.Profile.Disabled == false).OrderByDescending(p => p.View).ToList(); break; case "design": Portfolios = db.Portfolio.Where(p => p.Profile.Disabled == false).Where(p => p.Type.Contains("design")).ToList(); break; case "web": Portfolios = db.Portfolio.Where(p => p.Profile.Disabled == false).Where(p => p.Type.Contains("web")).ToList(); break; } var model = new PortSearchVM() { Portfolios = Portfolios, Users = db.Users.ToList(), CurrentUser = currentUser, PortfolioImages = db.PortfolioImages.ToList(), Profiles = db.Profile.Where(p => p.Disabled == false).ToList() }; return(PartialView("_indexPortfolio", model)); }
public async Task <IActionResult> GetByName(string type, string text) { string searctTxt = text.ToLower(); if (type == "cv") { List <Cv> cvList = new List <Cv>(); List <Profile> profList = new List <Profile>(); List <Users> usersList = new List <Users>(); var findedUsers = db.Users.Where(u => u.Name.ToLower().Contains(searctTxt) || u.Surname.ToLower().Contains(searctTxt) || u.Email.ToLower().Contains(searctTxt)).ToList(); foreach (var item in findedUsers) { var profile = db.Profile.FirstOrDefault(p => p.UsersId == item.Id); if (profile.Disabled == false) { cvList.Add(db.Cv.FirstOrDefault(c => c.ProfileId == profile.id)); profList.Add(profile); usersList.Add(item); } } var model = new CvSearch() { Cvs = cvList, Skills = db.Position.ToList(), Users = usersList, Profiles = profList }; return(PartialView("_indexCv", model)); } else if (type == "person") { List <Profile> profiles = new List <Profile>(); List <Users> userList = new List <Users>(); var users = db.Users.Where(u => u.Name.ToLower().Contains(searctTxt) || u.Surname.ToLower().Contains(searctTxt) || u.Email.ToLower().Contains(searctTxt)).ToList(); foreach (var user in users) { var prof = db.Profile.FirstOrDefault(p => p.UsersId == user.Id); if (prof.Disabled == false) { profiles.Add(prof); userList.Add(user); } } var userModel = new PersonSearchVM() { Users = users, Profiles = profiles }; return(PartialView("_indexPerson", userModel)); } else if (type == "port") { var portList = db.Portfolio.Where(p => p.Name.ToLower().Contains(searctTxt) && p.Profile.Disabled == false).ToList(); var portModel = new PortSearchVM() { Portfolios = portList, Users = db.Users.ToList(), CurrentUser = await _userManager.GetUserAsync(User), PortfolioImages = db.PortfolioImages.ToList(), Profiles = db.Profile.Where(p => p.Disabled == false).ToList() }; return(PartialView("_indexPortfolio", portModel)); } else { return(Json(new { error = "Netice tapilmadi" })); } }