Exemple #1
0
        public bool Invoke(int id)
        {
            var userToDelete = userRepository.GetById(id);

            if (userToDelete == null)
            {
                return(false);
            }

            userRepository.Delete(userToDelete);
            userRepository.Save();

            var userApps = userAppRepository.GetAll();

            var appsToDelete = (from app in userApps where app.User.Id == id select app).ToList();

            if (appsToDelete == null || appsToDelete.Count == 0)
            {
                return(false);
            }

            foreach (var app in appsToDelete)
            {
                userAppRepository.Delete(app);
            }

            userAppRepository.Save();

            return(true);
        }
Exemple #2
0
        public List <UserDetailsFromAppModel> Invoke(int appId)
        {
            var listUserApps = userAppRepository.GetAll();
            var listUser     = userRepository.GetAll();
            var listOfUsers  = new List <UserDetailsFromAppModel>();

            try {
                var list2 = (from userApps in listUserApps
                             join user in listUser on userApps.User.Id equals user.Id
                             where userApps.App.Id == appId select new UserDetailsFromAppModel()
                {
                    Id = user.Id,
                    Name = user.Name,
                    Email = user.Email,
                    Role = (UserRole)userApps.Role,
                }).ToList();

                listOfUsers = list2;
            }
            catch (Exception)
            {
                // ignored
            }

            return(listOfUsers);
        }
Exemple #3
0
        public List <AppModel> Invoke(int userId)
        {
            var listOfApps = new List <AppModel>();
            var listApps   = appRepository.GetAll();
            var user       = userRepository.GetById(userId);

            List <DataAccess.Models.App> list;

            if (user != null && user.IsSuperAdmin)
            {
                list = listApps.ToList();
            }
            else
            {
                var listUserApps = userAppRepository.GetAll();

                if (!listUserApps.Any())
                {
                    // Return empty list
                    return(listOfApps);
                }

                list = (from userApps in listUserApps
                        join app in listApps on userApps.App.Id equals app.Id
                        where userApps.User.Id == userId
                        select app).ToList();
            }

            listOfApps.AddRange(list.Select(appFromDb => new AppModel()
            {
                Id = appFromDb.Id, Name = appFromDb.Name
            }));


            return(listOfApps);
        }