Пример #1
0
        public virtual object GetClient(string token, string MAC)
        {
            if (!AuthenticationController.CheckToken(token))
            {
                return(null);
            }

            return(this.Context.Clients
                   .Where(client => client.MAC == MAC));
        }
Пример #2
0
        public virtual object LoggedClients(string token)
        {
            if (!AuthenticationController.CheckToken(token))
            {
                return(null);
            }

            return(this.Context.Clients
                   .Where(client => client.DateOfLogin != null).ToList());
        }
Пример #3
0
 public virtual T Get(string token, int Id) // Return specific
 {
     if (AuthenticationController.CheckToken(token))
     {
         return((T)this.DbSet.Find(Id));
     }
     else
     {
         return(null);
     }
 }
Пример #4
0
 public virtual IEnumerable <T> Get(string token) // Return all
 {
     if (AuthenticationController.CheckToken(token))
     {
         return(this.DbSet as IEnumerable <T>);
     }
     else
     {
         return(null);
     }
 }
Пример #5
0
        public virtual void Post(string token, T item) // Add
        {
            if (!AuthenticationController.CheckToken(token))
            {
                return;
            }

            if (item == null)
            {
                return;
            }

            this.DbSet.Add(item);
            this.Context.SaveChanges();
        }
Пример #6
0
        public virtual void Delete(string token, int id)
        {
            if (!AuthenticationController.CheckToken(token))
            {
                return;
            }

            T item = (T)this.DbSet.Find(id);

            if (item == null)
            {
                return;
            }

            this.Context.Set(typeof(T)).Remove(item);
            this.Context.SaveChanges();
        }
Пример #7
0
        public virtual object HomeQuery(string token)
        {
            if (!AuthenticationController.CheckToken(token))
            {
                return(null);
            }

            return((from cl in Context.Clients
                    join j in Context.Jobs on cl.Id equals j.IdClient
                    join c in Context.Configurations on j.IdConfiguration equals c.Id
                    select new
            {
                Id = cl.Id,
                CLName = cl.Name,
                COName = c.Name,
                Desc = c.Description
            }).ToList());
        }
Пример #8
0
        public virtual object IncomingBackupsQuery(string token)
        {
            if (!AuthenticationController.CheckToken(token))
            {
                return(null);
            }

            return(Context.Schedules
                   .Where(schedule => schedule.IdJob == schedule.Job.Id)
                   .Where(schedule => schedule.Job.Configuration.Id == schedule.Job.IdConfiguration)
                   .Where(Schedule => Schedule.Job.Client.Id == Schedule.Job.IdClient)
                   .Where(schedule => schedule.BackupDate >= DateTime.Now)
                   .Select(schedule => new
            {
                Datum = schedule.BackupDate,
                ClientName = schedule.Job.Client.Name,
                ConfigurationName = schedule.Job.Configuration.Name,
                schedule.Job.Configuration.Description
            }));
        }
Пример #9
0
        public virtual void Put(string token, T item) // Edit
        {
            if (!AuthenticationController.CheckToken(token))
            {
                return;
            }

            if (item == null)
            {
                return;
            }

            T tmp = Context.Set <T>().Find(item.Id);

            if (tmp == null)
            {
                return;
            }

            this.Context.Entry(tmp).CurrentValues.SetValues(item);
            this.Context.SaveChanges();
        }
Пример #10
0
        public virtual object ClientQuery(string token)
        {
            if (!AuthenticationController.CheckToken(token))
            {
                return(null);
            }

            return(Context.Clients
                   .GroupJoin(Context.Jobs
                              .Where(jobs => jobs.IdConfiguration == jobs.Configuration.Id),
                              client => client.Id,
                              q => q.IdClient,
                              (client, q) => new
            {
                Client = client,
                Configuration = q
            })
                   .SelectMany(x => x.Configuration
                               .DefaultIfEmpty(),
                               (x, y) => new
            {
                x.Client.Id,
                x.Client.Name,
                x.Client.MAC,
                Configuration = (y == null ? String.Empty : y.Configuration.Name)
            })
                   .GroupBy(client => client.Id)
                   .ToList()
                   .Select(eg => new
            {
                Id = eg.Key,
                Name = eg.First().Name,
                MAC = eg.First().MAC,
                Configuration = string.Join(",", eg.Select(i => i.Configuration))
            }));
        }