Asp.net core 3.1&Angular:几乎没有要求的问题

问题描述 投票:0回答:1

我目前正在开发一个使用aspnet core 3.1和Angular 9的小型电子商务网站,在订单验证期间出现错误。

当我验证订单时,我收到500类型错误,我无法理解问题的出处,预购应该在验证后显示在管理区域中,但是暂时无法使用,因此如果有人可以帮助我,因为我真的被困住了,这会非常好

error network

订单模型(clientapp):

import { Injectable } from '@angular/core';
import { Cart } from './cart.model';
import { Repository } from './repository';
import { Router, NavigationStart } from '@angular/router';
import { filter } from 'rxjs/operators';

@Injectable()
export class Order {

  constructor(
    private repo: Repository,
    public cart: Cart,
    private router: Router
    ) {
    this.router.events.pipe(
    filter(event => event instanceof NavigationStart))
    .subscribe(event => {
        if (router.url.startsWith('/checkout')
            && this.name != null && this.address != null) {
            repo.storeSessionData('checkout', {
                name: this.name,
                address: this.address,
                cardNumber: this.payment.cardNumber,
                cardExpiry: this.payment.cardExpiry,
                cardSecurityCode: this.payment.cardSecurityCode
            });
        }
    });
    repo.getSessionData('checkout').subscribe(data => {
        if (data != null) {
            this.name = data.name;
            this.address = data.address;
            this.payment.cardNumber = data.cardNumber;
            this.payment.cardExpiry = data.cardExpiry;
            this.payment.cardSecurityCode = data.cardSecurityCode;
        }
    });
 }

  orderId: number;
  name: string;
  address: string;
  // tslint:disable: no-use-before-declare
  payment: Payment = new Payment();
  // tslint:disable: no-inferrable-types
  submitted: boolean = false;
  shipped: boolean = false;
  orderConfirmation: OrderConfirmation;


  get clothes(): CartLine[] {
    return this.cart.selections
      .map(p => new CartLine(p.clotheId, p.quantity));
  }

  clear() {
    this.name = null;
    this.address = null;
    this.payment = new Payment();
    this.cart.clear();
    this.submitted = false;
  }

  submit() {
    this.submitted = true;
    this.repo.createOrder(this);
  }
}

export class Payment {
  cardNumber: string;
  cardExpiry: string;
  cardSecurityCode: string;
}

export class CartLine {
  constructor(private clotheId: number,
    private quantity: number) {}
}

export class OrderConfirmation {
  constructor(public orderId: number,
    public authCode: string,
    public amount: number) {}
}

服务:

  getOrders() {
    this.http.get<Order[]>(ordersUrl)
      .subscribe(data => this.orders = data);
  }
  createOrder(order: Order) {
    this.http.post<any>(ordersUrl, {
      name: order.name,
      address: order.address,
      payment: order.payment,
      clothes: order.clothes
    }).subscribe(data => {
      order.orderConfirmation = data;
      order.cart.clear();
      order.clear();
    });
  }
  shipOrder(order: Order) {
    this.http.post(ordersUrl + '/' + order.orderId, null)
      .subscribe(r => this.getOrders());
  }

order.component.html:

<div class="container mt-5">
  <table *ngIf="orders?.length > 0; else nodata" class="table table-striped">
    <tr>
        <th>Customer</th>
        <th>Address</th>
        <th>Clothes</th>
        <th>Total</th>
        <th></th>
    </tr>
    <tr *ngFor="let o of orders">
        <td>{{o.name}}</td>
        <td>{{o.address}}</td>
        <td>{{o.clothes.length}}</td>
        <td>{{o.payment.total | currency:'USD'}}</td>
        <td *ngIf="!o.shipped; else shipped">
            <button class="btn btn-sm btn-primary" (click)="markShipped(o)">
                Ship
            </button>
        </td>
    </tr>
  </table>
  <ng-template #shipped>
    <td>Shipped</td>
  </ng-template>
  <ng-template #nodata>
    <h3 class="text-center">There are no orders</h3>
  </ng-template>

</div>

order.component.ts:

import { Component } from '@angular/core';
import { Repository } from 'src/app/models/repository';
import { Order } from 'src/app/models/order.model';

@Component({
  selector: 'app-order-admin',
  templateUrl: './order-admin.component.html',
  styleUrls: ['./order-admin.component.css']
})
export class OrderAdminComponent {

  constructor(private repo: Repository) { }

    get orders(): Order[] {
        return this.repo.orders;
    }
    markShipped(order: Order) {
        this.repo.shipOrder(order);
    }

}

我的控制器:

   using System.Collections.Generic;
using System.Linq;
using Eshop.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace Eshop.Controllers
{
     [Route("/api/orders")]
    public class OrderValuesController : Controller
    {
        private DataContext context;
        public OrderValuesController(DataContext ctx)
        {
            context = ctx;
        }
        [HttpGet]
        public IEnumerable<Order> GetOrders()
        {
            return context.Orders
            .Include(o => o.Clothes).Include(o => o.Payment);
        }
        [HttpPost("{id}")]
        public void MarkShipped(long id)
        {
            Order order = context.Orders.Find(id);
            if (order != null)
            {
                order.Shipped = true;
                context.SaveChanges();
            }
        }
        [HttpPost]
        public IActionResult CreateOrder([FromBody] Order order)
        {
            if (ModelState.IsValid)
            {
                order.OrderId = 0;
                order.Shipped = false;
                order.Payment.Total = GetPrice(order.Clothes);
                ProcessPayment(order.Payment);
                if (order.Payment.AuthCode != null)
                {
                    context.Add(order);
                    context.SaveChanges();
                    return Ok(new
                    {
                        orderId = order.OrderId,
                        authCode = order.Payment.AuthCode,
                        amount = order.Payment.Total
                    });
                }
                else
                {
                    return BadRequest("Payment rejected");
                }
            }
            return BadRequest(ModelState);
        }
        private decimal GetPrice(IEnumerable<CartLine> lines)
        {
            IEnumerable<long> ids = lines.Select(l => l.ClotheId);
            return context.Clothes
            .Where(m => ids.Contains(m.ClotheId))
            .Select(m => lines
            .First(l => l.ClotheId == m.ClotheId).Quantity * m.Price)
            .Sum();
        }
        private void ProcessPayment(Payment payment)
        {
            // integrate your payment system here
            payment.AuthCode = "12345";
        }
    }
}

这就是控制台所说的:

    fail: Microsoft.AspNetCore.SpaServices[0]
      ERROR in ./node_modules/bootstrap/dist/css/bootstrap.min.css
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/postcss-loader/src/index.js):
Error: ENOENT: no such file or directory, open 'C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\bootstrap\dist\css\bootstrap.min.css'
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:343:35)
    at Storage.provideSync (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:98:13)
    at CachedInputFileSystem.readFileSync (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:259:32)
    at Observable.rxjs_1.Observable.obs [as _subscribe] (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\@ngtools\webpack\src\webpack-input-host.js:35:51)
    at Observable._trySubscribe (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\@ngtools\webpack\node_modules\rxjs\internal\Observable.js:44:25)
    at Observable.subscribe (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\@ngtools\webpack\node_modules\rxjs\internal\Observable.js:30:22)   
    at SyncDelegateHost._doSyncCall (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\@angular-devkit\core\src\virtual-fs\host\sync.js:22:20)    
    at SyncDelegateHost.read (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\@angular-devkit\core\src\virtual-fs\host\sync.js:49:21)
    at WebpackCompilerHost.readFileBuffer (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\@ngtools\webpack\src\compiler_host.js:161:44)        
    at VirtualFileSystemDecorator.readFile (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\@ngtools\webpack\src\virtual_file_system_decorator.js:42:54)
    at processResource (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:202:11)

fail: Microsoft.AspNetCore.SpaServices[0]
          at iteratePitchingLoaders (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:158:10)
    at iteratePitchingLoaders (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:165:10)
    at C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:176:18
    at loadLoader (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\loadLoader.js:47:3)
    at runLoaders (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\webpack\lib\NormalModule.js:313:20)
    at C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:367:11
    at C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:203:19
    at VirtualFileSystemDecorator.readFile (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\@ngtools\webpack\src\virtual_file_system_decorator.js:46:13)
    at processResource (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:202:11)
    at iteratePitchingLoaders (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:158:10)
    at iteratePitchingLoaders (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:165:10)
    at C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:176:18
    at loadLoader (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\loadLoader.js:47:3)
    at iteratePitchingLoaders (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
    at iteratePitchingLoaders (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:165:10)
    at C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:176:18
    at loadLoader (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\loadLoader.js:47:3)
    at iteratePitchingLoaders (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:169:2)
    at runLoaders (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\loader-runner\lib\LoaderRunner.js:365:2)
    at NormalModule.doBuild (C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\node_modules\webpack\lib\NormalModule.js:292:3)


fail: Microsoft.AspNetCore.SpaServices[0]
      ERROR in ./src/polyfills.ts
Module not found: Error: Can't resolve 'bootswatch' in 'C:\Users\Spartacus\Desktop\Core.net\ClotheShop\ClientApp\src'

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
System.InvalidOperationException: When called from 'VisitLambda', rewriting a node of type 'System.Linq.Expressions.ParameterExpression' must return a non-null value 
of the same type. Alternatively, override 'VisitLambda' and change it to not visit children of this type.
   at System.Linq.Expressions.ExpressionVisitor.VisitAndConvert[T](T node, String callerName)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitParameters(ExpressionVisitor visitor, IParameterProvider nodes, String callerName)
   at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
   at System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
   at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
   at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Translate(SelectExpression selectExpression, Expression expression)   
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.Sum(IQueryable`1 source)
   at Eshop.Controllers.OrderValuesController.GetPrice(IEnumerable`1 lines) in C:\Users\Spartacus\Desktop\Core.net\ClotheShop\Controllers\OrderValuesController.cs:line 63
   at Eshop.Controllers.OrderValuesController.CreateOrder(Order order) in C:\Users\Spartacus\Desktop\Core.net\ClotheShop\Controllers\OrderValuesController.cs:line 40 
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

感谢您的帮助!

angular api asp.net-core httprequest
1个回答
0
投票

请我需要帮助,我真的找不到解决方法

© www.soinside.com 2019 - 2024. All rights reserved.