Asp.Net Boilerplate… How to update a record in Existing tables in Database using Async methods?

社会主义新天地 提交于 2019-12-13 10:07:27

问题


I am working with ASP.Net Boilerplate. I want to send isActive=true to the AbpUser table when a user is confirmed by email. How can I access the database and do a query on that?

As you know Boilerplate doesn't provide entity classes so I am working with extensions on those classes. I don't know how queries on those classes access the database. Any idea?


回答1:


I wrote a sample code to show you how you can update a field of user with IRepository.

public interface IUserAppService: IApplicationService
{
    void ActivateUser(int userId);
}

 public class UserAppService : IUserAppService
    {
        private readonly IRepository<User, long> _userRepository;

        public UserEmailer(IRepository<User, long> userRepository)
        {
            _userRepository = userRepository;
        }

        public void ActivateUser(int userId)
        {
            var user = _userRepository.Get(userId);
            user.IsActive = true;
            _userRepository.Update(user);
        }
}


来源:https://stackoverflow.com/questions/45912587/asp-net-boilerplate-how-to-update-a-record-in-existing-tables-in-database-usi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!