Example #1
0
        public Task <T> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var db = new WeatherDb())
            {
                return((Task <T>)Convert.ChangeType(db.User.FirstOrDefaultAsync(u => u.NormalizedUserName.Equals(normalizedUserName)), typeof(Task <T>)));
            }
        }
Example #2
0
        public Task <bool> IsInRoleAsync(T user, string roleName, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var db = new WeatherDb())
            {
                return(Task.FromResult(db.UserInRole.Count(m => m.UserId.Equals(user.Id) && m.Role.NormalizedName.Equals(roleName)) > 0));
            }
        }
Example #3
0
        public Task <T> FindByIdAsync(string userId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var db = new WeatherDb())
            {
                return((Task <T>)Convert.ChangeType(db.User.FirstOrDefaultAsync(u => u.Id == userId), typeof(Task <T>)));
            }
        }
Example #4
0
        public Task <IdentityResult> DeleteAsync(T user, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var db = new WeatherDb())
            {
                db.User.Where(u => u.Id == user.Id).Delete();

                return(Success());
            }
        }
Example #5
0
        public Task <IList <string> > GetRolesAsync(T user, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var db = new WeatherDb())
            {
                IList <string> l = db.UserInRole.Where(m => m.UserId.Equals(user.Id)).Select(m => m.Role.Name).ToList();

                return(Task.FromResult(l));
            }
        }
Example #6
0
        public Task <IdentityResult> CreateAsync(T user, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var db = new WeatherDb())
            {
                if (db.Insert(user) > 0)
                {
                    return(Success());
                }

                return(Fail());
            }
        }
Example #7
0
        public Task <IdentityResult> UpdateAsync(T role, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var db = new WeatherDb())
            {
                if (db.Update(role) > 0)
                {
                    return(Success());
                }

                return(Fail());
            }
        }
Example #8
0
        public Task <IList <T> > GetUsersInRoleAsync(string roleName, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var db = new WeatherDb())
            {
                IList <T> l = new List <T>();

                foreach (var u in db.UserInRole.Where(m => m.Role.NormalizedName.Equals(roleName)).Select(m => m.User))
                {
                    l.Add((T)u);
                }

                return(Task.FromResult(l));
            }
        }
Example #9
0
        public Task RemoveFromRoleAsync(T user, string roleName, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            using (var db = new WeatherDb())
            {
                var roleId = db.UserRole.First(r => r.NormalizedName.Equals(roleName)).Id;

                db.Delete(new UserInRole()
                {
                    UserId = user.Id, RoleId = roleId
                });
            }

            return(Task.FromResult <object>(null));
        }
        public static void DeleteDashboardItems(WeatherDb db, string userId)
        {
            if (db.DataProvider.Name.Equals("SQLite"))
            {
                var ids = from item in db.DashboardItem
                          where item.UserId.Equals(userId)
                          select item.Id;

                db.DashbordFilter
                .Where(f => ids.Contains(f.DashboardItemId))
                .Delete();

                db.DashboardItem
                .Where(item => ids.Contains(item.Id))
                .Delete();
            }
            else
            {
                db.DashboardItem
                .Where(item => item.UserId.Equals(userId))
                .Delete();
            }
        }