Beispiel #1
0
        [Route("~/api/users/chrole")]                                                     //suprascrie ruta prestabilita [Route("api/[controller]")]
        public IActionResult Post([FromBody] UserUserRolePostModel userUserRolePostModel) //pentru creare de UserUserRole cu legatura manytomany intre User si UserRole
        {
            User   curentUserLogIn = userService.GetCurentUser(HttpContext);
            string roleNameLoged   = HttpContext.User.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Role).Value;

            string curentUserRoleName = userUserRolesService.GetUserRoleNameById(userUserRolePostModel.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 activRoleName = userUserRolesService.GetUserRoleNameById(userUserRolePostModel.UserId);

                    if (activRoleName.Equals("Admin"))
                    {
                        return(Forbid("Nu ai Rolul necesar pentru aceasta operatie !"));
                    }

                    if ((activRoleName.Equals("UserManager") | activRoleName.Equals("Regular")) && userUserRolePostModel.UserRoleName.Equals("Admin"))
                    {
                        return(Forbid("Nu ai Rolul necesar pentru aceasta operatie !"));
                    }
                }
                else
                {
                    return(Forbid("Nu ai Vechimea necesara ca UserManager pentru aceasta operatie !"));
                }
            }

            userUserRolesService.Create(userUserRolePostModel);
            return(Ok());
        }
Beispiel #2
0
 public void Post([FromBody] UserUserRolePostModel userUserRolePostModel)
 {
     userUserRoleService.Create(userUserRolePostModel);
 }
 public void Post([FromBody] UserUserRolePostDTO userUserRolePostDTO)
 {
     userUserRoleService.Create(userUserRolePostDTO);
 }