diff --git a/asg_form/Controllers/Com.cs b/asg_form/Controllers/Com.cs index a4a1018..b9b3ad0 100644 --- a/asg_form/Controllers/Com.cs +++ b/asg_form/Controllers/Com.cs @@ -1,4 +1,5 @@ using asg_form.Migrations; +using Manganese.Text; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; @@ -36,7 +37,7 @@ namespace asg_form.Controllers { TestDbContext testDb = new TestDbContext(); string chinaname = user.chinaname; - var teamgame = testDb.team_Games.Where(a => a.commentary.IndexOf(chinaname) >= 0).Select(a => new { a.id, a.team1_name, a.team2_name, a.bilibiliuri, a.commentary, a.referee ,a.opentime}).ToList(); + var teamgame = testDb.team_Games.Where(a => a.commentary.IndexOf(chinaname) >= 0).Select(a => new { a.id, a.team1_name, a.team2_name, a.bilibiliuri, a.commentary, a.referee, a.opentime,a.tag,a.belong}).ToList(); return JsonConvert.SerializeObject(teamgame); } @@ -55,25 +56,16 @@ namespace asg_form.Controllers var user = await userManager.FindByIdAsync(id); if (user.officium == "Commentator") { + TestDbContext testDb = new TestDbContext(); string chinaname = user.chinaname; var teamgame = await testDb.team_Games.FirstAsync(a => a.id == gameid); - if (teamgame.commentary == "待公布") - { - List strings = new List - { - chinaname - }; - teamgame.commentary = string.Join(",", strings.ToArray()); - await testDb.SaveChangesAsync(); - } - else - { - var team_game = teamgame.commentary.Split(",").ToList(); - team_game.Add(chinaname); - teamgame.commentary = string.Join(",", team_game.ToArray()); - await testDb.SaveChangesAsync(); - } + var com = JsonConvert.DeserializeObject>(teamgame.commentary); + com.Add(new com_json { id = id.ToInt32(), chinaname = chinaname }); + teamgame.commentary = JsonConvert.SerializeObject(com); + await testDb.SaveChangesAsync(); + user.Integral = user.Integral+10; + await userManager.UpdateAsync(user); try { await MessageManager.SendGroupMessageAsync("870248618", $"解说:\r\n{chinaname}\r\n选择了比赛:\r\n{teamgame.team1_name} VS {teamgame.team2_name}"); @@ -87,6 +79,21 @@ namespace asg_form.Controllers return BadRequest(new error_mb { code = 400, message = $"你是{user.officium},你不是解说,无法操作" }); } + public class com_json + { + /// + /// + /// + public int id { get; set; } + /// + /// 老恐龙 + /// + public string chinaname { get; set; } + } + + + + /// /// 取消选班 @@ -105,14 +112,17 @@ namespace asg_form.Controllers TestDbContext testDb = new TestDbContext(); string chinaname = user.chinaname; var teamgame = await testDb.team_Games.FirstAsync(a => a.id == gameid); - var team_game = teamgame.commentary.Split(",").ToList(); - team_game.Remove(chinaname); - teamgame.commentary = string.Join(",", team_game.ToArray()); - if (teamgame.commentary=="") - { - teamgame.commentary = "待公布"; + var com = JsonConvert.DeserializeObject>(teamgame.commentary); + com.Remove(com.First(a => a.id == id.ToInt32())); + try{ + user.Integral = cut_value((long)user.Integral); + await userManager.UpdateAsync(user); } - + catch{ + return BadRequest(new error_mb { code = 400, message = $"你的金钱无法满足你完成以下操作" }); + + } + teamgame.commentary = JsonConvert.SerializeObject(com); await testDb.SaveChangesAsync(); return "成功"; } @@ -125,12 +135,34 @@ namespace asg_form.Controllers public async Task> Search() { TestDbContext testDb = new TestDbContext(); - var team= await testDb.team_Games.Select(a => new {a.id,a.commentary,a.opentime,a.team1_name,a.team2_name,a.belong}).ToListAsync(); + var team = await testDb.team_Games.Select(a => new { a.id, a.commentary, a.opentime, a.team1_name, a.team2_name, a.belong }).ToListAsync(); var team1 = team.Where(a => a.commentary.Split(",").Length <= 1); - return JsonConvert.SerializeObject(team1); + return JsonConvert.SerializeObject(team1); } + [Route("api/v1/com/Integral/ranking")] + [HttpPost] + [Authorize] + [ResponseCache(Duration = 60)] + public async Task> ranking() + { + object user= await userManager.Users.OrderByDescending(a => a.Integral).Select(a=>new{a.Id,a.chinaname,a.Integral}).Take(10).ToListAsync(); + return user; + } + + public long cut_value(long value) + { + long _value = value; + value = value - 10; + if (value < 0) + { + throw new ArgumentException("你已经没钱啦!"); + + } + return value; + } + [Route("api/v1/com/")] [HttpGet] [Authorize] @@ -141,8 +173,8 @@ namespace asg_form.Controllers if (user.officium == "Commentator") { var chinaname = user.chinaname; - TestDbContext testDb=new TestDbContext(); - int a= await testDb.team_Games.CountAsync(a => a.commentary.IndexOf(chinaname) >= 0); + TestDbContext testDb = new TestDbContext(); + int a = await testDb.team_Games.CountAsync(a => a.commentary.IndexOf(id) >= 0); return a; } return BadRequest(new error_mb { code = 400, message = $"你是{user.officium},你不是解说,无法操作" }); @@ -150,5 +182,5 @@ namespace asg_form.Controllers } } - + diff --git a/asg_form/Controllers/Dbset.cs b/asg_form/Controllers/Dbset.cs index 90436c5..62383e5 100644 --- a/asg_form/Controllers/Dbset.cs +++ b/asg_form/Controllers/Dbset.cs @@ -1,4 +1,5 @@  +using asg_form.Controllers.Store; using asg_form.Model; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; @@ -52,7 +53,23 @@ namespace asg_form.Controllers } } - + public static class QueryableExtensions + { + public static IQueryable Paginate(this IQueryable query, int pageIndex, int pageSize) + { + return query.Skip(pageIndex * pageSize).Take(pageSize); + } + } + class STOREConfig : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("F_Store"); + builder.HasOne(c => c.Store).WithMany(a => a.buyer).IsRequired(); + + } + } + class newsConfig : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) @@ -163,7 +180,9 @@ namespace asg_form.Controllers public DbSet Champions { get; set; } public DbSet com_Forms { get; set; } public DbSet T_Friends { get; set; } - + public DbSet T_Store { get; set; } + public DbSet T_Storeinfo { get; set; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { string connStr = @"Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;TrustServerCertificate=true"; diff --git a/asg_form/Controllers/Store/StoreDB.cs b/asg_form/Controllers/Store/StoreDB.cs new file mode 100644 index 0000000..0962414 --- /dev/null +++ b/asg_form/Controllers/Store/StoreDB.cs @@ -0,0 +1,25 @@ +namespace asg_form.Controllers.Store +{ + public class StoreDB + { + public long id { get; set; } + public string Name { get; set; } + public long Price { get; set; } + + public string description { get; set; } + + public string information { get; set; } + public string Type { get; set; } + public List? buyer { get; set; }=new List(); + } + public class StoreinfoDB + { + public long id { get; set; } + public long buyerid { get; set; } + public StoreDB Store { get; set; } + + public bool isVerification { get; set; } + + + } +} diff --git a/asg_form/Controllers/Store/Storehttp.cs b/asg_form/Controllers/Store/Storehttp.cs new file mode 100644 index 0000000..920372c --- /dev/null +++ b/asg_form/Controllers/Store/Storehttp.cs @@ -0,0 +1,169 @@ +using Masuit.Tools; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using System.Security.Claims; + +namespace asg_form.Controllers.Store +{ + public class Storehttp : ControllerBase + { + private readonly RoleManager roleManager; + private readonly UserManager userManager; + public Storehttp( + RoleManager roleManager, UserManager userManager) + { + + this.roleManager = roleManager; + this.userManager = userManager; + } + + + + [Route("api/v1/admin/Store")] + [HttpPost] + [Authorize] + public async Task> AddStore([FromBody]StoreDB storeinfo) + { + if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) + { + return BadRequest(new error_mb { code = 400, message = "无权访问" }); + } + using (TestDbContext sb = new TestDbContext()) { + sb.T_Store.Add(storeinfo); + await sb.SaveChangesAsync(); + return Ok(storeinfo); + } + } + [Route("api/v1/admin/Store")] + [HttpDelete] + [Authorize] + public async Task> DelStore(long id) + { + if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) + { + return BadRequest(new error_mb { code = 400, message = "无权访问" }); + } + using (TestDbContext sb = new TestDbContext()) + { + sb.T_Store.Remove(sb.T_Store.Find(id)); + await sb.SaveChangesAsync(); + return Ok("ok"); + } + } + [Route("api/v1/admin/Store")] + [HttpPut] + [Authorize] + public async Task> putStore([FromBody] StoreDB storeinfo) + { + if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) + { + return BadRequest(new error_mb { code = 400, message = "无权访问" }); + } + using (TestDbContext sb = new TestDbContext()) + { + var a= await sb.T_Store.FindAsync(storeinfo.id); + a = storeinfo; + await sb.SaveChangesAsync(); + return Ok(storeinfo); + } + } + public long cut_value(long value,long money) + { + long _value = value; + value = value - money; + if (value < 0) + { + throw new ArgumentException("你已经没钱啦!"); + + } + return value; + } + [Route("api/v1/Store")] + [HttpGet] + [Authorize] + public async Task> GetStore() + { + + using (TestDbContext sb = new TestDbContext()) + { + var a= sb.T_Store.ToList().GroupBy(a => a.Type); + return Ok(a); + } + } + + /// + /// + /// + /// + /// + /// + /// 是否展示以及核销过的 + /// + [Route("api/v1/admin/Storeinfo")] + [HttpGet] + [Authorize] + public async Task> GetStoreinfo(bool showVerification,long? search_id,int pageindex=0,int pagesize=10) + { + if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin")) + { + return BadRequest(new error_mb { code = 400, message = "无权访问" }); + } + using (TestDbContext sb = new TestDbContext()) + { + var a = new Store_record(null,null); + IQueryable b; + if (showVerification) + { + b = sb.T_Storeinfo; + } + else + { + b = sb.T_Storeinfo.Where(a=>a.isVerification==false); + } + if (search_id == null) + { + return Ok(await b.Paginate(pageindex, pagesize).ToListAsync()) ; + } + else + { + return Ok(await b.Where(a=>a.buyerid==search_id).Paginate(pageindex, pagesize).ToListAsync()); + } + } + } + public record Store_record(long? allstort,List? Storeinfos); + [Route("api/v1/Store/Buy")] + [HttpGet] + [Authorize] + public async Task> BuyStore(long storeid) + { + string id = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value; + var user = await userManager.FindByIdAsync(id); + + if (user.officium != "Commentator") + { + return BadRequest(new error_mb { code = 400, message = $"你是{user.officium},你不是解说,无法操作" }); + + } + + using (TestDbContext sb = new TestDbContext()) + { + var stort= await sb.T_Store.FindAsync(storeid); + try + { + user.Integral = cut_value((long)user.Integral,stort.Price); + await userManager.UpdateAsync(user); + await sb.T_Storeinfo.AddAsync(new StoreinfoDB { buyerid = id.ToInt64(), Store = stort }); + await sb.SaveChangesAsync(); + return Ok("购买成功,请前往背包查看"); + } + catch + { + return BadRequest(new error_mb { code = 400, message = $"你的金钱无法满足你完成以下操作" }); + + } + } + } + } +} diff --git a/asg_form/Program.cs b/asg_form/Program.cs index 6fc3899..72af29e 100644 --- a/asg_form/Program.cs +++ b/asg_form/Program.cs @@ -21,7 +21,7 @@ using System.Text; Console.WriteLine("\n _____ _________ ________ \n / _ \\ / _____// _____/ \n / /_\\ \\ \\_____ \\/ \\ ___ \n/ | \\/ \\ \\_\\ \\\n\\____|__ /_______ /\\______ /\n \\/ \\/ \\/ \n__________ __ ___________ .___\n\\______ \\_____ ____ | | __\\_ _____/ ____ __| _/\n | | _/\\__ \\ _/ ___\\| |/ / | __)_ / \\ / __ | \n | | \\ / __ \\\\ \\___| < | \\ | \\/ /_/ | \n |______ /(____ /\\___ >__|_ \\/_______ /___| /\\____ | \n \\/ \\/ \\/ \\/ \\/ \\/ \\/ "); var builder = WebApplication.CreateBuilder(args); -builder.AddServiceDefaults(); +//builder.AddServiceDefaults(); // Add services to the container. @@ -137,7 +137,7 @@ services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) var app = builder.Build(); -app.MapDefaultEndpoints(); +//app.MapDefaultEndpoints(); app.UseCors(); // Configure the HTTP request pipeline. diff --git a/asg_form/User.cs b/asg_form/User.cs index 0ff3dff..cf6410b 100644 --- a/asg_form/User.cs +++ b/asg_form/User.cs @@ -1,4 +1,5 @@  +using System.ComponentModel; using asg_form.Controllers; using Microsoft.AspNetCore.Identity; @@ -7,6 +8,9 @@ namespace asg_form public class User : IdentityUser { public string? UserBase64 { get; set; } + + [DefaultValue(0)] + public long? Integral { get; set; } public DateTime CreationTime { get; set; } public form? haveform { get; set; } @@ -14,7 +18,10 @@ namespace asg_form public bool? isbooking { get; set; } public string? chinaname { get; set; } -public string? officium { get; set; } + public string? officium { get; set; } + + public int point { get; set; } + } public class Role : IdentityRole diff --git a/asg_form_houduan-main.zip b/asg_form_houduan-main.zip deleted file mode 100644 index 0e0261b..0000000 Binary files a/asg_form_houduan-main.zip and /dev/null differ