public PermissionDetail GetPermission(string userCode = null) { PermissionDetail permission = null; using (var db = new InternetAccountEntities()) { try { if (string.IsNullOrEmpty(userCode)) { var x = HttpContext.Current.User as CustomPrincipal; if (x != null) { userCode = x.UserCode; } } var group = (from t1 in db.Users join t2 in db.MasUserGroup on t1.UserGroupCode equals t2.Code where t1.UserCode == userCode select t2.AccessAreaCode).FirstOrDefault(); var province = new List <string>(); if (group != null) { if (group.Contains("00")) { province = db.Areas.Select(c => c.AreaCode).ToList(); } else { province = group.Split(',').ToList(); } } else { province = (from t1 in db.Users join t2 in db.Branches on t1.BranchCode equals t2.BranchCode join t3 in db.Areas on t2.AreaCode equals t3.AreaCode where t1.UserCode == userCode where t1.Disable == false select t3.AreaCode).ToList(); } var per = (from t1 in db.Users join t2 in db.MasUserGroupPermissions on t1.UserGroupCode equals t2.UserGroupCode where t1.UserCode == userCode select t2.PermissionCode).ToList(); permission = new PermissionDetail() { Province = province, Permission = per }; } catch (Exception ex) { Log.Error(this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " Error -> " + ex.Message); } } return(permission); }
public ActionResult Logout() { using (var db = new InternetAccountEntities()) { if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.User.Identity.Name)) { var user = new Authen().GetUserLogon(); if (user != null) { db.UserOnlines.Where(r => r.UserId == user.UserId).ToList().ForEach(r => db.UserOnlines.Remove(r)); db.SaveChanges(); } } } if (Request.Cookies[FormsAuthentication.FormsCookieName + "SINET"] != null) { var c = new HttpCookie(FormsAuthentication.FormsCookieName + "SINET"); c.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(c); } FormsAuthentication.SignOut(); System.Web.HttpContext.Current.Session.RemoveAll(); return(Redirect(this.MainUrl)); }
public ActionResult Index() { try { var permission = UserPermission; using (var db = new InternetAccountEntities()) { var area = db.Areas.Where(r => permission.Province.Contains(r.AreaCode)).ToList(); ViewBag.Area = area; var thailand = new Thailand(db); var province = thailand.GetAllProvince(); string selectProvince = (area != null ? area[0].AreaName : province[0].ProvinceName); if (!province.Exists(p => p.ProvinceName == selectProvince)) { selectProvince = province[0].ProvinceName; } if (province.Count > 0) { var amphur = thailand.GetAllAmphurs(selectProvince); var district = thailand.GetAllDistricts(selectProvince, amphur[0].AmphurName); ViewData["_Province"] = province.Select(p => new DropdownEntity { Id = p.ProvinceCode.ToString(), Name = p.ProvinceName, Selected = (p.ProvinceName == selectProvince ? true : false) }).ToList(); ViewData["_Amphur"] = amphur.Select(p => new DropdownEntity { Id = p.AmphurName, Name = p.AmphurName }).ToList(); ViewData["_District"] = district.Select(p => new DropdownEntity { Id = p.DistrictName, Name = p.DistrictName }).ToList(); ViewData["_Zipcode"] = thailand.GetZipcode(selectProvince, amphur[0].AmphurName, district[0].DistrictName) .ToString(); } } } catch (Exception ex) { Log.Error(this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " Error -> " + ex.Message); } return(View()); }
public ActionResult Index() { try { var permission = UserPermission; using (var db = new InternetAccountEntities()) { var area = db.Areas.Where(r => permission.Province.Contains(r.AreaCode)).ToList(); ViewBag.Area = area; } } catch (Exception ex) { Log.Error(this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " Error -> " + ex.Message); } return(View()); }
public UserLogon GetUserLogon() { UserLogon user = null; using (var db = new InternetAccountEntities()) { var x = HttpContext.Current.User as CustomPrincipal; string str = ""; if (x != null) { str = x.UserCode; } //string str = System.Web.HttpContext.Current.User.Identity.Name; if (!string.IsNullOrEmpty(str)) { try { var entity = db.Users.FirstOrDefault(r => r.UserCode == str); if (entity != null) { var role = db.MasUserGroup.FirstOrDefault(r => r.Code == entity.UserGroupCode); if (role != null) { var branch = db.Branches.FirstOrDefault(c => c.BranchCode == entity.BranchCode); user = new UserLogon() { UserCode = entity.UserCode, Username = entity.Username, FirstName = entity.FirstName, LastName = entity.LastName, LastLogin = entity.LastLogin, LastChangePassword = entity.LastChangePassword, Disable = entity.Disable, Default = entity.Default, UserGroupCode = entity.UserGroupCode, BranchCode = entity.BranchCode, Branches = branch, BranchId = branch != null ? branch.id : 0 }; if (string.IsNullOrEmpty(role.AccessAreaCode)) { user.AccessAreaCode = new List <string>() { user.Branches.AreaCode }; } else if (role.AccessAreaCode == "00") { user.AccessAreaCode = db.Areas.Select(r => r.AreaCode).ToList(); } else { user.AccessAreaCode = role.AccessAreaCode.Split(',').ToList(); } //user.PermissionCode = db.MasUserGroupPermissions.Where(r => r.UserGroupCode == entity.UserGroupCode).Select(r => r.PermissionCode).ToList(); user.UserId = entity.UserId; user.UserCode = entity.UserCode; user.Username = entity.Username; user.RoleId = entity.RoleId; user.FirstName = entity.FirstName; user.LastName = entity.LastName; user.EmailAddress = entity.EmailAddress; user.PhoneNo = entity.PhoneNo; user.Photo = entity.PhoneNo; user.BranchId = entity.BranchId; user.Branches = db.Branches.FirstOrDefault(r => r.BranchCode == entity.BranchCode); user.BranchCode = entity.BranchCode; user.Default = entity.Default; user.Disable = entity.Disable; user.LastLogin = entity.LastLogin; user.LastChangePassword = entity.LastChangePassword; user.EnableSetting = entity.EnableSetting; user.UserGroupCode = entity.UserGroupCode; } } } catch (Exception ex) { Log.Error(this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " Error -> " + ex.Message); } } } return(user); }
public Thailand(InternetAccountEntities databaseContext) { this.db = databaseContext; }