Пример #1
0
        public async Task <ActionResult> Get <TEntity, TResponse>(int group, MinMaxDate form, string username = "",
                                                                  string password = "")
            where TEntity : EntityLog where TResponse : TypeAndTimeStamp
        {
            _logger.LogInformation(form.ToJson());
            if (_authService.IsAuthenticate(group, username, password))
            {
                var list = await _dbContext.Set <TEntity>()
                           .Where(entity =>
                                  entity.Timestamp <= form.MaxDate && entity.Timestamp >= form.MinDate &&
                                  entity.Type != LogType.ActivityLog)
                           .AsNoTracking()
                           .ToListAsync();

                list.Sort(Utility.CompareEntityLog);
                var result = new List <TResponse>();
                foreach (var entityLog in list)
                {
                    var entityResponseLog = _mapper.Map <TResponse>(entityLog);
                    entityResponseLog.Type      = entityLog.Type.GetDescription();
                    entityResponseLog.Timestamp =
                        entityLog.Timestamp.ToShortTimeString() + " " + entityLog.Timestamp.ToShortDateString();
                    result.Add(entityResponseLog);
                }

                return(Ok(result));
            }
            else
            {
                return(Unauthorized());
            }
        }
Пример #2
0
        public async Task <List <TResponse> > GetEntity <TEntity, TResponse>(int group, MinMaxDate form, string projectType,
                                                                             string username = "",
                                                                             string password = "")
            where TEntity : EntityLog where TResponse : TypeAndTimeStamp
        {
            _logger.LogInformation(form.ToJson());
            if (!_authService.IsAuthenticate(@group, username, password))
            {
                throw new AuthenticationException();
            }

            if (!ProjectType.IsProjectType(projectType))
            {
                _logger.LogInformation($"projectType was wrong {projectType}");
                return(new List <TResponse>());
            }
            var list = await _dbContext.Set <TEntity>()
                       .Where(entity =>
                              entity.Timestamp <= form.MaxDate && entity.Timestamp >= form.MinDate && entity.ProjectType.ToLower() == projectType.ToLower())
                       .AsNoTracking()
                       .ToListAsync();

            list.Sort(Utility.CompareEntityLog);
            var result = new List <TResponse>();

            foreach (var entityLog in list)
            {
                var entityResponseLog = _mapper.Map <TResponse>(entityLog);
                entityResponseLog.Type      = entityLog.Type.GetDescription();
                entityResponseLog.Timestamp =
                    entityLog.Timestamp.ToShortTimeString() + " " + entityLog.Timestamp.ToShortDateString();
                result.Add(entityResponseLog);
            }
            return(result);
        }