public IActionResult Index() { HomeViewModel model = new HomeViewModel(); var cmd = new tuletContext(); var lease = cmd.Post.Where(x => x.Category == "Lease").OrderByDescending(o => o.Id).Take(4).ToList(); var rent = cmd.Post.Where(x => x.Category == "Rent").OrderByDescending(o => o.Id).Take(4).ToList(); var sale = cmd.Post.Where(x => x.Category == "Sale").OrderByDescending(o => o.Id).Take(4).ToList(); foreach (var item in lease) { item.User = cmd.User.SingleOrDefault(x => x.Email == item.UserId); } foreach (var item in rent) { item.User = cmd.User.SingleOrDefault(x => x.Email == item.UserId); } foreach (var item in sale) { item.User = cmd.User.SingleOrDefault(x => x.Email == item.UserId); } model.Sale = sale; model.Rent = rent; model.Lease = lease; return(View(model)); }
public async Task <IActionResult> Category(String Name) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var cmd = new tuletContext(); var vm = new Category { Name = Name }; if (!String.IsNullOrEmpty(Name)) { cmd.Category.Add(vm); cmd.SaveChanges(); var model = cmd.Category.ToList().OrderBy(x => x.Id); return(View(model)); } return(RedirectToAction("Category")); }
public IActionResult Post(int id) { var cmd = new tuletContext(); var model = cmd.Post.SingleOrDefault(x => x.Id == id); model.User = cmd.User.SingleOrDefault(x => x.Email == model.UserId); //model.CategoryNavigation.Post = cmd.Post.Where(x => x.Category == model.Category).ToList(); return(View(model)); }
public IActionResult Agent(string id, int pageIndex = 1) { int PageIndex = pageIndex; var cmd = new tuletContext(); var model = cmd.User.SingleOrDefault(x => x.Email == id); var post = cmd.Post.Where(x => x.UserId == id).ToList(); model.Post = PaginatedList <Post> .Create(post, PageIndex, 12); return(View(model)); }
public async Task <IActionResult> Post() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var cmd = new tuletContext(); List <Post> posts = cmd.Post.OrderBy(x => x.Id).ToList(); return(View(posts)); }
public async Task <IActionResult> Agent(string id) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var cmd = new tuletContext(); List <User> agents = cmd.User.Where(x => x.FirstName.Contains(id) || x.LastName.Contains(id) || x.Email.Contains(id)).OrderBy(x => x.FirstName).ToList(); return(View(agents)); }
public async Task <IActionResult> Post(string id) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var cmd = new tuletContext(); List <Post> posts = cmd.Post.Where(x => x.Title.Contains(id) || x.Description.Contains(id) || x.Category.Contains(id) || x.Type.Contains(id)).OrderBy(x => x.Id).ToList(); return(View(posts)); }
public async Task <IActionResult> Type() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var cmd = new tuletContext(); var model = cmd.Type.ToList().OrderBy(x => x.Id); return(View(model)); }
public async Task <IActionResult> AgentInfo(string id) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var cmd = new tuletContext(); User agent = cmd.User.SingleOrDefault(x => x.Email == id); agent.Post = cmd.Post.Where(x => x.UserId == agent.Email).Take(4).OrderByDescending(x => x.PostDate).ThenByDescending(x => x.Id).ToList(); return(View("AgentInfo", agent)); }
public async Task <IActionResult> DeActivateAgent(string id) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var cmd = new tuletContext(); var agent = cmd.User.SingleOrDefault(x => x.Email == id); agent.Active = false; cmd.SaveChanges(); return(RedirectToAction("Agent")); }
public async Task <IActionResult> DeletePost(int id) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var cmd = new tuletContext(); Post post = cmd.Post.SingleOrDefault(x => x.Id == id); cmd.Post.Remove(post); cmd.SaveChanges(); return(RedirectToAction("Post")); }
public async Task <IActionResult> PostInfo(int id) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var cmd = new tuletContext(); Post post = cmd.Post.SingleOrDefault(x => x.Id == id); post.User = cmd.User.SingleOrDefault(x => x.Email == post.UserId); if (cmd.Post.Count(x => x.Id != id) > 0) { post.User.Post = cmd.Post.Where(x => x.UserId == post.UserId && x.Id != id).Take(4).ToList(); } return(View(post)); }
public IActionResult Lease() { int PageIndex = 1; var cmd = new tuletContext(); var result = cmd.Post.Where(x => x.Category == "Lease").ToList(); var model = PaginatedList <Post> .Create(result, PageIndex, 12).ToList(); foreach (var item in model) { item.User = cmd.User.SingleOrDefault(x => x.Email == item.UserId); } ViewData["Title"] = "Search results for Tulet9ja Lease"; var page = new PaginatedList <Post>(model, model.Count(), PageIndex, 12); ViewBag.Next = page.hasNext ? "" : "disabled"; ViewBag.Previous = page.hasPrevious ? "" : "disabled"; return(View("Search", model)); }
public async Task <IActionResult> Post() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var cmd = new tuletContext(); var model = new PostViewModel { StatusMessage = StatusMessage, Categories = cmd.Category.Select(x => new SelectListItem { Value = x.Name, Text = x.Name }).ToList(), Types = cmd.Type.Select(x => new SelectListItem { Value = x.Name, Text = x.Name }).ToList() }; return(View(model)); }
public async Task <IActionResult> Profile() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var db = new tuletContext(); var email = user.Email; var u_model = db.User.SingleOrDefault(x => x.Email == email); if (u_model != null) { var i_model = new UserViewModel { FirstName = u_model.FirstName, LastName = u_model.LastName, Address = u_model.Address, Phone = u_model.Phone, BirthDate = u_model.BirthDate, StatusMessage = StatusMessage, PhotoUrl = u_model.Photo }; ViewBag.img = u_model.Photo; return(View(i_model)); } var model = new UserViewModel { StatusMessage = StatusMessage, PhotoUrl = "/images/avatar_default.png" }; return(View(model)); }
public AdminNavViewComponent() { ddb = new tuletContext(); }
public GlobalNavViewComponent() { db = new tuletContext(); }
public async Task <IActionResult> Post(PostViewModel vm) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } tuletContext cmd = new tuletContext(); var appUser = cmd.User.SingleOrDefault(x => x.Email == user.Email); if (appUser.Active == false) { StatusMessage = "Post was not uploaded..! Please Update your Profile or Contact Support"; return(RedirectToAction("Index")); } if (!ModelState.IsValid || String.IsNullOrEmpty(vm.Type) || String.IsNullOrEmpty(vm.Category) || String.IsNullOrEmpty(vm.State)) { vm.StatusMessage = "Please fill out the form correctly"; return(View(vm)); } if (vm.Photo1 == null || vm.Photo1.Length == 0) { vm.StatusMessage = "You have not added a photo"; return(View(vm)); } Post post = new Post { UserId = user.Email, Title = vm.Title, Category = vm.Category, Type = vm.Type, Price = vm.Price, Negotiable = vm.Negotiable, State = vm.State, Location = vm.Location, Photo1 = "default", Description = vm.Description, PostDate = DateTime.Now.Date }; cmd.Post.Add(post); cmd.SaveChanges(); var targetFileName = $"{post.Id}one{System.IO.Path.GetExtension(vm.Photo1.FileName)}"; var relativeFilePath = Path.Combine("images", "post", targetFileName); var absolutFilePath = Path.Combine(_environment.WebRootPath, relativeFilePath); using (var stream = new FileStream(absolutFilePath, FileMode.Create)) { vm.Photo1.CopyTo(stream); post.Photo1 = relativeFilePath; } if (vm.Photo2 != null && vm.Photo2.Length != 0) { var targetFileName1 = $"{post.Id}two{System.IO.Path.GetExtension(vm.Photo2.FileName)}"; var relativeFilePath1 = Path.Combine("images", "post", targetFileName1); var absolutFilePath1 = Path.Combine(_environment.WebRootPath, relativeFilePath1); using (var stream = new FileStream(absolutFilePath1, FileMode.Create)) { vm.Photo2.CopyTo(stream); post.Photo2 = relativeFilePath1; } } if (vm.Photo3 != null && vm.Photo3.Length != 0) { var targetFileName2 = $"{post.Id}three{System.IO.Path.GetExtension(vm.Photo3.FileName)}"; var relativeFilePath2 = Path.Combine("images", "post", targetFileName2); var absolutFilePath2 = Path.Combine(_environment.WebRootPath, relativeFilePath2); using (var stream = new FileStream(absolutFilePath2, FileMode.Create)) { vm.Photo3.CopyTo(stream); post.Photo3 = relativeFilePath2; } } cmd.SaveChanges(); StatusMessage = "Your post have been uploaded successfully!"; return(RedirectToAction("Post")); }
public async Task <IActionResult> Profile(UserViewModel vm) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } if (ModelState.IsValid) { var db = new tuletContext(); var email = user.Email; var userId = user.Id; vm.StatusMessage = ""; if (vm.Photo == null || vm.Photo.Length == 0) { vm.StatusMessage = "You have not added a photo"; return(View(vm)); } else if (vm.Photo.Length > 1048576) { vm.StatusMessage = "File to upload is bigger than 1mb"; return(View(vm)); } var targetFileName = $"{email}{System.IO.Path.GetExtension(vm.Photo.FileName)}"; var relativeFilePath = Path.Combine("images", "profile", targetFileName); var absolutFilePath = Path.Combine(_environment.WebRootPath, relativeFilePath); using (var stream = new FileStream(absolutFilePath, FileMode.Create)) { vm.Photo.CopyTo(stream); } User e_user = new User(); e_user = db.User.SingleOrDefault(e => e.Email == email); if (e_user != null) { e_user.FirstName = vm.FirstName; e_user.LastName = vm.LastName; e_user.Address = vm.Address; e_user.BirthDate = vm.BirthDate; e_user.Phone = vm.Phone; e_user.Photo = relativeFilePath; db.User.Update(e_user); await db.SaveChangesAsync(); StatusMessage = "Your Profile has been Updated successfully"; return(RedirectToAction(nameof(Index))); } var n_user = new User { UserId = userId, Email = email, FirstName = vm.FirstName, LastName = vm.LastName, Address = vm.Address, BirthDate = vm.BirthDate, Phone = vm.Phone, Verified = false, Active = true, Photo = relativeFilePath, RegDate = DateTime.Today }; db.User.Add(n_user); await db.SaveChangesAsync(); StatusMessage = "Your Profile has been Updated successfully"; return(RedirectToAction(nameof(Index))); } return(View(vm)); }