public async Task <IActionResult> Create([Bind("PropertyId,PropertyName,Bedroom,IsAvaliable,SalePrice,LeasePrice")] Property @property) { try { if (ModelState.IsValid) { if (_user == null) { _user = await _userManager.GetUserAsync(User); } @property.UserId = _user.UserName; _context.Add(@property); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(@property)); } catch (Exception ex) { _logger.LogError(ex.ToString()); return(View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier })); } }
// only dispaly user his/her data // admin can see all data public async Task <IActionResult> Index() { try { if (_user == null) { _user = await _userManager.GetUserAsync(User); } if (_user != null) { if (_user.IsAdmin) { return(View(await _context.Property.ToListAsync())); } else { return(View(await _context.Property.Where(x => x.UserId == _user.UserName).ToListAsync())); } } else { return(RedirectToAction("Index", "Home")); } } catch (Exception ex) { _logger.LogError(ex.ToString()); return(RedirectToAction("Index", "Home")); } }
public async Task <IActionResult> Edit(int?id) { try { if (id == null) { return(NotFound()); } var transaction = await _context.Transaction.FindAsync(id); if (transaction == null) { return(NotFound()); } if (_user == null) { _user = await _userManager.GetUserAsync(User); } List <Property> listofProperty = new List <Property>(); listofProperty = (_context.Property.Where(x => x.IsAvaliable == true && ((x.UserId == _user.UserName) || _user.IsAdmin == true)).ToList()); listofProperty.Insert(0, new Property { PropertyId = 0, PropertyName = "select" }); ViewBag.ListofavailableProduct = listofProperty; ViewBag.SelectedProperty = transaction.PropertyId; var model = new TransactionVM() { transaction = new Transaction() { UserId = transaction.UserId, property = new Property() { PropertyId = transaction.PropertyId }, PropertyId = transaction.PropertyId, TransactionDate = transaction.TransactionDate, TransactionId = transaction.TransactionId } }; return(View(model)); } catch (Exception ex) { _logger.LogError(ex.ToString()); return(View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier })); } }
private async Task LoadAsync(OkayAssignmentUser user) { var userName = await _userManager.GetUserNameAsync(user); var phoneNumber = await _userManager.GetPhoneNumberAsync(user); Username = userName; Input = new InputModel { PhoneNumber = phoneNumber }; }
public async Task <IActionResult> Create([Bind("TransactionId,PropertyId,UserId,TransactionDate,transaction,property")] TransactionVM _transactionVM) { try { if (_user == null) { _user = await _userManager.GetUserAsync(User); } if (_transactionVM.transaction.PropertyId == 0) { ModelState.AddModelError("", "Please select Property"); } if (ModelState.IsValid) { if (_transactionVM != null) { var _transaction = new Transaction { PropertyId = _transactionVM.transaction.PropertyId, TransactionDate = _transactionVM.transaction.TransactionDate, TransactionId = _transactionVM.transaction.TransactionId, UserId = _transactionVM.transaction.UserId }; _context.Add(_transaction); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } else { List <Property> listofProperty = new List <Property>(); listofProperty = (_context.Property.Where(x => x.IsAvaliable == true && ((x.UserId == _user.UserName) || _user.IsAdmin == true)).ToList()); listofProperty.Insert(0, new Property { PropertyId = 0, PropertyName = "select" }); ViewBag.ListofavailableProduct = listofProperty; } return(View(_transactionVM)); } catch (Exception ex) { _logger.LogError(ex.ToString()); return(View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier })); } }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = new OkayAssignmentUser { UserName = Input.Email, Email = Input.Email, IsAdmin = Input.IsAdmin }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); if (_userManager.Options.SignIn.RequireConfirmedAccount) { return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl })); } else { await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IActionResult> Details(int?id) { try { if (id == null) { return(NotFound()); } var transaction = await _context.Transaction .FirstOrDefaultAsync(m => m.TransactionId == id); if (transaction == null) { return(NotFound()); } if (_user == null) { _user = await _userManager.GetUserAsync(User); } var model = new TransactionVM() { transaction = new Transaction() { UserId = transaction.UserId, PropertyId = transaction.PropertyId, property = transaction.property, TransactionDate = transaction.TransactionDate, TransactionId = transaction.TransactionId } }; return(View(model)); } catch (Exception ex) { _logger.LogError(ex.ToString()); return(View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier })); } }
public async Task <IActionResult> Create() { try { if (_user == null) { _user = await _userManager.GetUserAsync(User); } var model = new TransactionVM() { transaction = new Transaction() { UserId = _user.UserName, property = new Property(), TransactionDate = System.DateTime.Now, TransactionId = 0 } }; List <Property> listofProperty = new List <Property>(); listofProperty = (_context.Property.Where(x => x.IsAvaliable == true && ((x.UserId == _user.UserName) || _user.IsAdmin == true)).ToList()); listofProperty.Insert(0, new Property { PropertyId = 0, PropertyName = "select" }); ViewBag.ListofavailableProduct = listofProperty; ViewBag.TransactionDatetime = System.DateTime.Now.ToString(); return(View(model)); } catch (Exception ex) { _logger.LogError(ex.ToString()); return(View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier })); } }
public async Task <IActionResult> Index() { try { if (_user == null) { _user = await _userManager.GetUserAsync(User); } IQueryable <TransactionVM> _transactionvm; if (_user != null) { if (_user.IsAdmin) { _transactionvm = _context.Transaction.Include(x => x.property).Select(y => new TransactionVM { transaction = y, propertyid = y.property.PropertyId }); } else { _transactionvm = _context.Transaction.Include(x => x.property).Where(z => z.UserId == _user.UserName).Select(y => new TransactionVM { transaction = y, propertyid = y.property.PropertyId }); } } else { return(RedirectToAction("Index", "Home")); } return(View(await _transactionvm.ToListAsync())); } catch (Exception ex) { _logger.LogError(ex.ToString()); return(RedirectToAction("Index", "Home")); } }