public async Task <ApiResult> Login(string username, string userpwd) { //加密后的密码 123456 =>sdlkfjkldsjidaifdaskfaj == sdlkfjkldsjidaifdaskfaj string pwd = MD5Helper.MD5Encrypt32(userpwd); //数据校验 var writer = await _iWriterInfoService.FindAsync(c => c.UserName == username && c.UserPwd == pwd); if (writer != null) { //登陆成功 var claims = new Claim[] { new Claim(ClaimTypes.Name, writer.Name), new Claim("Id", writer.Id.ToString()), new Claim("UserName", writer.UserName) //不能放敏感信息 }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("SDMC-CJAS1-SAD-DFSFA-SADHJVF-VF")); //issuer代表颁发Token的Web应用程序,audience是Token的受理者 var token = new JwtSecurityToken( issuer: "http://localhost:6060", audience: "http://localhost:5000", claims: claims, notBefore: DateTime.Now, expires: DateTime.Now.AddHours(1), signingCredentials: new SigningCredentials(key, SecurityAlgorithms.HmacSha256) ); var jwtToken = new JwtSecurityTokenHandler().WriteToken(token); return(ApiResultHelper.Success(jwtToken)); } else { return(ApiResultHelper.Error("账号或密码错误")); } }
public async Task <ApiResult> Create(string name, string username, string userpwd) { //数据校验 WriterInfo writer = new WriterInfo { Name = name, //加密密码 UserPwd = MD5Helper.MD5Encrypt32(userpwd), UserName = username }; //判断数据库中是否已经存在账号跟要添加的账号相同的数据 var oldWriter = await _iWriterInfoService.FindAsync(c => c.UserName == username); if (oldWriter != null) { return(ApiResultHelper.Error("账号已经存在")); } bool b = await _iWriterInfoService.CreateAsync(writer); if (!b) { return(ApiResultHelper.Error("添加失败")); } return(ApiResultHelper.Success(writer)); }
public async Task <ApiResult> Create(string name, string sex, string telnumber, string address, string units, string adminname, string adminpwd) { AdminInfo admin = new AdminInfo { Name = name, Sex = sex, TelNumber = telnumber, Address = address, Units = units, AdminName = adminname, AdminPwd = MD5Helper.MD5Encrypt32(adminpwd) //MD5加密 }; //判断数据库中是否已经存在账号跟要添加的账号相同的数据 var oldAdmin = await _iAdminInfoService.FindAsync(c => c.AdminName == adminname); if (oldAdmin != null) { return(ApiResultHelper.Error("账号已经存在")); } bool b = await _iAdminInfoService.CreateAsync(admin); if (!b) { return(ApiResultHelper.Error("添加失败")); } return(ApiResultHelper.Success(admin)); }
public async Task <ApiResult> Create(string name, string sex, string telnumber, string address, string units, string Counselorname, string Counselorpwd) { CounselorInfo Counselor = new CounselorInfo { Name = name, Sex = sex, TelNumber = telnumber, Address = address, Units = units, UserName = Counselorname, UserPwd = MD5Helper.MD5Encrypt32(Counselorpwd) //MD5加密 }; //判断数据库中是否已经存在账号跟要添加的账号相同的数据 var oldCounselor = await _iCounselorInfoService.FindAsync(c => c.UserName == Counselorname); if (oldCounselor != null) { return(ApiResultHelper.Error("账号已经存在")); } bool b = await _iCounselorInfoService.CreateAsync(Counselor); if (!b) { return(ApiResultHelper.Error("添加失败")); } return(ApiResultHelper.Success(Counselor)); }
public async Task <ApiResult> FindCounselor([FromServices] IMapper iMapper) { var Counselor = await _iCounselorInfoService.QueryAsync(); var counselorDTO = iMapper.Map <CounselorDTO>(Counselor); return(ApiResultHelper.Success(counselorDTO)); }
public async Task <ApiResult> FindAdmin([FromServices] IMapper iMapper) { var admin = await _iAdminInfoService.QueryAsync(); var adminDTO = iMapper.Map <AdminDTO>(admin); return(ApiResultHelper.Success(adminDTO)); }
public async Task <ApiResult> FindWriter([FromServices] IMapper iMapper, int id) { var writer = await _iWriterInfoService.FindAsync(id); var writerDTO = iMapper.Map <WriterDTO>(writer); return(ApiResultHelper.Success(writerDTO)); }
public async Task <ApiResult> Find([FromServices] IMapper iMapper) { int id = Convert.ToInt32(this.User.FindFirst("Id").Value); var admin = await _iAdminInfoService.FindAsync(id); var adminDTO = iMapper.Map <AdminDTO>(admin); return(ApiResultHelper.Success(adminDTO)); }
public async Task <ApiResult> Find([FromServices] IMapper iMapper) { int id = Convert.ToInt32(this.User.FindFirst("Id").Value); var Counselor = await _iCounselorInfoService.FindAsync(id); var counselorDTO = iMapper.Map <CounselorDTO>(Counselor); return(ApiResultHelper.Success(counselorDTO)); }
public async Task <ApiResult> Detele(int id) { bool b = await _iRoadInfoService.DeleteAsync(id); if (!b) { return(ApiResultHelper.Error("删除失败")); } return(ApiResultHelper.Success(b)); }
public async Task <ApiResult> Types() { var types = await _iTypeInfoService.QueryAsync(); if (types.Count == 0) { return(ApiResultHelper.Error("没有更多的类型")); } return(ApiResultHelper.Success(types)); }
public async Task <ActionResult <ApiResult> > Delete(int id) { bool b = await _iBlogNewsService.DeleteAsync(id); if (!b) { return(ApiResultHelper.Error("删除失败")); } return(ApiResultHelper.Success(b)); }
public async Task <ApiResult> GetNoticeInfo() { //int id = Convert.ToInt32(this.User.FindFirst("Id").Value); var data = await _iNoticeInfoService.QueryAsync(); if (data.Count == 0) { return(ApiResultHelper.Error("没有更多数据")); } return(ApiResultHelper.Success(data)); }
public async Task <ActionResult <ApiResult> > GetBlogNews() { int id = Convert.ToInt32(this.User.FindFirst("Id").Value); var data = await _iBlogNewsService.QueryAsync(c => c.WriterId == id); if (data == null) { return(ApiResultHelper.Error("没有更多的文章")); } return(ApiResultHelper.Success(data)); }
public async Task <ApiResult> Find() { int id = Convert.ToInt32(this.User.FindFirst("Id").Value); var data = await _iRoadInfoService.QueryAsync(c => c.CounselorId == id); if (data.Count == 0) { return(ApiResultHelper.Error("没有更多的数据")); } return(ApiResultHelper.Success(data)); }
public async Task <ApiResult> Edit(string name) { int id = Convert.ToInt32(this.User.FindFirst("Id").Value); var writer = await _iWriterInfoService.FindAsync(id); writer.Name = name; bool b = await _iWriterInfoService.EditAsync(writer); if (!b) { return(ApiResultHelper.Error("修改失败")); } return(ApiResultHelper.Success("修改成功")); }
public async Task <ApiResult> GetBlogNewsPage([FromServices] IMapper iMapper, int page, int size) { RefAsync <int> total = 0; var blognews = await _iBlogNewsService.QueryAsync(page, size, total); try { var blognewsDTO = iMapper.Map <List <BlogNewsDTO> >(blognews); return(ApiResultHelper.Success(blognewsDTO, total)); } catch (Exception) { return(ApiResultHelper.Error("AutoMapper映射错误")); } }
public async Task <ApiResult> FindAll([FromServices] IMapper iMapper, int page, int size) { RefAsync <int> total = 0; var road = await _iRoadInfoService.QueryAsync(page, size, total); try { var roadDTO = iMapper.Map <List <RoadDTO> >(road); return(ApiResultHelper.Success(roadDTO, total)); } catch (Exception) { return(ApiResultHelper.Error("AutoMapper映射错误")); } }
public async Task <ApiResult> Create(string location, string state) { RoadInfo road = new RoadInfo { Location = location, ReportTime = DateTime.Now, State = state, CounselorId = Convert.ToInt32(this.User.FindFirst("Id").Value) }; bool b = await _iRoadInfoService.CreateAsync(road); if (!b) { return(ApiResultHelper.Error("添加失败")); } return(ApiResultHelper.Success(road)); }
public async Task <ApiResult> Edit(int id, string name) { var type = await _iTypeInfoService.FindAsync(id); if (type == null) { return(ApiResultHelper.Error("没有找到该文章类型")); } type.Name = name; bool b = await _iTypeInfoService.EditAsync(type); if (!b) { return(ApiResultHelper.Error("修改失败")); } return(ApiResultHelper.Success(type)); }
public async Task <ApiResult> GetNoticeInfoPage([FromServices] IMapper iMapper, int page, int size) { RefAsync <int> total = 0; var noticeinfo = await _iNoticeInfoService.QueryAsync(page, size, total); try { var data = await _iBlogNewsService.QueryAsync(c => c.WriterId == id); var noticeDTO = iMapper.Map <List <NoticeDTO> >(noticeinfo); return(ApiResultHelper.Success(noticeDTO, total)); } catch (Exception) { return(ApiResultHelper.Error("AutoMapper映射错误")); } }
public async Task <ApiResult> AdminEdit(int id, string location, string state) { var road = await _iRoadInfoService.FindAsync(id); if (road == null) { return(ApiResultHelper.Error("没有找到该条数据")); } road.Location = location; road.State = state; bool b = await _iRoadInfoService.EditAsync(road); if (!b) { return(ApiResultHelper.Error("修改失败")); } return(ApiResultHelper.Success(road)); }
public async Task <ApiResult> Edit(string name, string sex, string telnumber, string address, string units) { int id = Convert.ToInt32(this.User.FindFirst("Id").Value); var Counselor = await _iCounselorInfoService.FindAsync(id); Counselor.Name = name; Counselor.Sex = sex; Counselor.TelNumber = telnumber; Counselor.Address = address; Counselor.Units = units; bool b = await _iCounselorInfoService.EditAsync(Counselor); if (!b) { return(ApiResultHelper.Error("修改失败")); } return(ApiResultHelper.Success(Counselor)); }
public async Task <ApiResult> EditAdmin(int id, string name, string sex, string telnumber, string address, string units) { int findid = id; var admin = await _iAdminInfoService.FindAsync(findid); admin.Name = name; admin.Sex = sex; admin.TelNumber = telnumber; admin.Address = address; admin.Units = units; bool b = await _iAdminInfoService.EditAsync(admin); if (!b) { return(ApiResultHelper.Error("修改失败")); } return(ApiResultHelper.Success(admin)); }
public async Task <ApiResult> EditCounselor(int id, string name, string sex, string telnumber, string address, string units) { int findId = id; var Counselor = await _iCounselorInfoService.FindAsync(findId); Counselor.Name = name; Counselor.Sex = sex; Counselor.TelNumber = telnumber; Counselor.Address = address; Counselor.Units = units; bool b = await _iCounselorInfoService.EditAsync(Counselor); if (!b) { return(ApiResultHelper.Error("修改失败")); } return(ApiResultHelper.Success(Counselor)); }
public async Task <ActionResult <ApiResult> > Edit(int id, string title, string content, int typeid) { var blogNews = await _iBlogNewsService.FindAsync(id); if (blogNews == null) { return(ApiResultHelper.Error("没有找到该文章")); } blogNews.Title = title; blogNews.Content = content; blogNews.TypeId = typeid; bool b = await _iBlogNewsService.EditAsync(blogNews); if (!b) { return(ApiResultHelper.Error("修改失败")); } return(ApiResultHelper.Success(blogNews)); }
public async Task <ApiResult> Create(string name) { #region 数据验证 if (String.IsNullOrWhiteSpace(name)) { return(ApiResultHelper.Error("文章类型名不能为空")); } #endregion TypeInfo type = new TypeInfo { Name = name }; bool b = await _iTypeInfoService.CreateAsync(type); if (!b) { return(ApiResultHelper.Error("添加失败")); } return(ApiResultHelper.Success(b)); }
public async Task <ActionResult <ApiResult> > Create(string title, string content, int typeid) { //数据验证 BlogNews blogNews = new BlogNews { BrowseCount = 0, Content = content, LikeCount = 0, Time = DateTime.Now, Title = title, TypeId = typeid, WriterId = Convert.ToInt32(this.User.FindFirst("Id").Value) }; bool b = await _iBlogNewsService.CreateAsync(blogNews); if (!b) { return(ApiResultHelper.Error("添加失败,服务器发生错误")); } return(ApiResultHelper.Success(blogNews)); }
public async Task <ApiResult> CounselorEdit(int id, string location, string state) { var road = await _iRoadInfoService.FindAsync(id); if (road == null) { return(ApiResultHelper.Error("没有找到该条数据")); } if (road.CounselorId != Convert.ToInt32(this.User.FindFirst("Id").Value)) { return(ApiResultHelper.Error("你没有权限修改该条数据")); } road.Location = location; road.State = state; bool b = await _iRoadInfoService.EditAsync(road); if (!b) { return(ApiResultHelper.Error("修改失败")); } return(ApiResultHelper.Success(road)); }
public async Task <ActionResult <ApiResult> > Edit(int id, string title, string category, IFormFile file) { string webRootPath = _webHostEnvironment.WebRootPath; // wwwroot 文件夹 string uploadPath = Path.Combine("uploads", DateTime.Now.ToString("yyyyMMdd")); string dirPath = Path.Combine(webRootPath, uploadPath); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } string fileExt = Path.GetExtension(file.FileName).Trim('.'); //文件扩展名,不含“.” string newFileName = Guid.NewGuid().ToString().Replace("-", "") + "." + fileExt; //随机生成新的文件名 var fileFolder = Path.Combine(dirPath, newFileName); using (var stream = new FileStream(fileFolder, FileMode.Create)) { await file.CopyToAsync(stream); } string url = $@"\{uploadPath}\{newFileName}"; var noticeinfo = await _iNoticeInfoService.FindAsync(id); if (noticeinfo == null) { return(ApiResultHelper.Error("没有找到该通告")); } noticeinfo.Title = title; noticeinfo.Category = category; noticeinfo.Path = "localhost:5000" + url; bool b = await _iNoticeInfoService.EditAsync(noticeinfo); if (!b) { return(ApiResultHelper.Error("修改失败")); } return(ApiResultHelper.Success(noticeinfo)); }