Example #1
0
        /// <summary>
        /// 新增一条
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <int> Insert(PersonInputDto input)
        {
            // 如果不需要返回自增Id,使用 InsertAsync即可
            var newEntity = await _personRepository.InsertNowAsync(input.Adapt <Person>());

            return(newEntity.Entity.Id);

            // 还可以直接操作
            // await personDto.Adapt<Person>().InsertNowAsync();
        }
Example #2
0
        /// <summary>
        /// 更新一条
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task Update(PersonInputDto input)
        {
            var person = await _personRepository.Entities.Include(u => u.PersonDetail)
                         .Include(u => u.Childrens)
                         .Include(u => u.Posts)
                         .SingleAsync(u => u.Id == input.Id.Value);

            input.Adapt(person);

            await _personRepository.UpdateAsync(person);

            // 还可以直接操作
            // await personDto.Adapt<Person>().UpdateAsync();
        }