public OperationResultVo <Guid> Save(Guid currentUserId, GameViewModel viewModel) { int pointsEarned = 0; try { Game game; Team newTeam = null; bool createTeam = viewModel.TeamId == Guid.Empty; ISpecification <GameViewModel> spec = new UserMustBeAuthenticatedSpecification <GameViewModel>(currentUserId) .And(new UserIsOwnerSpecification <GameViewModel>(currentUserId)); if (!spec.IsSatisfiedBy(viewModel)) { return(new OperationResultVo <Guid>(spec.ErrorMessage)); } if (createTeam) { newTeam = teamDomainService.GenerateNewTeam(currentUserId); newTeam.Name = String.Format("Team {0}", viewModel.Title); teamDomainService.Add(newTeam); } viewModel.ExternalLinks.RemoveAll(x => String.IsNullOrWhiteSpace(x.Value)); Game existing = gameDomainService.GetById(viewModel.Id); if (existing != null) { game = mapper.Map(viewModel, existing); } else { game = mapper.Map <Game>(viewModel); } if (viewModel.Id == Guid.Empty) { gameDomainService.Add(game); pointsEarned += gamificationDomainService.ProcessAction(viewModel.UserId, PlatformAction.GameAdd); } else { gameDomainService.Update(game); } unitOfWork.Commit(); viewModel.Id = game.Id; if (createTeam && newTeam != null) { game.TeamId = newTeam.Id; gameDomainService.Update(game); unitOfWork.Commit(); } return(new OperationResultVo <Guid>(game.Id, pointsEarned)); } catch (Exception ex) { return(new OperationResultVo <Guid>(ex.Message)); } }
public void Add(GameDto dto) { _gameDomainService.Add(MapFromDtoToEntity(dto, DtoToDomainEnum.Game)); _gameDomainService.SaveChange(); }