雪花

三、写服务

准备工作:

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

    }
}

  

一、添加菜单

 

posted @ 2019-04-09 11:21  十色  阅读(204)  评论(0编辑  收藏  举报