public async Task <IActionResult> AddPost(JDLYQuestion question) { try { await dbContext.AddAsync(question); await dbContext.SaveChangesAsync(); return(Json(new { success = true, msg = true })); } catch (Exception exc) { return(Json(new { success = false, msg = exc.Message })); } }
public async Task <IActionResult> ChekcUserCode(string userCode) { var jsonSetting = new JsonSerializerSettings(); jsonSetting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; var cacheEntryOptions = new DistributedCacheEntryOptions() .SetSlidingExpiration(TimeSpan.FromSeconds(10)); try { //check is employee var isEmployee = false; var isEmployeeResult = await _IDistributedCache.GetStringAsync("isEmployee" + userCode); if (string.IsNullOrEmpty(isEmployeeResult)) { var excelUserInfo = await dbContext.ExcelUserInfo.FirstOrDefaultAsync(x => x.Description == userCode); if (excelUserInfo != null) { isEmployee = true; } //await dbContext.UserInfo.AddAsync(new UserInfo //{ // Password = excelUserInfo.Description, // UserName = excelUserInfo.UserName //}); //await dbContext.SaveChangesAsync(); await _IDistributedCache.SetStringAsync("isEmployee" + userCode, isEmployee.ToString(), cacheEntryOptions); } else { bool.TryParse(isEmployeeResult, out isEmployee); } JDLYQuestion jsylQuestion = await dbContext.JDLYQuestion.OrderByDescending(x => x.Id).FirstOrDefaultAsync(); var isVoted = await dbContext.JDLYLog.AnyAsync(x => x.UserCode == userCode); return(Json(new { success = true, msg = isEmployee, isEnable = jsylQuestion.IsEnable, isVoted = isVoted })); } catch (Exception exc) { return(Json(new { success = false, msg = exc.Message })); } }