public IActionResult Update(int id, [FromBody] RightsToUserViewModel rightToUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } RightsToUser _rightToUserDb = _rightsToUserRepository.GetSingle(id); if (_rightToUserDb == null) { return(NotFound()); } else { _rightToUserDb.IdRight = rightToUser.IdRight; _rightToUserDb.IdUser = rightToUser.IdUser; } _rightsToUserRepository.Commit(); rightToUser = Mapper.Map <RightsToUser, RightsToUserViewModel>(_rightToUserDb); return(new NoContentResult()); }
public IActionResult CheckIfUserHasRight(int idRight, int idUser) { RightsToUser _rightToUser = _rightsToUserRepository.GetSingle(r => r.IdRight == idRight && r.IdUser == idUser); if (_rightToUser != null) { RightsToUserViewModel _rightsToUserViewModel = Mapper.Map <RightsToUser, RightsToUserViewModel>(_rightToUser); return(new OkObjectResult(_rightsToUserViewModel)); } else { return(new OkObjectResult("false")); } }
public IActionResult Create([FromBody] RightsToUserViewModel rightToUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } RightsToUser _newRightToUser = Mapper.Map <RightsToUserViewModel, RightsToUser>(rightToUser); _rightsToUserRepository.Add(_newRightToUser); _rightsToUserRepository.Commit(); rightToUser = Mapper.Map <RightsToUser, RightsToUserViewModel>(_newRightToUser); return(new OkObjectResult(rightToUser)); }