コード例 #1
0
 [HttpPost("EditByIDForUser")]                                                            //Thay đổi comment truyền vào Id của comment và Body comment
 public IActionResult EditByIDForUser(string id, [FromBody] Comment comment)
 {
     try{
         var           identity = HttpContext.User.Identity as ClaimsIdentity;            //khai báo biến danh tính của token
         IList <Claim> claim    = identity.Claims.ToList();                               //Danh sách các biến trong identity
         string        Email    = claim[1].Value;                                         //Email của token
         User          userinfo = new User();                                             //Khai bao biến thông tin người dùng
         if (userinfo.kiemtrathoigianlogin(DateTime.Parse(claim[0].Value)) == true)       //kiểm tra thời gian đăng nhập còn không
         {
             Comment comment1 = new Comment();                                            //Khai báo biến model Comment
             var     a        = comment1.getbyIdcomment(id);                              //lấy dữ liệu comment
             if (a.UserID == userinfo.GetIDToken(Email))
             {
                 comment1.AddbyidToFireBase(id, comment);
                 return(Ok(new[] { "sửa thành công" }));
             }
             return(Ok(new[] { "Không có quyền" }));
         }
         else
         {
             return(Ok(new[] { "Bạn cần đăng nhập" }));
         }
     }
     catch
     {
         return(Ok(new[] { "Error" }));
     }
 }
コード例 #2
0
 [HttpPost("EditByID")]                                                           //Chỉnh sửa thông tin comment
 public IActionResult EditByID(string id, [FromBody] Comment comment)
 {
     try{
         var           identity = HttpContext.User.Identity as ClaimsIdentity;    //khai báo biến danh tính của token
         IList <Claim> claim    = identity.Claims.ToList();                       //Danh sách các biến trong identity
         string        Email    = claim[1].Value;                                 //Email của token
         User          userinfo = new User();                                     //Khai bao biến thông tin người dùng
         if (userinfo.kiemtrathoigianlogin(DateTime.Parse(claim[0].Value)) == true &&
             userinfo.checkAdmin(Email) == true)                                  //kiểm tra thời gian đăng nhập còn không và có phải là admin không
         {
             Comment comment1 = new Comment();                                    //khai báo model comment
             comment1.AddbyidToFireBase(id, comment);                             //Update data
             return(Ok(new[] { "sửa thành công" }));
         }
         else
         {
             return(Ok(new[] { "Bạn cần đăng nhập" }));
         }
     }
     catch {
         return(Ok(new[] { "Error" }));
     }
 }