public IActionResult Add([FromBody] EngineerInfo Newengineer) { var user = this.GetAuthUser(); if (user.Power != 1) { return(StatusCode(403)); } try { _context.Add(Newengineer); _context.SaveChanges(); } catch (Exception e) { return(Json(new { success = false })); } //成功时执行以下操作 //获取header中的token var providedApiKey = long.Parse(Request.Headers["Authorization"].ToString()); //获取日志信息 ModifyInfo NewModify = modify.AddInfo(DateTime.Now, "Engineer", 1, providedApiKey); //保存日志信息 _context.Add(NewModify); return(Json(new { success = _context.SaveChanges() > 0 })); }
public IActionResult Add([FromBody] UserInfo NewUser) { var state = GetById(NewUser.ID); if (state != null) { return(Json(new { sucess = false })); } var user = this.GetAuthUser(); if (user.Power != 2) { return(StatusCode(403)); } _context.Add(NewUser); try { var providedApiKey = long.Parse(Request.Headers["Authorization"].ToString()); //获取日志信息 ModifyInfo NewModify = modify.AddInfo(DateTime.Now, "User", 1, providedApiKey); //保存日志信息 _context.Add(NewModify); _context.SaveChanges(); } catch (Exception e) { return(Json(new { sucess = false })); } return(Json(new { sucess = true })); }