public bool UpdatePlayer(PlayerPatchDto dto, Guid id) { var player = Session.Get <PlayerModel>(id); if (player == null) { return(false); } var groupDisjunction = new Disjunction(); foreach (var groupName in dto.GroupNames) { groupDisjunction.Add(Restrictions.InsensitiveLike(Projections.Property <GroupModel>(p => p.Players), dto.GroupNames)); } var groups = Session.QueryOver <GroupModel>() .Where(groupDisjunction).Future().ToList(); using (var transaction = Session.BeginTransaction()) { player.FirstName = dto.FirstName; player.LastName = dto.LastName; player.Email = dto.Email; player.Rating = dto.Rating; player.IsActive = dto.IsActive; player.Groups = groups; Session.Update(player); transaction.Commit(); } return(true); }
public IHttpActionResult Put([FromUri] Guid id, PlayerPatchDto dto) { var result = _playerRepository.UpdatePlayer(dto, id); if (result) { return(Ok()); } return(NotFound()); }