示例#1
0
 public async Task <List <ServerLoad> > GetAllServersLoad()
 {
     using (var ctx = new ServerTrackContext())
     {
         return(await ctx.ServerLoads.ToListAsync());
     }
 }
示例#2
0
        public async Task <InsertServerLoadResponse> InsertServerLoad(InsertServerLoadRequest request)
        {
            var serverLoad = MapServerLoadRequestToDomain(request);

            using (var ctx = new ServerTrackContext())
            {
                ctx.Entry(serverLoad).State = EntityState.Added;
                var status = await ctx.SaveChangesAsync();

                return(MapDomainToServerLoadResponse(serverLoad)); //return newly inserted server
            }
        }
示例#3
0
        public async Task <ServerLoad> GetServerLoadByName(string serverName)
        {
            using (var ctx = new ServerTrackContext())
            {
                var server = await ctx.ServerLoads.Where(t => t.ServerName.Equals(serverName, StringComparison.OrdinalIgnoreCase)).ToListAsync();

                if (server.Any())
                {
                    return(server.Single());
                }
                return(null);
            }
        }
示例#4
0
        public async Task <List <ServerLoad> > GetServerLoadByNameAndTime(string serverName, double?noOfMins, double?noOfHours)
        {
            using (var ctx = new ServerTrackContext())
            {
                var serverLoad = await ctx.ServerLoads.Where(t => t.ServerName.Equals(serverName, StringComparison.CurrentCultureIgnoreCase)).ToListAsync();

                if (noOfMins.HasValue && noOfMins > 0)
                {
                    var subtractMins = DateTime.Now.AddMinutes((double)-noOfMins);
                    return(serverLoad.Where(s => s.DateCreated > subtractMins).ToList());
                }
                else if (noOfHours.HasValue && noOfHours > 0)
                {
                    var subtractHours = DateTime.Now.AddHours((double)-noOfHours);
                    return(serverLoad.Where(s => s.DateCreated > subtractHours).ToList());
                }

                return(serverLoad);
            }
        }