ABP【二】
【摘要】
5.新增webapi接口,在.Application项目中新增文件夹和类IMyTestAppService.cs 和 MyTestAppService.cs
public interface IMyTestAppService : IApplicationService
{
stri...
5.新增webapi接口,在.Application项目中新增文件夹和类IMyTestAppService.cs 和 MyTestAppService.cs
public interface IMyTestAppService : IApplicationService
{
string Test();
}
class MyTestAppService: MyABPAppServiceBase,IMyTestAppService
{
public string Test()
{
return "ssss";
}
}
运行项目即可通过 http://localhost:port/swagger/ui/index 访问
6.添加实体类并更新到数据库
(6.1)在.Core项目下添加MyTest文件夹,然后添加Order类
[Table("yf_Order")]
public class Order : FullAuditedEntity
{
/// <summary>
/// 订单号(唯一)
/// </summary>
[StringLength(32)]
public virtual string OrderNo { get; set; }
/// <summary>
/// 用户
/// </summary>
[ForeignKey("UserId")]
public User User { get; set; }
public long UserId { get; set; }
/// <summary>
/// 订单金额
/// </summary>
public int Amount { get; set; }
/// <summary>
/// 备注信息
/// </summary>
[StringLength(256)]
public string Remark { get; set; }
}
在EntityFrame项目...DbContext类中添加引用
public virtual IDbSet<Order> Order { get; set; }
Add-Migration "Add_Order"和 Update-Database
(6.3)在接口中操作数据库
using Abp.Authorization;
using Abp.Domain.Repositories;
using Abp.Runtime.Session;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyTestABP.MyTest
{
//令牌认证
[AbpAuthorize]
class MyTestAppService : MyTestABPAppServiceBase, IMyTestAppService
{
private readonly IRepository<Order> _orderRepository;
/// <summary>
/// 构造函数自动注入我们所需要的类或接口
/// </summary>
public MyTestAppService(IRepository<Order> orderRepository)
{
_orderRepository = orderRepository;
}
public string CreateOrder()
{
Order o = new Order();
o.UserId = 1;
o.Amount = 100;
o.Remark = "test Order";
o.UserId = this.AbpSession.GetUserId();
_orderRepository.Insert(o);
return "Success";
}
}
}
文章来源: zzzili.blog.csdn.net,作者:清雨小竹,版权归原作者所有,如需转载,请联系作者。
原文链接:zzzili.blog.csdn.net/article/details/79403126
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)