zoukankan      html  css  js  c++  java
  • NetCore3.1+Flurl..Http_FluentHttp 增删改查

    1 Nuget包  Flurl.Http
    View Code
     1         /// <summary>
     2         /// 显示学生列表
     3         /// </summary>
     4         /// <returns></returns>
     5         [HttpGet()]
     6         public async Task<IActionResult> DisplayStudentInfo()
     7         {
     8             Tuple<IEnumerable<StudentDto>, int> tuple = await "http://localhost:5173/api/StudentInfo/GetStudentAndClassInfo".GetJsonAsync<Tuple<IEnumerable<StudentDto>, int>>();
     9             return View(tuple);
    10         }
    View Code
     1         /// <summary>
     2         /// 异步添加学生信息
     3         /// </summary>
     4         /// <param name="studentInfo"></param>
     5         /// <returns></returns>
     6         [HttpPost()]
     7         public async Task<IActionResult> AddStudentInfo(StudentDto studentInfo)
     8         {
     9             var result = await "http://localhost:5173/api/StudentInfo/AddStudentInfoAsync".PostJsonAsync(studentInfo).ReceiveJson<int>();
    10 
    11             if (result>0)
    12             {
    13                 return RedirectToAction("DisplayStudentInfo");
    14             }
    15             return RedirectToAction("AddStudentInfo");
    16         }  
    View Code
     1         /// <summary>
     2         /// 删除学生信息
     3         /// </summary>
     4         /// <param name="id"></param>
     5         /// <returns></returns>
     6         public async Task<IActionResult> DeleteStudentInfoById(int id)
     7         {
     8             string url = "http://localhost:5173/api/StudentInfo/DeleteStudentInfoByIdAsync?id=" + id;
     9 
    10             var result = await url.DeleteAsync().ReceiveJson<int>();
    11 
    12             if (result > 0)
    13             {
    14                 return RedirectToAction("DisplayStudentInfo");
    15             }
    16 
    17             else
    18             {
    19                 return Json("DisplayStudentInfo");
    20             }
    21         }
    View Code
     1      /// <summary>
     2         /// 编辑学生信息
     3         /// </summary>
     4         /// <param name="id"></param>
     5         /// <returns></returns>
     6         [HttpGet]
     7         public async Task<IActionResult> GetStudentInfoById(int id)
     8         {
     9             IEnumerable<ClassInfoDto> classInfoDtos = await GetClassInfoDtoList();
    10 
    11             ViewBag.ClassInfoList = classInfoDtos;
    12 
    13             StudentDto studentDto = await $"http://localhost:5173/api/StudentInfo/GetStudentInfoByIdAsync/{id}".GetJsonAsync<StudentDto>() ;
    14 
    15             return View(studentDto);
    16         } 
    View Code
     1          /// <summary>
     2         /// 修改学生信息
     3         /// </summary>
     4         /// <param name="studentDto"></param>
     5         /// <returns></returns>
     6         [HttpPost]
     7         public async Task<IActionResult> UpdateStudentInfo(StudentDto studentDto)
     8         {
     9             var result = await "http://localhost:5173/api/StudentInfo/UpdateStudentInfoAsync".PutJsonAsync(studentDto).ReceiveJson<int>();
    10             if (result > 0)
    11             {
    12                 return RedirectToAction("DisplayStudentInfo");
    13             }
    14 
    15             else
    16             {
    17                 return RedirectToAction("DisplayStudentInfo");
    18             }
    19         } 
    View Code
  • 相关阅读:
    BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊
    算法笔记-- 二进制集合枚举子集 && 求子集和 && 求父集和
    BZOJ 1084: [SCOI2005]最大子矩阵
    BZOJ 1968: [Ahoi2005]COMMON 约数研究
    2018 German Collegiate Programming Contest (GCPC 18)
    Codeforces 1100 F
    算法笔记--极大极小搜索及alpha-beta剪枝
    2017 Russian Code Cup (RCC 17), Elimination Round D
    All You Can Code 2008 (Romanian Contest) A
    2016 Russian Code Cup (RCC 16), Final Round B
  • 原文地址:https://www.cnblogs.com/ABC-wangyuhan/p/14181945.html
Copyright © 2011-2022 走看看