public ActionResult Index() { HttpResponseMessage result; result = WebApiRequestOperation.WebApiRequestOperationMethodForUser(SystemConstannts.WebApiDomainAddress, "api/Product/ProductList", new { user = ((User)HttpContext.Session["User"]) }); return(View()); }
public ActionResult LoginUser(User user) { if (ModelState.IsValid) { HttpResponseMessage result = WebApiRequestOperation.WebApiRequestOperationMethodForUser( SystemConstannts.WebApiDomainAddress, "api/Account/Login", new User { Password = Security.sha512encrypt(user.Password).Substring(0, 70), Email = user.Email, }); /* HttpClient client = new HttpClient(); * client.BaseAddress = new Uri(SystemConstannts.WebApiDomainAddress); * client.DefaultRequestHeaders.Add("apiKey", "AHMET"); * /* HttpResponseMessage result = client.PostAsJsonAsync("api/Account/Login", new User * { * Password = Security.sha512encrypt(user.Password).Substring(0, 70), * Email = user.Email, * }).Result;*/ if (result.StatusCode == HttpStatusCode.OK) { string resultString = result.Content.ReadAsStringAsync().Result; if (resultString != "{\"Token\":null}") { LoginResponse login = Newtonsoft.Json.JsonConvert.DeserializeObject <LoginResponse>(resultString); if (login.Code == 1) { HttpCookie httpCookie = new HttpCookie("userAuth", login.Token.TokenValue); httpCookie.Expires = login.Token.ExpireDate; HttpContext.Response.Cookies.Add(httpCookie); HttpContext.Session["User"] = login.Token.User; return(RedirectToAction("Index", "Home")); } TempData["SystemMessage"] = login.Message; HttpContext.Session["User"] = null; return(RedirectToAction("Login")); } HttpContext.Session["User"] = null; return(RedirectToAction("Login")); } TempData["SystemMessage"] = "Sistem Hatası"; HttpContext.Session["User"] = null; return(RedirectToAction("Login")); } HttpContext.Session["User"] = null; return(RedirectToAction("Login")); }
public ActionResult AddProduct() { ViewBag.PageInfo = "ÜRÜN EKLE"; ProductAddModel addModel = new ProductAddModel(); HttpResponseMessage result; result = WebApiRequestOperation.WebApiRequestOperationMethodForUser(SystemConstannts.WebApiDomainAddress, "api/Category/GetCategories", null); if (result.StatusCode == HttpStatusCode.OK) { string resultString = result.Content.ReadAsStringAsync().Result; if (resultString != "{\"Categories\":null}") { GetCategoryListResponse getCategory = Newtonsoft.Json.JsonConvert.DeserializeObject <GetCategoryListResponse>(resultString); if (getCategory.Code == 1) { addModel.Categories = getCategory.Categories; } else { addModel.Categories = null; } } } result = WebApiRequestOperation.WebApiRequestOperationMethodForUser(SystemConstannts.WebApiDomainAddress, "api/Brand/GetBrands", null); if (result.StatusCode == HttpStatusCode.OK) { string resultString = result.Content.ReadAsStringAsync().Result; if (resultString != "{\"Brands\":null}") { GetBrandListResponse getBrand = Newtonsoft.Json.JsonConvert.DeserializeObject <GetBrandListResponse>(resultString); if (getBrand.Code == 1) { addModel.Brands = getBrand.Brands; } else { addModel.Brands = null; } } } addModel.Product = null; return(View(addModel)); }
public ActionResult MyProducts() { if (LoginControl.ControlLogin() != null) { ViewBag.PageInfo = "ÜRÜNLERİM"; HttpResponseMessage result = WebApiRequestOperation.WebApiRequestOperationMethodForUser(SystemConstannts.WebApiDomainAddress, "api/UserProfile/GetMyProducts", (HttpContext.Session["User"] as Takas.Common.Entities.Concrete.User)); GetUserProductResponse response = null; if (result.StatusCode == HttpStatusCode.OK) { string resultString = result.Content.ReadAsStringAsync().Result; if (!resultString.Contains("{\"Products\":null")) { response = Newtonsoft.Json.JsonConvert.DeserializeObject <GetUserProductResponse>(resultString); } } return(View(response)); } return(View("NotFound")); }
public ActionResult SignUpUser(User user) { if (ModelState.IsValid) { user.AccountActiveDate = DateTime.Now; user.AccountCreateDate = DateTime.Now; user.Password = Security.sha512encrypt(user.Password).Substring(0, 70); user.Image = ""; user.isActive = false; user.isBlocked = false; user.ValidationKey = RandomSfr.Generate(10); user.WrongCount = 0; user.RoleID = 1; HttpResponseMessage result = WebApiRequestOperation.WebApiRequestOperationMethodForUser(SystemConstannts.WebApiDomainAddress, "api/Account/SignUp", user); //HttpClient client = new HttpClient(); //client.BaseAddress = new Uri("http://localhost:2765/"); //HttpResponseMessage result = WebApiRequestOperation.WebApiRequestOperationMethodForUser(SystemConstannts.WebApiDomainAddress, // "api/Account/SignUp", user); if (result.StatusCode == HttpStatusCode.OK) { string resultString = result.Content.ReadAsStringAsync().Result; if (resultString.Contains("true")) { return(RedirectToAction("Login", "Account")); } else { return(RedirectToAction("SignUp", "Account", user)); } } } return(RedirectToAction("SignUp", "Account", user)); }