public IActionResult Register([FromBody] DiscountType discountType) //Tạo loại khuyến mãi { string err = ""; 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 infoUser = new User(); //Khai bao biến thông tin người dùng if (infoUser.kiemtrathoigianlogin(DateTime.Parse(claim[0].Value)) == true) //kiểm tra thời gian đăng nhập còn không { if (infoUser.checkAdmin(Email) == true) //Kiểm tra có phải admin không { DiscountType discountType1 = new DiscountType(); //Khai báo biến Model DiscountType discountType.DiscountRule = "Admin"; discountType1.AddToFireBase(discountType); //Thêm data err = "Đăng ký thành công"; } else if (infoUser.checkOwner(Email) == true) //Kiểm tra có phải admin không { DiscountType discountType1 = new DiscountType(); //Khai báo biến Model DiscountType discountType.DiscountRule = "Owner"; discountType1.AddToFireBase(discountType); //Thêm data err = "Đăng ký thành công"; } else { err = "Bạn Không có quyền"; } } else { return(Ok(new[] { "Bạn cần đăng nhập" })); } } catch { err = "Error"; } return(Ok(new[] { err })); }