コード例 #1
0
        public Either <Error, Success> UnsetUserRoles(DtoLinkUserRoles link)
        {
            var dbQuery   = _appContext.UserRoles.AsQueryable();
            var foundUser = dbQuery.FirstOrDefault(x => x.Id == link.UserId.Id) ?? Left <Error, UserRole>(Error.NotFoundRecord);

            var result = foundUser.Bind(userRole =>
            {
                _appContext.UserRoles.Remove(userRole);
                var t = _appContext.TrySaveChanges().Bind <Success>(_ => Success.ItsSuccess);
                return(t);
            });

            return(result);
        }
コード例 #2
0
        public Either <Error, Success> SetUserRoles(DtoLinkUserRoles linkUserRoles)
        {
            var result = _appContext.Users.FindEither(linkUserRoles.UserId).Bind(
                user =>
            {
                linkUserRoles.RoleIds.Select(role => _appContext.Roles.Find <Role>(role)).Select(
                    role =>
                {
                    UserRole.Create(user, role).Bind <EntityEntry <UserRole> >(link =>
                                                                               _appContext.UserRoles.Add(link));
                    return(Right <Error, Role>(role));
                });
                var t = _appContext.TrySaveChanges().Bind <Success>(_ => Success.ItsSuccess);
                return(t);
            });

            return(result);
        }
コード例 #3
0
        /// <inheritdoc />
        public Either <Error, Success> UnsetUserRoles(DtoLinkUserRoles linkUserRoles)
        {
            var result = _userService.UnsetUserRoles(linkUserRoles);

            return(result);
        }