国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

WPF實(shí)戰(zhàn)學(xué)習(xí)筆記13-創(chuàng)建注冊(cè)登錄接口

這篇具有很好參考價(jià)值的文章主要介紹了WPF實(shí)戰(zhàn)學(xué)習(xí)筆記13-創(chuàng)建注冊(cè)登錄接口。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

創(chuàng)建注冊(cè)登錄接口

添加文件

創(chuàng)建文件

+ MyToDo.Api

? ./Controllers/LoginController.cs

? ./Service/ILoginService.cs

? ./Service/LoginService.cs

  • MyToDo.Share

    ./Dtos/UserDto.cs文章來源地址http://www.zghlxwxcb.cn/news/detail-614379.html

LoginController.cs
using Microsoft.AspNetCore.Mvc;
using MyToDo.Api.Context;
using MyToDo.Api.Service;
using MyToDo.Share.Dtos;
using MyToDo.Share.Parameters;

namespace MyToDo.Api.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class LoginController : ControllerBase
    {

        private readonly ILoginService service;

        public LoginController(ILoginService tService)
        {
            this.service = tService;
        }

        [HttpGet]
        public async Task<ApiReponse> LoginAsync(string Account, string PassWord) => await service.LoginAsync(Account,PassWord);

        [HttpPost]
        public async Task<ApiReponse> Resgiter([FromBody] UserDto param) => await service.Resgiter(param);
    }
}

ILoginService.cs
using MyToDo.Share.Dtos;

namespace MyToDo.Api.Service
{
    public interface ILoginService
    {
        /// <summary>
        /// 登錄
        /// </summary>
        /// <param name="Account">登錄名</param>
        /// <param name="PassWord">登錄密碼</param>
        /// <returns></returns>
        Task<ApiReponse> LoginAsync(string Account,string PassWord);

        /// <summary>
        /// 注冊(cè)
        /// </summary>
        /// <returns></returns>
        Task<ApiReponse> Resgiter(UserDto user);
    }
}

LoginService.cs
using Arch.EntityFrameworkCore.UnitOfWork;
using AutoMapper;
using MyToDo.Api.Context;
using MyToDo.Share.Dtos;
using System.Diagnostics.Eventing.Reader;

namespace MyToDo.Api.Service
{
    public class LoginService : ILoginService
    {
        private readonly IUnitOfWork work;
        private readonly IMapper mapper;

        public LoginService(IUnitOfWork work, IMapper mapper)
        {
            this.work = work;
            this.mapper = mapper;
        }

        public async Task<ApiReponse> LoginAsync(string Account, string PassWord)
        {
            try
            {
                if(Account==null || PassWord==null)
                    return new ApiReponse("賬號(hào)或密碼為空", false);

                var model = await work.GetRepository<User>().GetFirstOrDefaultAsync(predicate: x => (x.Account.Equals(Account)) && (x.Password.Equals(PassWord)));

                if(model == null)
                {
                    return new ApiReponse("賬號(hào)或密碼錯(cuò)誤",false); 
                }

                return new ApiReponse(true,model);
            }
            catch (Exception ex)
            {

                return new ApiReponse("登錄失敗", false); ;
            }
        }

        public async Task<ApiReponse> Resgiter(UserDto user)
        {
            try
            {
                var model = mapper.Map<User>(user);

                var repository = work.GetRepository<User>();
                //.GetFirstOrDefaultAsync(predicate: x => x.Account.Equals(model.Account));

                var usermodel = await repository.GetFirstOrDefaultAsync(predicate: x => x.Account.Equals(model.Account));

                if(usermodel != null) 
                    return new ApiReponse("當(dāng)前賬戶已存在",false);  
               
                model.CreateDate = DateTime.Now;

                await repository.InsertAsync(model);

                if(await work.SaveChangesAsync()>0)
                    return new ApiReponse(true, model);

                return new ApiReponse("注冊(cè)失敗,請(qǐng)稍后重試", false);

            }
            catch (Exception ex)
            {
                return new ApiReponse($"注冊(cè)失敗.{ex.Message}", false);
            }
        }
    }
}

UserDto.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyToDo.Share.Dtos
{
    public class UserDto:BaseDto
    {
		private string? userName;
		private string? passWord;
		private string? account;

		/// <summary>
		/// 賬戶
		/// </summary>
		public string? Account
		{
			get { return account; }
			set { account = value; OnPropertyChanged(); }
		}

		/// <summary>
		/// 密碼
		/// </summary>
		public string PassWord
		{
			get { return passWord; }
			set { passWord = value; OnPropertyChanged(); }
		}

		/// <summary>
		/// 用戶名
		/// </summary>
		public string UserName
		{
			get { return userName; }
			set { userName = value; OnPropertyChanged(); }
		}

	}
}

依賴注入

Program.cs 添加
.AddCustomRepository<User, UserRepository>();
AutoMapperProfilec.s 添加
builder.Services.AddTransient<ILoginService, LoginService>();

到了這里,關(guān)于WPF實(shí)戰(zhàn)學(xué)習(xí)筆記13-創(chuàng)建注冊(cè)登錄接口的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記28-登錄界面

    添加登錄界面UI 添加文件loginview.xaml。注意本界面使用的是md內(nèi)的圖標(biāo)。沒有登錄界面的圖片 添加對(duì)應(yīng)的viewmodel 添加文件Mytodo.ViewModels.LoginViewModel.cs 注冊(cè)視圖 添加啟動(dòng) 修改文件:App.xmal.cs

    2024年02月14日
    瀏覽(14)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記29-登錄數(shù)據(jù)綁定,編寫登錄服務(wù)

    添加登錄綁定字段、命令、方法 修改對(duì)象:Mytodo.ViewModels.ViewModels 添加密碼依賴對(duì)象行為 添加文件:Mytodo.Extensions.PassWordExtensions ### 登錄UI添加密碼行為 修改文件:Mytodo.Views.LoginView.xmal 添加命名空間,略 修改passbox。 添加加密方法,并使用 添加文件:MyToDo.Share.StringE

    2024年02月15日
    瀏覽(18)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記31-登錄界面全局通知

    UI添加消息聚合器 注冊(cè)提示消息 文件:Mytodo.Views.LoginView.cs構(gòu)造函數(shù)添加內(nèi)容 在需要的地方添加提示消息 修改文件:Mytodo.ViewModels.LoginViewModel.cs

    2024年02月14日
    瀏覽(24)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記08-創(chuàng)建數(shù)據(jù)庫(kù)

    創(chuàng)建文件夾 ./Context 創(chuàng)建文件 ./Context/BaseEnity.cs ./Context/Memo.cs ./Context/MyTodoContext.cs ./Context/Todo.cs ./Context/User.cs 創(chuàng)建數(shù)據(jù)對(duì)象 ./Context/BaseEnity.cs ./Context/Memo.cs ./Context/MyTodoContext.cs 創(chuàng)建數(shù)據(jù)庫(kù)DbSet ./Context/Todo.cs ./Context/User.cs 添加nuget包 Microsoft.EntityFrameworkCore.Design Shared design-time co

    2024年02月16日
    瀏覽(46)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記15-使用Memo類的GetAll接口

    總體參照上節(jié)即可 創(chuàng)建MemoService接口 新建文件Mytodo/Service/IMemoService.cs 實(shí)現(xiàn)MemoService接口 新建文件Mytodo/Service/MemoService.cs 依賴注入 修改 文件:Mytodo/App.xaml.cs 部分修改為: 修改ViewModel 參照上節(jié)

    2024年02月15日
    瀏覽(18)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記25-首頁(yè)匯總

    注意:本實(shí)現(xiàn)與視頻不一致。本實(shí)現(xiàn)中單獨(dú)做了匯總接口,而視頻中則合并到國(guó)todo接口當(dāng)中了。 添加匯總webapi接口 添加匯總數(shù)據(jù)客戶端接口 總數(shù)據(jù)客戶端接口對(duì)接3 首頁(yè)數(shù)據(jù)模型 添加數(shù)據(jù)匯總字段類 新建文件MyToDo.Share.Models.SummaryDto 添加匯總webapi接口 添加匯總接口 添加文

    2024年02月15日
    瀏覽(19)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記04-菜單導(dǎo)航

    添加文件與文件夾 添加文件夾 ? ./Extensions 添加文件 類型:用戶控件 ./Views/IndexView.xaml ./Views/MemoView.xaml ./Views/TodoView.xaml ./Views/SettingsView.xaml ./ViewModels/IndexViewModel.cs ./ViewModels/IndexViewModel.cs ./ViewModels/IndexViewModel.cs ./ViewModels/IndexViewModel.cs ./Extensions/PrismManager.cs 建立View與Vie

    2024年02月16日
    瀏覽(17)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記26-首頁(yè)導(dǎo)航

    修改UI,添加單擊行為,并綁定導(dǎo)航命令 修改文件:Mytodo.Views.IndexView.xaml ,在導(dǎo)航梯形添加內(nèi)容 添加導(dǎo)航命令,并初始化 修改文件:indexviewmodel.cs 添加導(dǎo)航區(qū)域變量,并初始化 修改文件:indexviewmodel.cs 添加導(dǎo)航方法 TaskBars添加對(duì)應(yīng)的導(dǎo)航區(qū)域 修改OnNavigate方法 當(dāng)為“已完成

    2024年02月15日
    瀏覽(43)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記27-全局通知

    新建消息事件 添加文件:Mytodo.Common.Events.MessageModel.cs 注冊(cè)、發(fā)送提示消息 UI增加Snackbar 修改文件:Mytodo.Views.MainView.xaml 注冊(cè)消息 修改文件:Mytodo.Views.MainViewcs 構(gòu)造函數(shù)添加 要注意的是,我們要發(fā)送的是文本,所以,this.skbar.MessageQueue.Enqueue函數(shù)內(nèi)發(fā)送的是文本。 在需要的地

    2024年02月15日
    瀏覽(17)
  • WPF實(shí)戰(zhàn)學(xué)習(xí)筆記16-數(shù)據(jù)加載

    新建Update事件,增加Prism事件列表 新建文件Mytodo/Common/Events/UpdateLoadingEvent.cs 新建含加載窗體基類 新建文件Mytodo/ViewModels/NavigationViewModel.cs 建立數(shù)據(jù)加載窗體擴(kuò)展方法 新建文件Mytodo/Extensions/DialogExtension.cs 主窗口命名 修改文件Mytodo/Extensions/DialogExtension.cs 主窗口訂閱消息 修改文

    2024年02月15日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包