• 三、写服务


    准备工作:

    1、领域层.Core类库下新建BasicData文件夹-分别写入领域实体和领域DB操作分别如下

    1.1  里面写入Student.cs实体类

    using Abp.Auditing;
    using Abp.Authorization.Users;
    using Abp.Domain.Entities;
    using Abp.Domain.Entities.Auditing;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace YD.CloudTimetable.BasicData
    {
        [Table("BD_Student")]
        [Audited]
        public class Student : FullAuditedEntity,IMayHaveTenant
        {
            public int? TenantId { get; set; }
            [Required]
            [MaxLength(AbpUserBase.MaxUserNameLength)]
            public virtual string Name { get; set; }
        }
    }
    

      

    1.2  用户领域DomainService DB的操作 

    using Abp.Domain.Repositories;
    using Abp.Domain.Services;
    using Microsoft.EntityFrameworkCore;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace YD.CloudTimetable.BasicData
    {
        public class DataStudentDomainService: DomainService
        {
            private readonly IRepository<Student, int> _Student;
            public DataStudentDomainService(IRepository<Student, int> Student)
            {
                _Student = Student;
            }
    
            public async Task<Student> GetProductByName(string name)
            {
                var query = from p in _Student.GetAll()
                            where p.Name == name
                            select p;
                var product = await query.FirstOrDefaultAsync();
                /*
                if (product == null)
                {
                    throw new UserFriendlyException($"商品({name})不存在");
                }
                if (product.Price < 0)
                {
                    throw new UserFriendlyException($"商品({name})的价格小于0,请检查");
                }*/
                return product;
            }
    
        }
    }
    

      

    一、添加菜单

  • 相关阅读:
    常用正则表达式
    偶得
    监控文件夹里面文件修改的小程序
    使用Windows服务发布WCF服务
    查看wcf服务中方法测试客户端
    twitter注册使用指南
    打包工具使用下载
    c#多线程编程
    请确保此文件可访问并且是一个有效的程序集或COM组件
    添加Service Reference, 无法为服务生成代码错误的解决办法
  • 原文地址:https://www.cnblogs.com/fger/p/10675823.html
Copyright © 2020-2023  润新知