public async Task <IActionResult> Index() { var idList = new List <int>(); var phones = new List <PhoneDto>(); if (HttpContext.Session.TryGetValue(_constants.SessionIdListKey, out var data)) { var json = HttpContext.Session.GetString(_constants.SessionIdListKey); idList = JsonConvert.DeserializeObject <List <int> >(json); var response = await _client.PostAsync <List <PhoneDto>, List <int> >(idList, $"/api/purchase/phones"); if (response.IsSuccessStatusCode) { phones = response.Result; } } var model = new BucketViewModel { Phones = phones }; return(LayoutView(model)); }
public async Task <IActionResult> Register(SignInViewModel model) { HttpClient client = new HttpClient(); var userData = new UserDto { Login = model.Login, Password = model.Password, FirstName = model.FristName, LastName = model.LastName, UserKind = model.IsAdmin ? "Admin" : "Buyer" }; var response = await _client.PostAsync <Response <string>, UserDto>(userData, $"/api/account/registration"); if (response.IsSuccessStatusCode) { var dataResponse = response.Result; if (dataResponse.Data != null) { HttpContext.Session.SetString(_constants.SessionTokenKey, dataResponse.Data); HttpContext.Session.SetString(_constants.SessionUserKey, dataResponse.UserName); return(RedirectToRoute(new { controller = "Home", action = "Index" })); } } return(RedirectToAction("Index")); }
public async Task <IActionResult> Edit(PhoneDto editedPhone) { if (!HttpContext.Session.TryGetValue(_constants.SessionTokenKey, out var token)) { return(RedirectToRoute(new { controller = "LoginForm", action = "Index" })); } var response = await _client.PostAsync <Response <bool>, PhoneDto>(editedPhone, $"/api/purchase/updatePhone", HttpContext.Session.GetString(_constants.SessionTokenKey)); if (response.IsSuccessStatusCode) { var dataResponse = response.Result; } return(RedirectToAction("EditPhone", editedPhone)); }
public async Task <IActionResult> Edit(ProfileViewModel model) { if (!HttpContext.Session.TryGetValue(_constants.SessionTokenKey, out var token)) { return(RedirectToRoute(new { controller = "LoginForm", action = "Index" })); } var user = new UserDto { Login = model.Login, Password = model.Password, FirstName = model.FirstName, LastName = model.LastName, Cash = model.Cash }; var response = await _client.PostAsync <Response <string>, UserDto>(user, $"/api/account/update", HttpContext.Session.GetString(_constants.SessionTokenKey)); if (response.IsSuccessStatusCode) { var dataResponse = response.Result; if (dataResponse.Data != null) { HttpContext.Session.SetString(_constants.SessionTokenKey, dataResponse.Data); HttpContext.Session.SetString(_constants.SessionUserKey, dataResponse.UserName); return(RedirectToAction("ShowProfile")); } } return(RedirectToAction("EditProfile")); }
public async Task <IActionResult> Login(LoginViewModel model) { var userData = new UserDto { Login = model.Login, Password = model.Password, }; var response = await _client.PostAsync <Response <string>, UserDto>(userData, $"/api/account/authorize"); if (response.IsSuccessStatusCode) { var dataResponse = response.Result; if (dataResponse.Data != null) { HttpContext.Session.SetString(_constants.SessionTokenKey, dataResponse.Data); HttpContext.Session.SetString(_constants.SessionUserKey, dataResponse.UserName); return(RedirectToRoute(new { controller = "Home", action = "Index" })); } } return(RedirectToAction("Index")); }