• 三、写服务


    准备工作:

    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;
            }
    
        }
    }
    

      

    一、添加菜单

  • 相关阅读:
    myeclipse_导入js文件报错
    myeclipse_tomcat在debug模式中报错的信息
    myeclipse_修改@author的值
    项目总结_web文件上传问题
    项目总结_导入JSTL标签库
    在Ubuntu上实现人脸识别登录
    Data Science and Matrix Optimization-课程推荐
    Digix2019华为算法精英挑战赛代码
    Shell script notes
    optim.py-使用tensorflow实现一般优化算法
  • 原文地址:https://www.cnblogs.com/fger/p/10675823.html
Copyright © 2020-2023  润新知