public ActionResult ViewMessage(string id) { var user = GetUserName(); MESSAGE message = new MESSAGE(); HttpClient client = new AccessAPI().Access(); StringContent content = new StringContent(""); HttpResponseMessage response = client.GetAsync(string.Format("api/MESSAGE/GetMESSAGE/{0}", id)).Result; if (response.IsSuccessStatusCode) { message = response.Content.ReadAsAsync <MESSAGE>().Result; if (message.Receiver != "ALL" && message.Receiver != "all" && user.UserName != message.Sender) { HttpResponseMessage response1 = client.PostAsync(string.Format("api/MESSAGE/UpdateIsRead?ID={0}", id), content).Result; bool check = response1.IsSuccessStatusCode; } } HttpResponseMessage response2 = client.GetAsync(string.Format("api/MESSAGETYPE/CountUnreadMessage?MaCode={0}&UserType={1}", user.UserName, user.UserType)).Result; if (response2.IsSuccessStatusCode) { int number = response2.Content.ReadAsAsync <int>().Result; Session.Add(CommonConstants.NUMBER_UNREAD_MESSAGE, number); } return(View(message)); }
public ActionResult Login(LoginModel model) { if (model.UserName == null || model.Password == null) { ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu còn trống. Vui lòng nhập lại !!!"); return(View("Index")); //khong nhat thiet phai co model } List <USER_INFORMATION> list = new List <USER_INFORMATION>(); HttpClient client = new AccessAPI().Access(); StringContent content = new StringContent(""); HttpResponseMessage response = client.PostAsync(string.Format("api/USER_INFORMATION/Search?username={0}&password={1}", model.UserName, Encryptor.MD5Hash(model.Password)), content).Result; if (response.IsSuccessStatusCode) { list = response.Content.ReadAsAsync <List <USER_INFORMATION> >().Result; } if (list.Count == 1) { var userSession = new USER_INFORMATION(); userSession = list[0]; Session.Add(CommonConstants.USER_SESSION, userSession); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không chính xác. Vui lòng xem lại !!!"); return(View("Index")); //khong nhat thiet phai co model } }
public ActionResult Edit() { var model = Session[CommonConstants.USER_SESSION]; //khai báo 1 session bên common giống như bên Cart var temp = new USER_INFORMATION(); if (model != null) { temp = (USER_INFORMATION)model; } HttpClient client = new AccessAPI().Access(); var user = (USER_INFORMATION)Session[CommonConstants.USER_SESSION]; var pass = Session[CommonConstants.HASH_PASSWORD]; StringContent content = new StringContent("username="******"&password="******"&grant_type=password"); HttpResponseMessage res = client.PostAsync(string.Format("api/security/token"), content).Result; TokenModel token = res.Content.ReadAsAsync <TokenModel>().Result; client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + token.access_token); HttpResponseMessage response = client.GetAsync(string.Format("api/AGENT/FindAgent?agentCode={0}", temp.UserName)).Result; var agent = new AGENT(); if (response.IsSuccessStatusCode) { agent = response.Content.ReadAsAsync <AGENT>().Result; //return RedirectToAction("Index", "Home"); } return(View(agent)); }