Esempio n. 1
0
        public IActionResult Post([FromBody] User_UserRolePostModel user_userRolePostModel)
        {
            User   curentUserLogIn = userService.GetCurrentUser(HttpContext);
            string roleNameLoged   = HttpContext.User.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Role).Value;

            string curentUserRoleName = user_userRoleService.GetUserRoleNameById(user_userRolePostModel.UserId);


            if (roleNameLoged.Equals("UserManager"))
            {
                var anulUserRegistered = curentUserLogIn.DataRegistered;                                //data inregistrarii
                var curentMonth        = DateTime.Now;                                                  //data curenta
                var nrLuni             = curentMonth.Subtract(anulUserRegistered).Days / (365.25 / 12); //diferenta in luni dintre datele transmise

                if (nrLuni >= 6)
                {
                    string currentRoleName = user_userRoleService.GetUserRoleNameById(user_userRolePostModel.UserId);

                    if (currentRoleName.Equals("Admin"))
                    {
                        return(Forbid("You don`t have the right role for this action!"));
                    }

                    if ((currentRoleName.Equals("UserManager") | currentRoleName.Equals("Regular")) && user_userRolePostModel.UserRoleName.Equals("Admin"))
                    {
                        return(Forbid("You don`t have the right role for this action!"));
                    }
                }
                else
                {
                    return(Forbid("Your UserManager is not more than 6 month"));
                }
            }
            user_userRoleService.Create(user_userRolePostModel);
            return(Ok());
        }
 public void Post([FromBody] User_UserRolePostModel user_userRolePostModel)
 {
     user_userRoleService.Create(user_userRolePostModel);
 }