public async Task <Response <bool> > Update(GameDto game) { var response = new Response <bool>(); try { // Mapping GameDto into Game entity var gameEntity = _mapper.Map <Game>(game); // Persisting entity and returning await _gameDomainService.Update(gameEntity); return(response.SetResult(true)); } catch (EntityNotExistsException) { return(response.SetNotFound(Resources.CantFounGameWithGivenId)); } catch (Exception ex) { Console.Write(ex.Message); return(response.SetInternalServerError(Resources.UnexpectedErrorWhileUpdatingGame)); } }
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 Update(GameDto dto) { _gameDomainService.Update(MapFromDtoToEntity(dto, DtoToDomainEnum.Game)); _gameDomainService.SaveChange(); }