Beispiel #1
0
 public static List <WorkHours> list()
 {
     using (var dbContext = new WashingtonRedskinsContext())
     {
         return(dbContext.WorkHours.ToList());
     }
 }
Beispiel #2
0
 private static Statuses get(uint id)
 {
     using (var dbCOntext = new WashingtonRedskinsContext())
     {
         return(dbCOntext.Statuses.Find(id));
     }
 }
Beispiel #3
0
 public static Registrations get(uint id)
 {
     using (var dbCOntext = new WashingtonRedskinsContext())
     {
         return(dbCOntext.Registrations.Find(id));
     }
 }
Beispiel #4
0
 public static void delete(uint id)
 {
     using (var dbContext = new WashingtonRedskinsContext())
     {
         dbContext.Remove(dbContext.Statuses.Find(id));
     }
 }
Beispiel #5
0
        public static List <Registrations> list(DateTime start, int pageSize,
                                                int skip, uint userId)
        {
            IQueryable <Registrations> dbRegs;

            using (var dbContext = new WashingtonRedskinsContext())
            {
                dbRegs = dbContext.Registrations;

                if (start != null)
                {
                    dbRegs = dbRegs.Where(r => r.Time > start);
                }
                if (pageSize != 0)
                {
                    dbRegs = dbRegs.Take(pageSize + skip);
                }
                if (skip != 0)
                {
                    dbRegs = dbRegs.Skip(skip);
                }
                if (userId != 0)
                {
                    dbRegs = dbRegs.Where(r => r.UserId == userId);
                }
                return(dbRegs.ToList());
            }
        }
Beispiel #6
0
 public static Users get(uint id)
 {
     using (var dbContext = new WashingtonRedskinsContext())
     {
         return(dbContext.Users.Find(id));
     }
 }
Beispiel #7
0
        public static List <Users> list(int pageSize = 50, int skip = 0, uint userGroupId = 0, uint departmentId = 0)
        {
            IQueryable <Users> dbUsers;

            using (var dbContext = new WashingtonRedskinsContext())
            {
                dbUsers = dbContext.Users;

                if (pageSize != 0)
                {
                    dbUsers = dbUsers.Take(pageSize);
                }
                if (skip != 0)
                {
                    dbUsers = dbUsers.Skip(skip);
                }
                if (userGroupId != 0)
                {
                    dbUsers = dbUsers.Where(u => u.UserGroupId == userGroupId);
                }
                if (departmentId != 0)
                {
                    dbUsers = dbUsers.Where(u => u.DepartmentId == departmentId);
                }
                return(dbUsers.ToList());
            }
        }
Beispiel #8
0
 public static List <Statuses> list()
 {
     using (var dbContext = new WashingtonRedskinsContext())
     {
         return(dbContext.Statuses.ToList());
     }
 }
Beispiel #9
0
 public static Departments get(uint id)
 {
     using (var dbCOntext = new WashingtonRedskinsContext())
     {
         return(dbCOntext.Departments.Find(id));
     }
 }
Beispiel #10
0
 public void add()
 {
     using (var dbContext = new WashingtonRedskinsContext())
     {
         dbContext.WorkHours.Add(this).State = EntityState.Added;
         dbContext.SaveChanges();
     }
 }
Beispiel #11
0
 public static void add(RegistrationsEdits regEdit)
 {
     using (var DbContext = new WashingtonRedskinsContext())
     {
         DbContext.RegistrationsEdits.Add(regEdit);
         DbContext.SaveChanges();
     }
 }
Beispiel #12
0
 public void add()
 {
     using (var dbContext = new WashingtonRedskinsContext())
     {
         dbContext.Users.Add(this);
         dbContext.SaveChanges();
     }
 }
Beispiel #13
0
        public List <string> GetUserPrivileges()
        {
            IQueryable <string> privileges;

            using (var dbcontext = new WashingtonRedskinsContext())
            {
                privileges = dbcontext.Privileges.Where(x => x.UserGroupsPrivileges.Where(up => up.Isallowed == 1).Any(r => r.UserGroup.Id == UserGroupId)).Select(p => p.Name);
                return(privileges.ToList());
            }
        }
Beispiel #14
0
        public static Breaks get(uint id)
        {
            Breaks brk;

            using (var dbCOntext = new WashingtonRedskinsContext())
            {
                brk = dbCOntext.Breaks.Find(id);
            }
            return(brk);
        }
Beispiel #15
0
 public static void delete(uint id)
 {
     using (var dbContext = new WashingtonRedskinsContext())
     {
         var orig = dbContext.Departments.Find(id);
         orig.DeletedAt = DateTime.Now;
         bool a = dbContext.ChangeTracker.HasChanges(); //double check if there was any change detected by EF or not?
         dbContext.SaveChanges();
     }
 }
Beispiel #16
0
        public static void delete(uint id)
        {
            var orig = get(id);

            using (var dbContext = new WashingtonRedskinsContext())
            {
                orig.DeletedAt = DateTime.Now;
                dbContext.Entry(orig).State = EntityState.Modified;
                dbContext.SaveChanges();
            }
        }
Beispiel #17
0
        public static void edit(uint id, Users changes)
        {
            var orig = get(id);

            using (var dbContext = new WashingtonRedskinsContext())
            {
                dbContext.Entry(orig).CurrentValues.SetValues(changes);
                dbContext.Entry(orig).State = EntityState.Modified;
                dbContext.SaveChanges();
            }
        }
Beispiel #18
0
        public static RegistrationsEdits get()
        {
            RegistrationsEdits regEdit;

            using (var dbContext = new WashingtonRedskinsContext())
            {
                regEdit = dbContext.RegistrationsEdits.First();
            }

            return(regEdit);
        }
Beispiel #19
0
 public static void set(DateTime time)
 {
     using (var dbContext = new WashingtonRedskinsContext())
     {
         var regEdit = dbContext.RegistrationsEdits.Where(r => r.Time > time).FirstOrDefault();
         if (regEdit != null)
         {
             regEdit.Time = time;
             dbContext.SaveChanges();
         }
     }
 }
Beispiel #20
0
        public static void delete(uint id)
        {
            DateTime time;

            using (var dbContext = new WashingtonRedskinsContext())
            {
                time = dbContext.Registrations.Find(id).Time;
                dbContext.Registrations.Find(id).DeletedAt = DateTime.Now;
                dbContext.SaveChanges();
            }
            RegistrationsEdits.set(time);
        }
Beispiel #21
0
 public static string login(string email, string password)
 {
     if (AuthController.validatePassword(email, password))
     {
         Users usr;
         using (var dbContext = new WashingtonRedskinsContext())
         {
             usr = dbContext.Users.Where(u => u.Email == email).First();
         }
         return(AuthController.generateToken(usr));
     }
     return(null);
 }
Beispiel #22
0
        public static void edit(Registrations newRegistration, uint origId)
        {
            var orig = get(origId);

            using (var dbContext = new WashingtonRedskinsContext())
            {
                dbContext.Entry(orig).CurrentValues.SetValues(newRegistration);
                dbContext.Entry(orig).State = EntityState.Modified;
                dbContext.SaveChanges();
            }
            var earliestTime = newRegistration.Time < orig.Time ? newRegistration.Time : orig.Time;

            RegistrationsEdits.set(earliestTime);
        }
Beispiel #23
0
        public Registrations getPrevious()
        {
            Registrations reg;

            try
            {
                using (var dbContext = new WashingtonRedskinsContext())
                {
                    reg = dbContext.Registrations.Where(r => r.UserId == UserId).Where(r => r.Id < Id).OrderByDescending(r => r.Id).First();
                }
            }
            catch
            {
                reg = null;
            }
            return(reg);
        }
Beispiel #24
0
        public static List <Departments> list(int pageSize = 50, int skip = 0)
        {
            IQueryable <Departments> dbDepartments;

            using (var dbContext = new WashingtonRedskinsContext())
            {
                dbDepartments = dbContext.Departments;

                if (pageSize != 0)
                {
                    dbDepartments = dbDepartments.Take(pageSize);
                }
                if (skip != 0)
                {
                    dbDepartments = dbDepartments.Skip(skip);
                }
                return(dbDepartments.ToList());
            }
        }
Beispiel #25
0
        public static List <UserGroup> list(int pageSize = 50,
                                            int skip     = 0)
        {
            IQueryable <UserGroup> dbUserGroups;

            using (var dbContext = new WashingtonRedskinsContext())
            {
                dbUserGroups = dbContext.UserGroups;

                if (pageSize != 0)
                {
                    dbUserGroups = dbUserGroups.Take(pageSize);
                }
                if (skip != 0)
                {
                    dbUserGroups = dbUserGroups.Skip(skip);
                }
                return(dbUserGroups.ToList());
            }
        }
Beispiel #26
0
        public static List <Breaks> list(int pageSize = 50,
                                         int skip     = 0)
        {
            IQueryable <Breaks> dbBreaks;
            List <Breaks>       brks;

            using (var dbContext = new WashingtonRedskinsContext())
            {
                dbBreaks = dbContext.Breaks;

                if (pageSize != 0)
                {
                    dbBreaks = dbBreaks.Take(pageSize);
                }
                if (skip != 0)
                {
                    dbBreaks = dbBreaks.Skip(skip);
                }
                brks = dbBreaks.ToList();
            }
            return(brks);
        }
Beispiel #27
0
        public static void add(uint userId, uint statusId)
        {
            Registrations reg = new Registrations();

            Users usr;

            using (var dbContext = new WashingtonRedskinsContext())
            {
                usr = dbContext.Users.Find(userId);
            }

            reg.UserId       = userId;
            reg.Time         = DateTime.Now;
            reg.DepartmentId = usr.DepartmentId;
            reg.StatusId     = statusId;

            using (var dbContext = new WashingtonRedskinsContext())
            {
                dbContext.Add(reg);
                dbContext.SaveChanges();
            }
        }
Beispiel #28
0
        public static List <RegistrationSummary> list(DateTime start, bool groupByDay, bool groupByWeek, bool groupByMonth)
        {
            List <RegistrationSummary> regSum;

            using (var dbContext = new WashingtonRedskinsContext())
            {
                if (groupByMonth)
                {
                    regSum = dbContext.RegistrationSummary.Where(r => r.Date > start).GroupBy(s => new { s.YearMonth, s.UserId, s.StatusId, s.DepartmentId })
                             .Select(g =>
                                     new RegistrationSummary
                    {
                        UserId       = g.Key.UserId,
                        Duration     = g.Sum(x => x.Duration),
                        Id           = g.Min(x => x.Id),
                        YearMonth    = g.Key.YearMonth,
                        YearWeek     = 0,
                        DepartmentId = g.Key.DepartmentId,
                        StatusId     = g.Key.StatusId,
                        Date         = g.Min(x => x.Date)
                    }
                                     ).ToList();
                }
                else if (groupByMonth)
                {
                    regSum = dbContext.RegistrationSummary.Where(r => r.Date > start).GroupBy(s => new { s.YearWeek, s.UserId, s.StatusId, s.DepartmentId })
                             .Select(g =>
                                     new RegistrationSummary
                    {
                        UserId       = g.Key.UserId,
                        Duration     = g.Sum(x => x.Duration),
                        Id           = g.Min(x => x.Id),
                        YearMonth    = g.Key.YearWeek,
                        YearWeek     = 0,
                        DepartmentId = g.Key.DepartmentId,
                        StatusId     = g.Key.StatusId,
                        Date         = g.Min(x => x.Date)
                    }
                                     ).ToList();
                }
                else
                {
                    regSum = dbContext.RegistrationSummary.Where(r => r.Date > start).GroupBy(s => new { s.UserId, s.StatusId, s.DepartmentId })
                             .Select(g =>
                                     new RegistrationSummary
                    {
                        UserId       = g.Key.UserId,
                        Duration     = g.Sum(x => x.Duration),
                        Id           = g.Min(x => x.Id),
                        YearMonth    = 0,
                        YearWeek     = 0,
                        DepartmentId = g.Key.DepartmentId,
                        StatusId     = g.Key.StatusId,
                        Date         = g.Min(x => x.Date)
                    }
                                     ).ToList();
                }

                return(regSum);
            }
        }