public ActionResult ViewCars(ApplicationUser user) { //// var car = car_context.Cars.ToList(); //var viewModel = new CarAndCustomerViewModel //{ // User = user, // Cars = db.Cars.ToList() //}; //return View(viewModel); IEnumerable <Car> car; HttpResponseMessage response = GlobalVariables.WebApiClient.GetAsync("Car").Result; car = response.Content.ReadAsAsync <IEnumerable <Car> >().Result; var id = HttpContext.User.Identity.GetUserId(); HttpResponseMessage response1 = GlobalVariables.WebApiClient.GetAsync("User/" + id.ToString()).Result; user = response1.Content.ReadAsAsync <ApplicationUser>().Result; var viewModel = new CarAndCustomerViewModel() { User = user, Cars = car }; return(View(viewModel)); }
public ActionResult EditCar(Car car) { // ApplicationUser user = null; //string uri = "https://localhost:44346/api/"; string uri = "https://garageproject20190808114242.azurewebsites.net/api/"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(uri); var responseTask = client.GetAsync("cars?id=" + car.Id); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <Car>(); readTask.Wait(); var viewModel = new CarAndCustomerViewModel() { Cars = readTask.Result, Users = GetUsrById(car.ApplicationUserId), CarBrandDbs = CarBrandList(), CarStyleDbs = CarStyleList() }; return(View(viewModel)); } } return(View()); }
public ActionResult EditCar(Car car) { // ApplicationUser user = null; string uri = "https://localhost:44346/api/"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(uri); var responseTask = client.GetAsync("cars?id=" + car.Id); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <Car>(); readTask.Wait(); var viewModel = new CarAndCustomerViewModel() { Cars = readTask.Result, Users = db.Users.Where(c => c.Id.Equals(car.ApplicationUserId)).SingleOrDefault(), CarBrandDbs = db.CarBrandDbs.ToList(), CarStyleDbs = db.CarStyleDbs.ToList() }; return(View(viewModel)); } } return(View()); }
// User ID is included for Admin but never for user because the user // goes to their car page and does not come from a list of users public async Task <IActionResult> OnGet(string userId = null) { // If the userId is still null the the user is a customer if (userId == null) { // Let's get the user ID - Not sure how this works but gets // the logged in users ID somehow var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); userId = claim.Value; } // Goal is to get a list of the user's cars and to get // the users info and put them in a CarAndCustomerViewModel // object. This is availble to the view. CarAndCustVM = new CarAndCustomerViewModel() { // Get a list where the id in the table equals the id of the login // user that we got right above. Convert the return data set to // a list. Cars = await _db.Car.Where(c => c.UserId == userId).ToListAsync(), // Get the user's data from the User Id we got above. UserObj = await _db.ApplicationUser.FirstOrDefaultAsync(u => u.Id == userId) }; // A way to return back to the page this model is linked to. return(Page()); }
public ActionResult Create(CarAndCustomerViewModel cc) { cc.Car.UserId = cc.User.Id; HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("Car", cc.Car).Result; //TempData["SuccessMessage"] = "Saved Successfully"; return(RedirectToAction("ViewCars", "Car", new { cc.User.Id })); }
public ActionResult Create(ApplicationUser user) { var viewModel = new CarAndCustomerViewModel { User = user }; return(View(viewModel)); }
// Cars public ActionResult ViewDetails(ApplicationUser applicationUser) { var customerDetails = new CarAndCustomerViewModel() { User = _context.Users.SingleOrDefault(c => c.Id == applicationUser.Id), Cars = _context.Cars.ToList() }; return(View(customerDetails)); }
//public ActionResult ViewCar(ApplicationUser user) //{ // var viewModel = new CustomerViewModel() // { // SingleUser = user, // Cars = db.Cars.ToList() // }; // return View(viewModel); //} public ActionResult Create(ApplicationUser user) { var viewModel = new CarAndCustomerViewModel() { Users = user, CarBrandDbs = db.CarBrandDbs.ToList(), CarStyleDbs = db.CarStyleDbs.ToList() }; return(View(viewModel)); }
public ActionResult Index() { string userName = User.Identity.GetUserName(); ApplicationUser user = _context.Users.Where(c => c.UserName.Equals(userName)).SingleOrDefault(); var viewModel = new CarAndCustomerViewModel { User = user, Cars = _context.Cars.ToList() }; return(View(viewModel)); }
// GET: Cars public async Task <IActionResult> Index(string userId = null) { // guest user exclusive userId = (userId == null) ? this.User.FindFirstValue(ClaimTypes.NameIdentifier) : userId; var model = new CarAndCustomerViewModel { Cars = _context.Cars.Where(c => c.UserId == userId), UserObj = await _context.Users.FirstOrDefaultAsync(u => u.Id == userId) }; return(View(model)); }
public async Task <IActionResult> Index(string userId = null) { if (userId == null) { userId = this.User.FindFirstValue((ClaimTypes.NameIdentifier)); // Only used when a guest user logs in } var model = new CarAndCustomerViewModel { Cars = _db.Cars.Where(c => c.UserId == userId), UserObj = _db.Users.FirstOrDefault(u => u.Id == userId) }; return(View(model)); }
public IActionResult Index(string userId = null) { if (userId == null) { //Only Called when a customer logs in userId = User.FindFirstValue(ClaimTypes.NameIdentifier); } var model = new CarAndCustomerViewModel { Cars = _db.Cars.Where(c => c.UserId == userId), UserObj = _db.Users.FirstOrDefault(u => u.Id == userId) }; return(View(model)); }
//get index public async Task <IActionResult> Index(string userID = null) { if (string.IsNullOrWhiteSpace(userID)) { //only if guest userID = User.FindFirstValue(ClaimTypes.NameIdentifier); } var model = new CarAndCustomerViewModel() { Cars = _dbContext.Cars.Where(c => c.UserId == userID).ToList(), User = _dbContext.Users.FirstOrDefault(u => u.Id == userID) }; return(View(model)); }
public async Task <IActionResult> OnGet(string userId = null) { if (userId == null) { var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); userId = claim.Value; } CarAndCustomerVM = new CarAndCustomerViewModel() { Cars = await _db.Car.Where(c => c.UserId == userId).ToListAsync(), UserObj = await _db.ApplicationUser.FirstOrDefaultAsync(u => u.Id == userId) }; return(Page()); }
public async Task <IActionResult> Index(string id = null) { if (string.IsNullOrEmpty(id)) { //only called when guest user sign in id = User.FindFirstValue(ClaimTypes.NameIdentifier); } var model = new CarAndCustomerViewModel { Cars = _db.Cars.Where(c => c.UserId == id), User = _db.Users.FirstOrDefault(u => u.Id == id) }; return(View(model)); }
// GET: Car public ActionResult ViewCars(ApplicationUser user) { HttpResponseMessage response = GlobalVariables.WebApiClient.GetAsync($"APICustomer?id={user.Id}&type=find").Result; var userInDb = response.Content.ReadAsAsync <ApplicationUser>().Result; HttpResponseMessage response1 = GlobalVariables.WebApiClient.GetAsync($"APICar?id={user.Id}&type=whereByUserId").Result; var cars = response1.Content.ReadAsAsync <IEnumerable <Car> >().Result; var viewModel = new CarAndCustomerViewModel { User = userInDb, Cars = cars }; return(View(viewModel)); }
public async Task <IActionResult> Index(string userId = null) { if (userId == null) { //Apenas chamado quando um cliente faz login userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); } var model = new CarAndCustomerViewModel { Cars = _db.Cars.Where(c => c.UserId == userId), UserObj = _db.Users.FirstOrDefault(u => u.Id == userId) }; return(View(model)); }
public async Task <IActionResult> Index(string userId = null) { if (userId == null) { //this will only be called if user is a guest user userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); } var model = new CarAndCustomerViewModel { Cars = _db.Cars.Where(c => c.UserId == userId), UserObj = _db.Users.FirstOrDefault(u => u.Id == userId) }; return(View(model)); }
public async Task <IActionResult> Index(string userId = null) { // user id will be null when customer logs in if (userId == null) { userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); } var model = new CarAndCustomerViewModel { Cars = _db.Cars.Where(u => u.UserId == userId), UserObj = _db.Users.FirstOrDefault(u => u.Id == userId) }; return(View(model)); }
/// <summary> /// Indexes the specified user identifier. /// </summary> /// <param name="userId">The user identifier.</param> /// <returns>Task<IActionResult>.</returns> public async Task <IActionResult> Index(string userId = null) { if (userId == null) { // Only called when a guest user logs in userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); } var model = new CarAndCustomerViewModel() { Cars = await _db.Cars.Where(w => w.UserId == userId).ToListAsync(), UserObj = await _db.Users.Cast <ApplicationUser>().FirstOrDefaultAsync(f => f.Id == userId) }; return(View(model)); }
public async Task <IActionResult> OnGet(string userId = null) { if (userId == null) { var claimsIdentity = (ClaimsIdentity)User.Identity; // eğer user buraya log in oluyorsa user ıd sini claimsten getirmeliyiz.. admin oluyorsa zaten gelecek var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); userId = claim.Value; } CarAndCustVM = new CarAndCustomerViewModel() { Cars = await _db.Car.Where(x => x.UserId == userId).ToListAsync(), // birden fazla araba olabileceği için first and default kullanmadık.. UserObj = await _db.ApplicationUser.FirstOrDefaultAsync(x => x.Id == userId) }; return(Page()); }
public async Task <IActionResult> OnGet(string userId = null) { if (string.IsNullOrEmpty(userId)) { var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); userId = claim.Value; } CarAndCustomerVM = new CarAndCustomerViewModel { UserObj = (ApplicationUser)await _dbContext.Users.FirstOrDefaultAsync(u => u.Id == userId), Cars = _dbContext.Cars.Where(c => c.UserId == userId) }; return(Page()); }
public ActionResult CustomerDetails() { var id = User.Identity.GetUserId(); HttpResponseMessage response = GlobalVariables.WebApiClient.GetAsync($"APICustomer?id={id}&type=find").Result; var user = response.Content.ReadAsAsync <ApplicationUser>().Result; HttpResponseMessage response1 = GlobalVariables.WebApiClient.GetAsync($"APICar?id={id}&type=whereByUserId").Result; var cars = response1.Content.ReadAsAsync <IEnumerable <Car> >().Result; var viewModel = new CarAndCustomerViewModel { User = user, Cars = cars }; return(View("ViewCars", viewModel)); }
public async Task <IActionResult> OnGetAsync(string userId = null) { if (userId == null) { var clamisIdentity = (ClaimsIdentity)User.Identity; //Con el Claim de tipo NameIdentifier se puede obenter el Id de la entidad requerida, en este caso el UserId var claim = clamisIdentity.FindFirst(ClaimTypes.NameIdentifier); userId = claim.Value; } CarAndCustomerVM = new CarAndCustomerViewModel() { Cars = await _context.Cars.Where(c => c.UserId == userId).ToListAsync(), UserObj = await _context.ApplicationUsers.FirstOrDefaultAsync(x => x.Id == userId) }; return(Page()); }
//GET:Car public ActionResult ViewCars(string id) { IEnumerable <Car> car; HttpResponseMessage response = GlobalVariables.WebApiClient.GetAsync("Car").Result; car = response.Content.ReadAsAsync <IEnumerable <Car> >().Result; //var id = HttpContext.User.Identity.GetUserId(); HttpResponseMessage response1 = GlobalVariables.WebApiClient.GetAsync("User/" + id).Result; var user = response1.Content.ReadAsAsync <ApplicationUser>().Result; var viewModel = new CarAndCustomerViewModel() { User = user, Cars = car }; return(View(viewModel)); }
public ActionResult Create(CarAndCustomerViewModel viewModel) { viewModel.Cars.ApplicationUserId = viewModel.Users.Id; if (!ModelState.IsValid) { return(View()); } else { var car = viewModel.Cars; var user = GetUsr(viewModel.Users.Id); using (var client = new HttpClient()) { //client.BaseAddress = new Uri("https://localhost:44346/api/cars"); client.BaseAddress = new Uri("https://garageproject20190808114242.azurewebsites.net/api/cars"); //HTTP POST JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter(); var postTask = client.PostAsync("cars", car, formatter); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { if (HttpContext.User.IsInRole("admin")) { return(RedirectToAction("ViewCar", "Vehicle", user)); } else { return(RedirectToAction("IndexUser", "User")); } } } } // ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); return(View()); }
public ActionResult EditCar(CarAndCustomerViewModel car) { var user = db.Users.Find(car.Users.Id); string uri = "https://localhost:44346/api/"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(uri); JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter(); //HTTP POST var putTask = client.PutAsync <Car>("cars", car.Cars, formatter); //PutAsJsonAsync<Customer>("customers", customer); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("ViewCar", user)); } } return(View()); }
public ActionResult IndexUser() { //string email = User.Identity.GetUserName(); string uid = User.Identity.GetUserName(); string uri = "https://localhost:44346/api/"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(uri); var viewModel1 = new CarAndCustomerViewModel(); var responseTask = client.GetAsync("customers?username="******"cars"); responseTask1.Wait(); var result1 = responseTask1.Result; JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter(); if (result1.IsSuccessStatusCode) { var readTask = result1.Content.ReadAsAsync <IEnumerable <Car> >(); readTask.Wait(); viewModel1.UserCar = readTask.Result.Where(c => c.ApplicationUserId.Equals(viewModel1.Users.Id)).ToList(); } viewModel1.CarBrandDbs = database.CarBrandDbs.ToList(); viewModel1.CarStyleDbs = database.CarStyleDbs.ToList(); return(View(viewModel1)); } }
public ApplicationUser GetUsrById(string uid) { string uri = "https://garageproject20190808114242.azurewebsites.net/api/"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(uri); var viewModel1 = new CarAndCustomerViewModel(); var responseTask = client.GetAsync("customers?id=" + uid.ToString()); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <ApplicationUser>(); readTask.Wait(); return(readTask.Result); } } return(null); }
public ActionResult IndexUser() { //string email = User.Identity.GetUserName(); string uid = User.Identity.GetUserId(); //string uri = "https://localhost:44346/api/"; string uri = "https://garageproject20190808114242.azurewebsites.net/api/"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(uri); var viewModel1 = new CarAndCustomerViewModel(); var responseTask = client.GetAsync("customers/" + uid.ToString()); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <ApplicationUser>(); readTask.Wait(); viewModel1.Users = readTask.Result; } var responseTask1 = client.GetAsync("cars"); responseTask1.Wait(); var result1 = responseTask1.Result; JsonMediaTypeFormatter formatter = new JsonMediaTypeFormatter(); if (result1.IsSuccessStatusCode) { var readTask = result1.Content.ReadAsAsync <IEnumerable <Car> >(); readTask.Wait(); viewModel1.UserCar = readTask.Result.Where(c => c.ApplicationUserId.Equals(viewModel1.Users.Id)).ToList(); } using (var brndClient = new HttpClient()) { brndClient.BaseAddress = new Uri(uri); var responseTaskBrnd = brndClient.GetAsync("AddBrands"); responseTaskBrnd.Wait(); var resultBrnd = responseTaskBrnd.Result; if (resultBrnd.IsSuccessStatusCode) { var readbrnd = resultBrnd.Content.ReadAsAsync <IEnumerable <CarBrandDb> >(); readbrnd.Wait(); viewModel1.CarBrandDbs = readbrnd.Result; } } using (var styleClient = new HttpClient()) { styleClient.BaseAddress = new Uri(uri); var responseTaskStyle = styleClient.GetAsync("AddStyles"); responseTaskStyle.Wait(); var resultStyl = responseTaskStyle.Result; if (resultStyl.IsSuccessStatusCode) { var readStyle = resultStyl.Content.ReadAsAsync <IEnumerable <CarStyleDb> >(); readStyle.Wait(); viewModel1.CarStyleDbs = readStyle.Result; } return(View(viewModel1)); } } }