using Manganese.Text; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Components.Routing; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using System.Security.Claims; namespace asg_form.Controllers { public class comform : ControllerBase { private readonly RoleManager roleManager; private readonly UserManager userManager; public comform( RoleManager roleManager, UserManager userManager) { this.roleManager = roleManager; this.userManager = userManager; } [Route("api/v1/comform")] [HttpPost] [Authorize] public async Task> getschedle_c([FromBody]req_com_form req) { long id = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value.ToInt64(); var user = await userManager.Users.FirstAsync(a=>a.Id==id); TestDbContext testDb = new TestDbContext(); var result = new com_form { Com_Email = req.Com_Email, Com_Cocial_media = req.Com_Cocial_media, Com_qq = req.Com_qq, User = user, Status = 0, introduction = req.introduction }; testDb.com_Forms.Add(result); await testDb.SaveChangesAsync(); return Ok("成功!"); } [Route("api/v1/admin/comform")] [HttpGet] [Authorize] public async Task> getschedle_c(short page, short page_long = 10) { if (this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) { int a = userManager.Users.Count(); int b = page_long * page; if (page_long * page > a) { b = a; } TestDbContext testDb = new TestDbContext(); var comform = testDb.com_Forms.Skip(page_long * page - page_long).Take(page_long).Include(a => a.User).Select(a => new {a.Id,a.idv_id,a.Status,a.introduction,a.Com_Cocial_media,a.Com_Email,a.Com_qq,a.User.chinaname}).ToList(); return comform.ToString(); } return BadRequest(new error_mb { code = 400, message = "没有管理员,无法获取" }); } [Route("api/v1/admin/comform_ok")] [HttpGet] [Authorize] public async Task> ok_comform(long comform_id) { if (this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) { TestDbContext testDb = new TestDbContext(); var comform = await testDb.com_Forms.Include(a=>a.User).FirstAsync(a=>a.Id == comform_id); comform.Status = 1; var ouser = comform.User; ouser.officium = "Commentator"; await userManager.UpdateAsync(ouser); admin.SendEmail(ouser.Email, "ASG赛事组", $@"
{ouser.chinaname} ,欢迎加入ASG赛事组。
欢迎
欢迎{ouser.chinaname}加入ASG赛事组。
你的职位已经被设置为Commentator。
  • 对此次执行有疑问请联系我们的QQ:2667210109。
  • 请不要回复此邮件。如果你需要帮助,请联系我们。
  • 请加入对应职位的群聊。
版权所有 ASG赛事官网
"); return "成功!"; } return BadRequest(new error_mb { code = 400, message = "没有管理员,无法设置" }); } [Route("api/v1/admin/comform_no")] [HttpGet] [Authorize] public async Task> no_comform(long comform_id) { if (this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) { TestDbContext testDb = new TestDbContext(); var comform = await testDb.com_Forms.Include(a => a.User).FirstAsync(a => a.Id == comform_id); comform.Status = 2; var ouser = comform.User; admin.SendEmail(ouser.Email, "ASG赛事组", $@"很抱歉,你的解说申请未通过"); return "成功!"; } return BadRequest(new error_mb { code = 400, message = "没有管理员,无法设置" }); } public class req_com_form { public string Com_Email { get; set; } public string? Com_Cocial_media { get; set; } public string idv_id { get; set; } public string introduction { get; set; } public string Com_qq { get; set; } } public class com_form { public long Id { get; set; } public User User { get; set; } public string Com_Email { get; set; } public string? Com_Cocial_media { get; set; } public string idv_id { get; set; } public string introduction { get; set; } public string Com_qq { get; set; } public int Status { get; set; } } } }