我在我的 asp.net 核心项目中编写用于向用户添加角色的代码
这是我的角色控制器。
public class RolesController : Controller
{
RoleManager<IdentityRole> _roleManager;
UserManager<AspNetUsers> _userManager;
public RolesController(RoleManager<IdentityRole> roleManager, UserManager<AspNetUsers> userManager)
{
_roleManager = roleManager;
_userManager = userManager;
}
public IActionResult Index() => View(_roleManager.Roles.ToList());
public IActionResult Create() => View();
[HttpPost]
public async Task<IActionResult> Create(string name)
{
if (!string.IsNullOrEmpty(name))
{
IdentityResult result = await _roleManager.CreateAsync(new IdentityRole(name));
if (result.Succeeded)
{
return RedirectToAction("Index");
}
else
{
foreach (var error in result.Errors)
{
ModelState.AddModelError(string.Empty, error.Description);
}
}
}
return View(name);
}
[HttpPost]
public async Task<IActionResult> Delete(string …Run Code Online (Sandbox Code Playgroud) TooSeeWeb.Infrastructure 用于迁移。
当我尝试使用此命令运行迁移时
dotnet ef migrations add ExampleMigration -s ..\TooSeeWeb
Run Code Online (Sandbox Code Playgroud)
我有这个错误
无法检索项目元数据。确保它是基于 MSBuild 的 .NET Core 项目。如果您使用自定义 BaseIntermediateOutputPath 或 MSBuildProjectExtensionsPath 值,请使用 --msbuildprojectextensionspath 选项
我该如何解决这个问题?
我有脚本可以在地图上显示标记
这是它的代码
我需要在标记悬停时显示弹出窗口
例如,我尝试这样做,因此它需要在Ibis London Barking酒店工作。
但这行不通
map.on('mouseover', 'Ibis London Barking', function(e) {
alert("Hover");
});
Run Code Online (Sandbox Code Playgroud)
官方文档说我需要这样的代码
map.on('mouseenter', 'places', function(e) {******}):
Run Code Online (Sandbox Code Playgroud)
但是他们从中添加标记,addLayer()而我没有。如何解决这个问题?
我尝试运行集成测试并收到此错误
System.InvalidOperationException:入口点在未构建 IHost 的情况下退出。在 Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.CreateHost() 在 Microsoft.Extensions.Hosting.HostFactoryResolver.<>c__DisplayClass10_0.b__0(String[] args) 在 Microsoft.AspNetCore.Mvc.Testing.DeferredHostBuilder.Build() 在 Microsoft .AspNetCore.Mvc.Testing.WebApplicationFactory
1.CreateHost(IHostBuilder builder) at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.ConfigureHostBuilder(IHostBuilder hostBuilder) 在 Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.EnsureServer() at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateDefaultClient(DelegatingHandler[] 处理程序) 在 Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateDefaultClient(Uri baseAddress, DelegatingHandler[] handlers) at Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactory1.CreateClient(WebApplicationFactoryClientOptions options) )位于 C:\Users\nemes\Documents\GitHub\ptco.app\System\Ptco.System.IntegrationTests\Infrastruct\IntegrationTestsWebFactory.cs 中的 Ptco.System.IntegrationTests.Infrastruct.IntegrationTestsWebFactory.CreteManagedClient():第 249 行
第 249 行是
private HttpClient CreteManagedClient() =>
CreateClient(new WebApplicationFactoryClientOptions
{
BaseAddress = new Uri(_configuration.GetValue<string>("IntegrationServerBaseUri"))
});
Run Code Online (Sandbox Code Playgroud)
就是这样称呼的
public IntegrationTestsWebFactory()
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{ …Run Code Online (Sandbox Code Playgroud) 我在组件中有从后端获取数据并检查状态的方法
就这个
getRecognitionById() {
this.loaderService.show(null, true);
this.vendorWebApiService
.createRecognition(this.executiveChangeId)
.pipe(take(1))
.subscribe((res) => {
this.vendorWebApiService
.getRecognition(res.taskRequestId, this.executiveChangeId)
.pipe(take(1))
.subscribe((recognitionResponse) => {
if (recognitionResponse.jobStatus === "completed") {
this.recognitionData = recognitionResponse;
this.getLatesFeedback();
}
if (recognitionResponse.jobStatus === "failed") {
alert();
} else {
}
});
});
}
Run Code Online (Sandbox Code Playgroud)
在这部分我检查状态
this.vendorWebApiService
.getRecognition(res.taskRequestId, this.executiveChangeId)
.pipe(take(1))
.subscribe((recognitionResponse) => {
if (recognitionResponse.jobStatus === "completed") {
this.recognitionData = recognitionResponse;
this.getLatesFeedback();
}
if (recognitionResponse.jobStatus === "failed") {
alert();
} else {
}
});
Run Code Online (Sandbox Code Playgroud)
但问题是,如果状态是另一个然后完成或失败,我需要每 5 秒重新运行一次此逻辑,因此每 5 秒我需要检查状态,并且在 10 次尝试后,我需要显示警报。
我需要如何重写代码才能实现这个逻辑?
我正在使用 Angular 材料来构建表格
这是我的表格组件:
import { Component, AfterViewInit, ViewChild } from '@angular/core';
import {MatTableDataSource, MatPaginator, MatDialog, MatDialogConfig} from '@angular/material';
import { PAYMENTS } from "./payments-mock";
@Component({
selector: 'app-payments',
templateUrl: './payments.component.html',
styleUrls: ['./payments.component.scss']
})
export class PaymentsComponent implements AfterViewInit {
//Default values to checkboxes
pending = false;
approved = false;
rejected = false;
//List of displaying columns
displayedColumns = ['PaymentDate','Amount','StatusDescription','Reason','Action'];
dataSource = new MatTableDataSource(PAYMENTS);
@ViewChild(MatPaginator) paginator: MatPaginator;
ngAfterViewInit() {
this.dataSource.paginator = this.paginator;
this.dataSource.filterPredicate =
(data, filter: string) => !filter || data.StatusDescription …Run Code Online (Sandbox Code Playgroud) 我有 Angular Material 对话框,我在其中更新表单击更改状态。
我需要从对话框中的单选按钮中获取价值
这是完整的工作示例
这是组件的代码
import {Component, Inject, OnInit, ViewEncapsulation} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef, MatDialog} from "@angular/material";
import {FormBuilder, Validators, FormGroup} from "@angular/forms";
import { Payment } from '../payments/payment';
@Component({
selector: 'editing-dialog',
templateUrl: './editing-dialog.component.html',
styleUrls: ['./editing-dialog.component.scss']
})
export class EditingDialogComponent implements OnInit {
form: FormGroup;
reason:String;
id: Number;
statusdescription: String ;
constructor(
private fb: FormBuilder,
private dialogRef: MatDialogRef<EditingDialogComponent>,
@Inject(MAT_DIALOG_DATA) data:Payment) {
this.reason = data.Reason;
this.id = data.Id;
this.statusdescription = data.StatusDescription;
this.form = fb.group({
reason: [this.reason, Validators.required], …Run Code Online (Sandbox Code Playgroud) 我有来自后端的字符串,我需要替换一些值
我是这样做的 usr_.avatar_base64.Replace("data:image/jpeg;base64,", "")
但有时它有data:image/jpg;base64,这样可以在替换中使用某种OR来处理不同的变体?
我有从后端获取值的角度分量。
这是ts中的方法。
properties: PropertyDto[] = [];
getProperties(event?: LazyLoadEvent): void {
if (this.primengTableHelper.shouldResetPaging(event)) {
this.paginator.changePage(0);
return;
}
this.primengTableHelper.showLoadingIndicator();
this._propertyService.getProperties(
this.filterText,
this.primengTableHelper.getSorting(this.dataTable),
this.primengTableHelper.getMaxResultCount(this.paginator, event),
this.primengTableHelper.getSkipCount(this.paginator, event)
)
.pipe(finalize(() => this.primengTableHelper.hideLoadingIndicator()))
.subscribe(result => {
this.primengTableHelper.totalRecordsCount = result.totalCount;
this.primengTableHelper.records = result.items;
this.primengTableHelper.hideLoadingIndicator();
});
}
Run Code Online (Sandbox Code Playgroud)
结果中的某些值可以为null。
这是这些值的html部分
<td>
{{record.landlord.name}}
</td>
<td>
{{record.agent.name}}
</td>
Run Code Online (Sandbox Code Playgroud)
我有类似的错误
无法读取未定义的属性“名称”
我如何只显示空白字段并避免这些错误?
我有 3 种方法可以做同样的事情。一个区别,它们适用于不同的模型。
下面是方法代码:
public IEnumerable<PropertyImportDto> ImportStandardCsv(string fileData)
{
List<PropertyImportDto> data;
using (var memoryStream =
new MemoryStream(Convert.FromBase64String(fileData.Substring(fileData.IndexOf(',') + 1))))
{
using (var streamWriter = new StreamReader(memoryStream))
using (var csvReader = new CsvReader(streamWriter))
{
var records = csvReader.GetRecords<PropertyImportDto>();
data = records.ToList();
}
}
return data;
}
public IEnumerable<ArthurPropertiesImportDto> ImportArthurCsv(string fileData)
{
List<ArthurPropertiesImportDto> data;
using (var memoryStream =
new MemoryStream(Convert.FromBase64String(fileData.Substring(fileData.IndexOf(',') + 1))))
{
using (var streamWriter = new StreamReader(memoryStream))
using (var csvReader = new CsvReader(streamWriter))
{
var records = csvReader.GetRecords<ArthurPropertiesImportDto>();
data = …Run Code Online (Sandbox Code Playgroud) c# ×5
javascript ×5
angular ×4
typescript ×4
.net ×3
asp.net ×1
asp.net-core ×1
asp.net-mvc ×1
html ×1
jquery ×1
mapbox ×1
mapbox-gl-js ×1
sass ×1