public string InitializeCart() { // TODO // check session expiration // currently this just returns true // needs time check in session utility if (_session.IsValid()) { if (!_cart.NeedACart()) // kind of a double negative but checks session for cart-id { return(_session.GetSession("cart")); } if (_cart.MakeNewCart().Result == true) // hit when starting new session { IPAddress ip = Request.HttpContext.Connection.LocalIpAddress; var details = new SessionLog() // log the session information { cart_id = _session.GetSession("cart"), session_id = _session.CurrentSession(), client_ip = ip.ToString() }; _log.Session(details); return(details.cart_id); // return with the cart id } // TODO error creating the new cart } var error = "you messed up"; // error in session. figure out how to reset return(error); }
private QueryLog CreateLog(string method) { return(new QueryLog() { cart_id = _sess.GetSession("cart"), method = method, parameters = new List <string>(), succeeded = false, return_count = 0 }); }
public string GetCart() { return(_session.GetSession("cart")); }
private object GetMenuList() { object result = null; try { //session.SetSession("sesUserName", "admin"); if (session.GetSession("sesUserName") != null) { string sesUserName = session.GetSession("sesUserName").ToString(); HttpClient client = new HttpClient(); string baseUrl = Url.Action("", "", null, HttpContext.Request.Scheme); client.BaseAddress = new Uri(baseUrl); var textUser = client.GetStringAsync("api/UserApi/GetList").Result; var resultUser = JsonConvert.DeserializeObject <List <UserEntity.User> >(textUser); var textRole = client.GetStringAsync("api/RoleApi/GetList").Result; var resultRole = JsonConvert.DeserializeObject <List <RoleEntity.Role> >(textRole); string userId = ""; string roleId = ""; string fullname = ""; string roleName = ""; userId = resultUser.Where(x => x.UserName.ToLower() == sesUserName.ToLower()).FirstOrDefault().ID.ToString(); roleId = resultUser.Where(x => x.UserName.ToLower() == sesUserName.ToLower()).FirstOrDefault().IDRole.ToString(); roleName = resultRole.Where(x => x.ID == Convert.ToInt16(roleId)).FirstOrDefault().RoleName; fullname = resultUser.Where(x => x.UserName.ToLower() == sesUserName.ToLower()).FirstOrDefault().Fullname; // Get Name into Header ViewData["vdHeaderName"] = fullname; // Kartu List var textKartu = client.GetStringAsync("api/KartuApi/GetList").Result; var resultKartu = JsonConvert.DeserializeObject <List <KartuEntity.Kartu> >(textKartu); ViewData["vdKartuList"] = resultKartu; // Select Menu By Role Id MenuRepository menu = new MenuRepository(context, hosting, session); IEnumerable <MenuEntity.Menu> list = menu.GetListMenuByRole(Convert.ToInt16(roleId)); result = list; } else { ViewData["vdHeaderName"] = null; GetLogoutIfSessionNull(); result = null; } } catch (Exception ex) { Log.WriteLog(ex.Message, hosting); } return(result); }
public ActionResult GetLogin(string userName, string password) { object result = null; // Select Login By User and Password HttpClient client = new HttpClient(); string baseUrl = Url.Action("", "", null, HttpContext.Request.Scheme); client.BaseAddress = new Uri(baseUrl); var text = client.GetStringAsync("api/UserApi/GetList").Result; var resultUser = JsonConvert.DeserializeObject <List <UserEntity.User> >(text); try { if (ModelState.IsValid) { string hashPassword = Functions.HashPasswordSha256(password); int countLoginAll = 0; int countLoginActive = 0; int countIsLogin = 0; countLoginAll = resultUser.Where(x => x.UserName.ToLower() == userName.ToLower().Trim() && x.Password == hashPassword.Trim()).Count(); countLoginActive = resultUser.Where(x => x.UserName.ToLower() == userName.ToLower().Trim() && x.Password == hashPassword.Trim() && x.IsActive == true).Count(); countIsLogin = resultUser.Where(x => x.UserName.ToLower() == userName.ToLower().Trim() && x.Password == hashPassword.Trim() && x.IsActive == true && x.IsLogin == true).Count(); // If password not null if (countLoginAll > 0) { if (countIsLogin == 0) { // If User is active if (countLoginActive > 0) { session.SetSession("sesUserName", userName); session.SetCookies("cookieUserName", userName); string sesUserName = session.GetSession("sesUserName").ToString(); result = new { error = 0 }; } else { result = new { error = 3 } }; } else { result = new { error = 2 } }; } else { result = new { error = 1 } }; } } catch (Exception ex) { Log.WriteLog(ex.Message, hosting); } return(Json(result)); }