public async Task <dynamic> EnterNewRecordLoad([FromBody] dynamic settings) { try { var settingConfig = System.Web.Helpers.Json.Decode(settings.ToString()); var serverName = settingConfig.serverName; var cpuLoad = ((string)settingConfig.cpuLoad).ToNullableDouble() ?? 0; var ramLoad = ((string)settingConfig.ramLoad).ToNullableDouble() ?? 0; var memHelper = new MemoryCacheHelper(); _loadRecords = await memHelper.GetValue("LoadRecords") as List <LoadRecord> ?? new List <LoadRecord>(); var newRecord = new LoadRecord { CpuLoad = cpuLoad, RamLoad = ramLoad, ServerName = serverName, TimeStamp = DateTimeOffset.UtcNow }; _loadRecords.Add(newRecord); await memHelper.Add("LoadRecords", _loadRecords, DateTimeOffset.UtcNow.AddYears(1)); return(new { Success = true, Message = string.Empty }); } catch (Exception exception) { return(new { Success = false, Message = $"Failed to record load. {exception.Message}" }); } }
public ResultData GetCaptcha() { ResultData oResultData = new ResultData(); try { string capcha = ""; Bitmap bm = MT.Library.CommonFunction.CreateCapcha(ref capcha); MemoryCacheHelper.Add(Commonkey.Capcha, capcha, DateTimeOffset.Now.AddMinutes(5)); using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { bm.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); byte[] imageBytes = stream.ToArray(); string base64String = Convert.ToBase64String(imageBytes); oResultData.Data = base64String; } } catch (Exception ex) { oResultData.SetError(ex); } return(oResultData); }
public ActionResult SampleData(int id, Int64 FeedMappingID, string jsonFileName) { if (FeedMappingID > 0) { string contentRootPath = _hostingEnvironment.ContentRootPath; var rootFilePath = string.Concat(contentRootPath, "/", Settings.FeedJSONFilePath); JToken jToken = null; if (!string.IsNullOrEmpty(jsonFileName)) { dynamic data = null; using (StreamReader r = new StreamReader(Path.Combine(rootFilePath, jsonFileName))) { string json = r.ReadToEnd(); data = JsonConvert.DeserializeObject <dynamic>(json); } jToken = data as JToken; } if (jToken != null) { //DbCall getFeed var lstFeedSampleData = new List <FeedSampleData>(); var oResult = MemoryCacheHelper.GetValue("GetSampleData_" + id); if (oResult == null) { lstFeedSampleData = FilterRuleHelper.GetSampleData(id); MemoryCacheHelper.Add("GetSampleData_" + id, lstFeedSampleData, DateTimeOffset.UtcNow.AddHours(1)); } else { lstFeedSampleData = oResult as List <FeedSampleData>; } string jsonPath = lstFeedSampleData.FirstOrDefault(x => x.ID == FeedMappingID).ActualFeedKeyPath; if (!string.IsNullOrEmpty(jsonPath)) { jsonPath = jsonPath.Substring(jsonPath.LastIndexOf(']') + 1); var jValue = jToken.Root.SelectTokens("$." + jsonPath).FirstOrDefault(); if (jValue != null) { var val = jValue.Value <object>(); return(Content( JsonConvert.SerializeObject(val, Formatting.Indented) , "application/json")); } else { return(Content(JsonConvert.SerializeObject("", Formatting.Indented), "application/json")); } } else { return(Content( JsonConvert.SerializeObject("", Formatting.Indented) , "application/json")); } } } return(Json("")); }
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) { if (actionExecutedContext.ActionContext.Request.Method == HttpMethod.Get && actionExecutedContext.Response.IsSuccessStatusCode) { MemoryCacheHelper.Add(cacheKey, actionExecutedContext.Response, DateTimeOffset.UtcNow.AddHours(cacheHours)); } }
public async Task <dynamic> GetLoadData([FromBody] dynamic settings) { try { var settingConfig = System.Web.Helpers.Json.Decode(settings.ToString()); var serverName = settingConfig.serverName; var memHelper = new MemoryCacheHelper(); _loadRecords = await memHelper.GetValue("LoadRecords") as List <LoadRecord>; if (_loadRecords == null || _loadRecords.Count <= 0) { _loadRecords = await GenerateTestData(); //new List<LoadRecord>(); await memHelper.Add("LoadRecords", _loadRecords, DateTimeOffset.UtcNow.AddYears(1)); } var serverRecords = _loadRecords.Where(record => record.ServerName == serverName && record.TimeStamp >= DateTimeOffset.UtcNow.Subtract(new TimeSpan(1, 0, 0, 0))).ToList(); var serverAverageHourLoad = serverRecords.Where( record => record.TimeStamp >= DateTimeOffset.UtcNow.Subtract(new TimeSpan(1, 0, 0))) .GroupBy(record => new { TimeKey = record.TimeStamp.ToString("HH:mm") }) .Select( group => new { CpuLoad = group.Average(p => p.CpuLoad), RamLoad = group.Average(p => p.RamLoad), group.First().ServerName, group.Key.TimeKey }).OrderBy(list => list.TimeKey); var serverAverageDayLoad = serverRecords.GroupBy( record => new { TimeKey = record.TimeStamp.ToString("MM/dd/yyyy HH:00") }) .Select( group => new { CpuLoad = group.Average(p => p.CpuLoad), RamLoad = group.Average(p => p.RamLoad), group.First().ServerName, group.Key.TimeKey }).OrderBy(list => list.TimeKey); return(new { HourReport = serverAverageHourLoad, DayReport = serverAverageDayLoad }); //return new { Success = true, Message = string.Empty }; } catch { return(new { Success = false, Message = "Failed to record load." }); } }
public ActionResult GetAllActivities() { var oRequestCode = new Random().Next(0, int.MaxValue); var oRequestTime = DateTime.Now; LogHelper.InsertServiceLogs("search/allactivities (GetAllActivities) (" + oRequestCode + ")", null, oRequestTime); var activities = new List <string>(); var oResult = MemoryCacheHelper.GetValue("GetAllActivities"); if (oResult == null) { activities = FeedHelper.GetAllActivities(); MemoryCacheHelper.Add("GetAllActivities", activities, DateTimeOffset.UtcNow.AddHours(2)); } else { activities = oResult as List <string>; } LogHelper.InsertServiceLogs("search/allactivities (GetAllActivities) - Response (" + oRequestCode + ")", null, oRequestTime, DateTime.Now); return(Ok(new { items = activities })); }
private bool CheckAccessTokenValidity(string accessToken) { bool IsAuthorized = false; try { #region Allow same access token by pass added 01-04-2019 var oCacheKey = string.Concat("AccessToken_", accessToken); var oResult = MemoryCacheHelper.GetValue(oCacheKey); if (oResult != null && (string)oResult == accessToken) { return(true); } #endregion var lstSqlParameter = new List <SqlParameter>(); lstSqlParameter.Add(new SqlParameter() { ParameterName = "@AccessToken", SqlDbType = SqlDbType.NVarChar, Value = (object)accessToken ?? DBNull.Value }); var dt = DBProvider.GetDataTable("AccessToken_Authorize", CommandType.StoredProcedure, ref lstSqlParameter); if (dt != null && dt.Rows.Count > 0) { if (dt.Rows[0]["IsAuthorized"] != DBNull.Value) { MemoryCacheHelper.Add(oCacheKey, accessToken, DateTimeOffset.UtcNow.AddDays(1)); IsAuthorized = Convert.ToBoolean(dt.Rows[0]["IsAuthorized"]); } } } catch (Exception ex) { LogHelper.InsertErrorLogs("[DataLaundryApi] AuthorizationHandler", "CheckAccessTokenValid", ex.Message, ex.InnerException?.Message, ex.StackTrace); } return(IsAuthorized); }
public async Task <HttpResponseMessage> GetAll(HttpRequestMessage request, string filter = "") { return(await CreateHttpResponse(request, () => { HttpResponseMessage response = null; IEnumerable <Function> model = null; var cacheFunctions = MemoryCacheHelper.GetValue("function"); if (cacheFunctions != null) { model = (IEnumerable <Function>)cacheFunctions; } else { MemoryCacheHelper.Add("function", _functionService.GetAll(filter), DateTimeOffset.MaxValue); model = _functionService.GetAll(filter); } IEnumerable <FunctionViewModel> modelVm = Mapper.Map <IEnumerable <Function>, IEnumerable <FunctionViewModel> >(model); response = request.CreateResponse(HttpStatusCode.OK, modelVm); return response; })); }
public ActionResult GetActivities(double?lat, double?lng, double?radius, [FromQuery] string[] source, [FromQuery] string[] kind, [FromQuery] string[] tag, [FromQuery] string[] excludeTag, [FromQuery] string[] disabilitySupport, [FromQuery] string[] weekdays, string gender = null, double?minCost = null, double?maxCost = null, string from = null, string to = null, long?minTime = null, long?maxTime = null, long?minAge = null, long?maxAge = null) { #region Variable declaration or assignment lat = lat ?? defaultLatitude; lng = lng ?? defaultLongitude; radius = radius ?? defaultRadius; string sources = null; string kinds = null; string tags = null; string excludeTags = null; string disabilitySupports = null; string days = null; if (source.Length > 0) { sources = string.Join(",", source); } if (kind.Length > 0) { kinds = string.Join(",", kind); } if (tag.Length > 0) { tags = string.Join(",", tag); } if (excludeTag.Length > 0) { excludeTags = string.Join(",", excludeTag); } if (disabilitySupport.Length > 0) { disabilitySupports = string.Join(",", disabilitySupport); } if (weekdays.Length > 0) { days = string.Join(",", weekdays); } #endregion var oRequestCode = new Random().Next(0, int.MaxValue); var oRequestTime = DateTime.Now; string Model = string.Concat("{lat:", lat, ",lng:", lng, ",radius:", radius, ",sources:", sources, ",kinds:", kinds, ",tags:", tags, ",excludeTags:", excludeTags, ",disabilitySupports:", disabilitySupports, ",days:", days, ",gender:", gender, ",minCost:", minCost, ",maxCost:", maxCost, ",from:", from, ",to:", to, ",minTime:", minTime, ",maxTime:", maxTime, ",minAge:", minAge, ",maxAge:", maxAge, "}"); var oResult = MemoryCacheHelper.GetValue(Model + "-Activities"); var activities = new List <string>(); LogHelper.InsertServiceLogs("search/activities (GetActivities) (" + oRequestCode + ")", Model, oRequestTime); if (oResult == null) { activities = FeedHelper.GetActivities(lat, lng, radius, sources, kinds, tags, excludeTags, disabilitySupports, days, minCost, maxCost, gender, minTime, maxTime, minAge, maxAge, from, to); MemoryCacheHelper.Add(Model + "-Activities", activities, DateTimeOffset.UtcNow.AddHours(2)); } else { activities = oResult as List <string>; } LogHelper.InsertServiceLogs("search/activities (GetActivities) - Response (" + oRequestCode + ")", Model, oRequestTime, DateTime.Now); return(Ok(new { items = activities })); }
private RoleState Get(string unitCode, string username, string machucnang) { RoleState roleState = new RoleState(); if (username.Equals("admin") || username.Equals("hanghanh")) { roleState = new RoleState() { Approve = true, Delete = true, Add = true, STATE = "all", Edit = true, View = true }; } else { var cacheData = MemoryCacheHelper.GetValue(unitCode + "|" + machucnang + "|" + username); if (cacheData == null) { using (var connection = new OracleConnection(ConfigurationManager.ConnectionStrings["Database.Connection"].ConnectionString)) { connection.Open(); using (OracleCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = @"SELECT XEM,THEM,SUA,XOA,DUYET FROM AU_NHOMQUYEN_CHUCNANG WHERE UNITCODE='" + unitCode + "' AND MACHUCNANG='" + machucnang + "' AND MANHOMQUYEN IN (SELECT MANHOMQUYEN FROM AU_NGUOIDUNG_NHOMQUYEN WHERE UNITCODE='" + unitCode + "' AND USERNAME='******') UNION SELECT AU_NGUOIDUNG_QUYEN.XEM,AU_NGUOIDUNG_QUYEN.THEM,AU_NGUOIDUNG_QUYEN.SUA,AU_NGUOIDUNG_QUYEN.XOA,AU_NGUOIDUNG_QUYEN.DUYET " + "FROM AU_NGUOIDUNG_QUYEN WHERE AU_NGUOIDUNG_QUYEN.UNITCODE='" + unitCode + "' AND AU_NGUOIDUNG_QUYEN.MACHUCNANG='" + machucnang + "' AND AU_NGUOIDUNG_QUYEN.USERNAME='******'"; using (OracleDataReader oracleDataReader = command.ExecuteReader()) { if (!oracleDataReader.HasRows) { roleState = new RoleState() { STATE = string.Empty, View = false, Approve = false, Delete = false, Add = false, Edit = false }; } else { roleState.STATE = machucnang; while (oracleDataReader.Read()) { int objXem = Int32.Parse(oracleDataReader["XEM"].ToString()); if (objXem == 1) { roleState.View = true; } int objThem = Int32.Parse(oracleDataReader["THEM"].ToString()); if (objThem == 1) { roleState.Add = true; } int objSua = Int32.Parse(oracleDataReader["SUA"].ToString()); if (objSua == 1) { roleState.Edit = true; } int objXoa = Int32.Parse(oracleDataReader["XOA"].ToString()); if (objXoa == 1) { roleState.Delete = true; } int objDuyet = Int32.Parse(oracleDataReader["DUYET"].ToString()); if (objDuyet == 1) { roleState.Approve = true; } } MemoryCacheHelper.Add(unitCode + "|" + machucnang + "|" + username, roleState, DateTimeOffset.Now.AddHours(6)); } } } } } else { roleState = (RoleState)cacheData; } } return(roleState); }
public RoleState GetRoleStateByMaChucNang(string unitCode, string username, string machucnang) { RoleState roleState = new RoleState(); roleState.STATE = machucnang; if (username == "admin" || username == "hanghanh") { roleState = new RoleState() { STATE = machucnang, View = true, Approve = true, Delete = true, Add = true, Edit = true, Giamua = true, Giaban = true, Giavon = true, Tylelai = true, Banchietkhau = true, Banbuon = true, Bantralai = true }; } else { using (var connection = new OracleConnection(new ERPContext().Database.Connection.ConnectionString)) { connection.Open(); using (OracleCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = @"SELECT AU_NHOMQUYEN_CHUCNANG.XEM,AU_NHOMQUYEN_CHUCNANG.THEM,AU_NHOMQUYEN_CHUCNANG.SUA,AU_NHOMQUYEN_CHUCNANG.XOA,AU_NHOMQUYEN_CHUCNANG.DUYET,AU_NHOMQUYEN_CHUCNANG.GIAMUA,AU_NHOMQUYEN_CHUCNANG.GIABAN,AU_NHOMQUYEN_CHUCNANG.GIAVON,AU_NHOMQUYEN_CHUCNANG.TYLELAI,AU_NHOMQUYEN_CHUCNANG.BANCHIETKHAU,AU_NHOMQUYEN_CHUCNANG.BANBUON,AU_NHOMQUYEN_CHUCNANG.BANTRALAI FROM AU_NHOMQUYEN_CHUCNANG WHERE UNITCODE='" + unitCode + "' AND MACHUCNANG='" + machucnang + "' AND MANHOMQUYEN IN (SELECT MANHOMQUYEN FROM AU_NGUOIDUNG_NHOMQUYEN WHERE UNITCODE='" + unitCode + "' AND USERNAME='******') UNION SELECT AU_NGUOIDUNG_QUYEN.XEM,AU_NGUOIDUNG_QUYEN.THEM,AU_NGUOIDUNG_QUYEN.SUA,AU_NGUOIDUNG_QUYEN.XOA,AU_NGUOIDUNG_QUYEN.DUYET,AU_NGUOIDUNG_QUYEN.GIAMUA,AU_NGUOIDUNG_QUYEN.GIABAN,AU_NGUOIDUNG_QUYEN.GIAVON,AU_NGUOIDUNG_QUYEN.TYLELAI,AU_NGUOIDUNG_QUYEN.BANCHIETKHAU,AU_NGUOIDUNG_QUYEN.BANBUON,AU_NGUOIDUNG_QUYEN.BANTRALAI " + "FROM AU_NGUOIDUNG_QUYEN WHERE AU_NGUOIDUNG_QUYEN.UNITCODE='" + unitCode + "' AND AU_NGUOIDUNG_QUYEN.MACHUCNANG='" + machucnang + "' AND AU_NGUOIDUNG_QUYEN.USERNAME='******'"; using (OracleDataReader oracleDataReader = command.ExecuteReader()) { if (!oracleDataReader.HasRows) { roleState = new RoleState() { STATE = string.Empty, View = false, Approve = false, Delete = false, Add = false, Edit = false, Giamua = false, Giaban = false, Giavon = false, Tylelai = false, Banchietkhau = false, Banbuon = false, Bantralai = false }; } else { roleState.STATE = machucnang; while (oracleDataReader.Read()) { int objXem = Int32.Parse(oracleDataReader["XEM"].ToString()); if (objXem == 1) { roleState.View = true; } int objThem = Int32.Parse(oracleDataReader["THEM"].ToString()); if (objThem == 1) { roleState.Add = true; } int objSua = Int32.Parse(oracleDataReader["SUA"].ToString()); if (objSua == 1) { roleState.Edit = true; } int objXoa = Int32.Parse(oracleDataReader["XOA"].ToString()); if (objXoa == 1) { roleState.Delete = true; } int objDuyet = Int32.Parse(oracleDataReader["DUYET"].ToString()); if (objDuyet == 1) { roleState.Approve = true; } int objGiamua = Int32.Parse(oracleDataReader["GIAMUA"].ToString()); if (objGiamua == 1) { roleState.Giamua = true; } int objGiaban = Int32.Parse(oracleDataReader["GIABAN"].ToString()); if (objGiaban == 1) { roleState.Giaban = true; } int objGiavon = Int32.Parse(oracleDataReader["GIAVON"].ToString()); if (objGiavon == 1) { roleState.Giavon = true; } int objTylelai = Int32.Parse(oracleDataReader["TYLELAI"].ToString()); if (objTylelai == 1) { roleState.Tylelai = true; } int objBanchietkhau = Int32.Parse(oracleDataReader["BANCHIETKHAU"].ToString()); if (objBanchietkhau == 1) { roleState.Banchietkhau = true; } int objBanbuon = Int32.Parse(oracleDataReader["BANBUON"].ToString()); if (objBanbuon == 1) { roleState.Banbuon = true; } int objBantralai = Int32.Parse(oracleDataReader["BANTRALAI"].ToString()); if (objBantralai == 1) { roleState.Bantralai = true; } } MemoryCacheHelper.Add(unitCode + "|" + machucnang + "|" + username, roleState, DateTimeOffset.Now.AddHours(6)); } } } } } return(roleState); }
public ResultData SendLinkActive([FromUri] string userName, [FromUri] string capcha, [FromUri] string emailConfirm) { ResultData oResultData = new ResultData(); try { if (!string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(capcha)) { //Kiểm tra user có tồn tại không ApplicationUser user = UserManager.FindByName <ApplicationUser, string>(userName); if (user != null) { //Kiểm tra capcha có hợp lệ không object objCapcha = MemoryCacheHelper.GetValue(Commonkey.Capcha); if (objCapcha == null && !string.IsNullOrWhiteSpace(capcha)) { oResultData.Success = false; oResultData.ErrorMessage = MT.Resources.GlobalResource.WarnCodeExpried; } if (!objCapcha.ToString().Equals(capcha, StringComparison.OrdinalIgnoreCase)) { oResultData.Success = false; oResultData.ErrorMessage = MT.Resources.GlobalResource.WarnCodeInValid; } else { MemoryCacheHelper.Delete(Commonkey.Capcha); } if (user.Email == emailConfirm) { Guid token = Guid.NewGuid(); MemoryCacheHelper.Add(token.ToString(), userName, DateTimeOffset.Now.AddDays(1)); string hostName = MT.Library.CommonFunction.GetDomainBEcore(); string pathEmail = MT.Library.CommonFunction.GetMapPathEmail(); //var destinationPath = Path.Combine(pathEmail, "ConfirmPassword.html"); var destinationPath = Path.Combine(pathEmail, "SetNewPassword.html"); string strBody = MT.Library.CommonFunction.ReadData(destinationPath); strBody = strBody.Replace("#Link#", hostName); strBody = strBody.Replace("#Token#", token.ToString()); //Gửi mail kích hoạt tài khoản EmailUltility.SendMail(user.Email, "", MT.Resources.GlobalResource.Title_ActiveLink, strBody, null); oResultData.Success = true; oResultData.Data = user.Email; } else { oResultData.Success = false; oResultData.ErrorMessage = MT.Resources.GlobalResource.InvalidEmailConfirm; } } else { oResultData.Success = false; oResultData.ErrorMessage = MT.Resources.GlobalResource.UserNameInValid; } } else { oResultData.Success = false; oResultData.ErrorMessage = MT.Resources.GlobalResource.WarnUserNameOrCodeBlank; } } catch (Exception ex) { oResultData.SetError(ex); } return(oResultData); }
public RoleState GetRoleStateByMaChucNang(string unitCode, string username, string machucnang) { RoleState roleState = new RoleState(); roleState.STATE = machucnang; if (username == "admin") { roleState = new RoleState() { STATE = machucnang, XEM = true, THEM = true, SUA = true, XOA = true, DUYET = true, GIAMUA = true, GIABAN = true, GIAVON = true, TYLELAI = true, BANCHIETKHAU = true, BANBUON = true, BANTRALAI = true }; } else { using (var connection = new OracleConnection(new ERBusContext().Database.Connection.ConnectionString)) { connection.Open(); using (OracleCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = @"SELECT NHOMQUYEN_MENU.XEM,NHOMQUYEN_MENU.THEM,NHOMQUYEN_MENU.SUA,NHOMQUYEN_MENU.XOA,NHOMQUYEN_MENU.DUYET,NHOMQUYEN_MENU.GIAMUA,NHOMQUYEN_MENU.GIABAN,NHOMQUYEN_MENU.GIAVON,NHOMQUYEN_MENU.TYLELAI,NHOMQUYEN_MENU.BANCHIETKHAU,NHOMQUYEN_MENU.BANBUON,NHOMQUYEN_MENU.BANTRALAI FROM NHOMQUYEN_MENU WHERE UNITCODE LIKE '" + unitCode + "%' AND MA_MENU='" + machucnang + "' AND MANHOMQUYEN IN (SELECT MANHOMQUYEN FROM NGUOIDUNG_NHOMQUYEN WHERE UNITCODE LIKE '" + unitCode + "%' AND USERNAME='******') UNION SELECT NGUOIDUNG_MENU.XEM,NGUOIDUNG_MENU.THEM,NGUOIDUNG_MENU.SUA,NGUOIDUNG_MENU.XOA,NGUOIDUNG_MENU.DUYET,NGUOIDUNG_MENU.GIAMUA,NGUOIDUNG_MENU.GIABAN,NGUOIDUNG_MENU.GIAVON,NGUOIDUNG_MENU.TYLELAI,NGUOIDUNG_MENU.BANCHIETKHAU,NGUOIDUNG_MENU.BANBUON,NGUOIDUNG_MENU.BANTRALAI " + "FROM NGUOIDUNG_MENU WHERE NGUOIDUNG_MENU.UNITCODE LIKE '" + unitCode + "%' AND NGUOIDUNG_MENU.MA_MENU='" + machucnang + "' AND NGUOIDUNG_MENU.USERNAME='******'"; using (OracleDataReader oracleDataReader = command.ExecuteReader()) { if (!oracleDataReader.HasRows) { roleState = new RoleState() { STATE = string.Empty, XEM = false, THEM = false, SUA = false, XOA = false, DUYET = false, GIAMUA = false, GIABAN = false, GIAVON = false, TYLELAI = false, BANCHIETKHAU = false, BANBUON = false, BANTRALAI = false }; } else { roleState.STATE = machucnang; while (oracleDataReader.Read()) { int objXem = Int32.Parse(oracleDataReader["XEM"].ToString()); if (objXem == 1) { roleState.XEM = true; } int objThem = Int32.Parse(oracleDataReader["THEM"].ToString()); if (objThem == 1) { roleState.THEM = true; } int objSua = Int32.Parse(oracleDataReader["SUA"].ToString()); if (objSua == 1) { roleState.SUA = true; } int objXoa = Int32.Parse(oracleDataReader["XOA"].ToString()); if (objXoa == 1) { roleState.XOA = true; } int objDuyet = Int32.Parse(oracleDataReader["DUYET"].ToString()); if (objDuyet == 1) { roleState.DUYET = true; } int objGIAMUA = Int32.Parse(oracleDataReader["GIAMUA"].ToString()); if (objGIAMUA == 1) { roleState.GIAMUA = true; } int objGIABAN = Int32.Parse(oracleDataReader["GIABAN"].ToString()); if (objGIABAN == 1) { roleState.GIABAN = true; } int objGIAVON = Int32.Parse(oracleDataReader["GIAVON"].ToString()); if (objGIAVON == 1) { roleState.GIAVON = true; } int objTYLELAI = Int32.Parse(oracleDataReader["TYLELAI"].ToString()); if (objTYLELAI == 1) { roleState.TYLELAI = true; } int objBANCHIETKHAU = Int32.Parse(oracleDataReader["BANCHIETKHAU"].ToString()); if (objBANCHIETKHAU == 1) { roleState.BANCHIETKHAU = true; } int objBANBUON = Int32.Parse(oracleDataReader["BANBUON"].ToString()); if (objBANBUON == 1) { roleState.BANBUON = true; } int objBANTRALAI = Int32.Parse(oracleDataReader["BANTRALAI"].ToString()); if (objBANTRALAI == 1) { roleState.BANTRALAI = true; } } MemoryCacheHelper.Add(unitCode + "|" + machucnang + "|" + username, roleState, DateTimeOffset.Now.AddHours(6)); } } } } } return(roleState); }
public RoleState GetRoleStateByMaChucNang(string unitCode, string username, string machucnang) { RoleState roleState = new RoleState(); roleState.STATE = machucnang; //var cacheData = MemoryCacheHelper.GetValue(unitCode+"|"+machucnang + "|" + username); //if (cacheData==null) //{ //} //else //{ // roleState = (RoleState)cacheData; //} if (username == "admin") { roleState = new RoleState() { STATE = machucnang, View = true, Approve = true, Delete = true, Add = true, Edit = true }; } else { using (var connection = new SqlConnection(new MTADbContext().Database.Connection.ConnectionString)) { connection.Open(); using (SqlCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = @"SELECT XEM,THEM,SUA,XOA,DUYET FROM AU_NHOMQUYEN_CHUCNANG WHERE UNITCODE='" + unitCode + "' AND MACHUCNANG='" + machucnang + "' AND MANHOMQUYEN IN (SELECT MANHOMQUYEN FROM AU_NGUOIDUNG_NHOMQUYEN WHERE UNITCODE='" + unitCode + "' AND USERNAME='******') UNION SELECT AU_NGUOIDUNG_QUYEN.XEM,AU_NGUOIDUNG_QUYEN.THEM,AU_NGUOIDUNG_QUYEN.SUA,AU_NGUOIDUNG_QUYEN.XOA,AU_NGUOIDUNG_QUYEN.DUYET " + "FROM AU_NGUOIDUNG_QUYEN WHERE AU_NGUOIDUNG_QUYEN.UNITCODE='" + unitCode + "' AND AU_NGUOIDUNG_QUYEN.MACHUCNANG='" + machucnang + "' AND AU_NGUOIDUNG_QUYEN.USERNAME='******'"; using (SqlDataReader sqlReader = command.ExecuteReader()) { if (!sqlReader.HasRows) { roleState = new RoleState() { STATE = string.Empty, View = false, Approve = false, Delete = false, Add = false, Edit = false }; } else { roleState.STATE = machucnang; while (sqlReader.Read()) { int objXem = Int32.Parse(sqlReader["XEM"].ToString()); if (objXem == 1) { roleState.View = true; } int objThem = Int32.Parse(sqlReader["THEM"].ToString()); if (objThem == 1) { roleState.Add = true; } int objSua = Int32.Parse(sqlReader["SUA"].ToString()); if (objSua == 1) { roleState.Edit = true; } int objXoa = Int32.Parse(sqlReader["XOA"].ToString()); if (objXoa == 1) { roleState.Delete = true; } int objDuyet = Int32.Parse(sqlReader["DUYET"].ToString()); if (objDuyet == 1) { roleState.Approve = true; } } MemoryCacheHelper.Add(unitCode + "|" + machucnang + "|" + username, roleState, DateTimeOffset.Now.AddHours(6)); } } } } } return(roleState); }
private RoleState Get(string unitCode, string username, string machucnang) { RoleState roleState = new RoleState(); if (username.Equals("admin")) { roleState = new RoleState() { XEM = true, THEM = true, SUA = true, XOA = true, DUYET = true, STATE = "all", }; } else { var cacheData = MemoryCacheHelper.GetValue(unitCode + "|" + machucnang + "|" + username); if (cacheData == null) { using (var connection = new OracleConnection(ConfigurationManager.ConnectionStrings["ERBusConnection"].ConnectionString)) { connection.Open(); using (OracleCommand command = connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = @"SELECT XEM,THEM,SUA,XOA,DUYET FROM NHOMQUYEN_MENU WHERE UNITCODE LIKE '" + unitCode + "%' AND MA_MENU='" + machucnang + "' AND MANHOMQUYEN IN (SELECT MANHOMQUYEN FROM NGUOIDUNG_NHOMQUYEN WHERE UNITCODE LIKE '" + unitCode + "%' AND USERNAME='******') UNION SELECT NGUOIDUNG_MENU.XEM,NGUOIDUNG_MENU.THEM,NGUOIDUNG_MENU.SUA,NGUOIDUNG_MENU.XOA,NGUOIDUNG_MENU.DUYET " + "FROM NGUOIDUNG_MENU WHERE NGUOIDUNG_MENU.UNITCODE LIKE '" + unitCode + "%' AND NGUOIDUNG_MENU.MA_MENU='" + machucnang + "' AND NGUOIDUNG_MENU.USERNAME='******'"; using (OracleDataReader oracleDataReader = command.ExecuteReader()) { if (!oracleDataReader.HasRows) { roleState = new RoleState() { STATE = string.Empty, XEM = false, THEM = false, SUA = false, XOA = false, DUYET = false, }; } else { roleState.STATE = machucnang; while (oracleDataReader.Read()) { int objXem = Int32.Parse(oracleDataReader["XEM"].ToString()); if (objXem == 1) { roleState.XEM = true; } int objThem = Int32.Parse(oracleDataReader["THEM"].ToString()); if (objThem == 1) { roleState.THEM = true; } int objSua = Int32.Parse(oracleDataReader["SUA"].ToString()); if (objSua == 1) { roleState.SUA = true; } int objXoa = Int32.Parse(oracleDataReader["XOA"].ToString()); if (objXoa == 1) { roleState.XOA = true; } int objDuyet = Int32.Parse(oracleDataReader["DUYET"].ToString()); if (objDuyet == 1) { roleState.DUYET = true; } } MemoryCacheHelper.Add(unitCode + "|" + machucnang + "|" + username, roleState, DateTimeOffset.Now.AddHours(6)); } } } } } else { roleState = (RoleState)cacheData; } } return(roleState); }