示例#1
0
        public async Task <List <UserDTOs> > GetAllUserDetails()
        {
            try
            {
                var cacheUser = _distributedCache.GetString(Constant.StudentEntity);

                if (cacheUser == null)
                {
                    var usertListFromDB = await _dataContext.Users.ToListAsync();

                    if (usertListFromDB == null)
                    {
                        return(null);
                    }
                    cacheUser = System.Text.Json.JsonSerializer.Serialize(usertListFromDB);
                    GetDataFromCache(cacheUser, Constant.StudentEntity);
                    return(EntityMapper <User, UserDTOs> .MapEntityCollection(usertListFromDB));
                }
                else
                {
                    return(JsonConvert.DeserializeObject <List <UserDTOs> >(cacheUser));
                }
            }

            catch (Exception ex)
            {
                await _loggerRepository.InsertIntoLog(ExceptionHelper.HandleException(ErrorLevel.Error.ToString(), ex.ToString(), $"Failed to get Student details from db."));

                return(null);
            }
        }
示例#2
0
        public async Task <bool> InsertIntoLog(LoggerDTOs loggerDTOs)
        {
            var createLog = new Logger
            {
                Exception = loggerDTOs.Exception,
                Message   = loggerDTOs.Message,
                Level     = loggerDTOs.Level,
                Date      = loggerDTOs.Date
            };
            await _loggerRepository.InsertIntoLog(createLog);

            return(true);
        }
        public async Task <List <StudentDTOs> > GetAllStudentDetails()
        {
            try
            {
                return(await _studentRepository.GetAllStudentDetails());
            }
            catch (Exception ex)
            {
                await _loggerRepository.InsertIntoLog(ExceptionHelper.HandleException(ErrorLevel.Error.ToString(), ex.ToString(), $"Failed to get Student details."));

                return(null);
            }
        }