assign
This commit is contained in:
		
							parent
							
								
									3f58c35d60
								
							
						
					
					
						commit
						421dc173cc
					
				
							
								
								
									
										125
									
								
								asg_form/Controllers/AssignmentController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										125
									
								
								asg_form/Controllers/AssignmentController.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,125 @@
 | 
				
			|||||||
 | 
					using AngleSharp.Text;
 | 
				
			||||||
 | 
					using asg_form.Controllers.Hubs;
 | 
				
			||||||
 | 
					using asg_form.Controllers.Store;
 | 
				
			||||||
 | 
					using Manganese.Array;
 | 
				
			||||||
 | 
					using Microsoft.AspNetCore.Authorization;
 | 
				
			||||||
 | 
					using Microsoft.AspNetCore.Identity;
 | 
				
			||||||
 | 
					using Microsoft.AspNetCore.Mvc;
 | 
				
			||||||
 | 
					using Microsoft.AspNetCore.SignalR;
 | 
				
			||||||
 | 
					using NPOI.HPSF;
 | 
				
			||||||
 | 
					using System.Security.Claims;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace asg_form.Controllers
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public class TaskDB
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public long id { get; set; }
 | 
				
			||||||
 | 
					        public string userId { get; set; }
 | 
				
			||||||
 | 
					        public string taskName { get; set; }
 | 
				
			||||||
 | 
					        public string taskDescription {  get; set; }
 | 
				
			||||||
 | 
					        public string status { get; set; }
 | 
				
			||||||
 | 
					        public long money { get; set; }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    public class TaskCreate
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        public string UserId { get; set; }
 | 
				
			||||||
 | 
					        public string TaskName { get; set; }
 | 
				
			||||||
 | 
					        public string TaskDescription { get; set; }
 | 
				
			||||||
 | 
					        public long Money { get; set; }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    public class AssignmentController : ControllerBase
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        private readonly RoleManager<Role> roleManager;
 | 
				
			||||||
 | 
					        private readonly UserManager<User> userManager;
 | 
				
			||||||
 | 
					        public AssignmentController(
 | 
				
			||||||
 | 
					            RoleManager<Role> roleManager, UserManager<User> userManager)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            this.roleManager = roleManager;
 | 
				
			||||||
 | 
					            this.userManager = userManager;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        [Route("api/v1/admin/Task")]
 | 
				
			||||||
 | 
					        [HttpPost]
 | 
				
			||||||
 | 
					        [Authorize]
 | 
				
			||||||
 | 
					        public async Task<ActionResult<string>> PubTask([FromBody] TaskCreate taskinfo)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin"))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return Ok(new error_mb { code = 401, message = "无权访问" });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            using (TestDbContext sub = new TestDbContext())
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                var task = new TaskDB
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    userId = taskinfo.UserId,
 | 
				
			||||||
 | 
					                    taskName = taskinfo.TaskName,
 | 
				
			||||||
 | 
					                    taskDescription = taskinfo.TaskDescription,
 | 
				
			||||||
 | 
					                    money = taskinfo.Money,
 | 
				
			||||||
 | 
					                    status = "0",
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					                sub.T_Task.Add(task);
 | 
				
			||||||
 | 
					                await sub.SaveChangesAsync();
 | 
				
			||||||
 | 
					                return Ok(taskinfo);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Route("api/v1/admin/Task")]
 | 
				
			||||||
 | 
					        [HttpDelete]
 | 
				
			||||||
 | 
					        [Authorize]
 | 
				
			||||||
 | 
					        public async Task<ActionResult<object>> DelTask([FromQuery]long id)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin"))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return Ok(new error_mb { code = 401, message = "无权访问" });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            using (TestDbContext sub = new TestDbContext())
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                sub.T_Task.Remove(sub.T_Task.Find(id));
 | 
				
			||||||
 | 
					                await sub.SaveChangesAsync();
 | 
				
			||||||
 | 
					                return Ok("ok");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        public class Click_done
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            public string userId { get; set; }
 | 
				
			||||||
 | 
					            public long id { get; set; }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Route("api/v1/Task")]
 | 
				
			||||||
 | 
					        [HttpGet]
 | 
				
			||||||
 | 
					        [Authorize]
 | 
				
			||||||
 | 
					        public async Task<ActionResult<object>> CekTask([FromBody] Click_done msg)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            string userId = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
 | 
				
			||||||
 | 
					            var user = await userManager.FindByIdAsync(userId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            using (TestDbContext sub = new TestDbContext())
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                var task = sub.T_Task.Find(msg.id);
 | 
				
			||||||
 | 
					                task.status = "1";
 | 
				
			||||||
 | 
					                await sub.SaveChangesAsync();
 | 
				
			||||||
 | 
					                return Ok(task);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Route("api/v1/admin/Task/Done")]
 | 
				
			||||||
 | 
					        [HttpGet]
 | 
				
			||||||
 | 
					        [Authorize]
 | 
				
			||||||
 | 
					        public async Task<ActionResult<object>> FinishTask([FromBody] Click_done msg)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            string userId = this.User.FindFirst(ClaimTypes.NameIdentifier)!.Value;
 | 
				
			||||||
 | 
					            var user = await userManager.FindByIdAsync(userId);
 | 
				
			||||||
 | 
					            if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin"))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return Ok(new error_mb { code = 401, message = "无权访问" });
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            using (TestDbContext sub = new TestDbContext())
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                var task = sub.T_Task.Find(msg.id);
 | 
				
			||||||
 | 
					                task.status = "1";
 | 
				
			||||||
 | 
					                await sub.SaveChangesAsync();
 | 
				
			||||||
 | 
					                return Ok(task);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -204,7 +204,7 @@ namespace asg_form.Controllers
 | 
				
			|||||||
        public DbSet<StoreDB> T_Store { get; set; }
 | 
					        public DbSet<StoreDB> T_Store { get; set; }
 | 
				
			||||||
        public DbSet<StoreinfoDB> T_Storeinfo { get; set; }
 | 
					        public DbSet<StoreinfoDB> T_Storeinfo { get; set; }
 | 
				
			||||||
        public DbSet<T_config> T_config { get; set; }
 | 
					        public DbSet<T_config> T_config { get; set; }
 | 
				
			||||||
 | 
					        public DbSet<TaskDB> T_Task { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 | 
					        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user