private bool IsValidPlacement(string caller, User currentUser, PlacementDto placementDto) { if (placementDto == null) { _logger.LogWarning($"{caller} called with empty PlacementDto."); return(false); } if (_userService.GetUser(placementDto.UserId) == null) { _logger.LogWarning($"{caller} called with invalid userId of {placementDto.UserId}."); return(false); } if (currentUser.Id != placementDto.UserId && !currentUser.IsSystemUser) { _logger.LogWarning($"{caller} called by user {currentUser.Id} attempting to create/update a placement for {placementDto.UserId} which is forbidden as they are not authorised."); return(false); } if (string.IsNullOrWhiteSpace(placementDto.Title)) { _logger.LogWarning($"{caller} called with invalid title."); return(false); } if (placementDto.Start == DateTime.MinValue) { _logger.LogWarning($"{caller} called with invalid start date of {placementDto.Start}."); return(false); } if (placementDto.End == DateTime.MinValue) { _logger.LogWarning($"{caller} called with invalid end date of {placementDto.Start}."); return(false); } return(true); }
public PlacementDto UpdatePlacement(User user, PlacementDto placementDto) { var placementAggregate = _repository.GetById <PlacementAggregate>(placementDto.Id); placementAggregate.Update(placementDto.Title, placementDto.Start, placementDto.End, placementDto.Reference, user.Id); _repository.Save(placementAggregate, commitId: Guid.NewGuid(), updateHeaders: null); return(placementDto); }
public PlacementDto CreatePlacement(User user, PlacementDto placementDto) { var id = Guid.NewGuid(); var placementAggregate = (PlacementAggregate)_factory.Build(typeof(PlacementAggregate), id, null); placementAggregate.OnFirstCreated(); placementAggregate.Create(placementDto.UserId, placementDto.Title, placementDto.Start, placementDto.End, placementDto.Reference, user.Id); _repository.Save(placementAggregate, commitId: Guid.NewGuid(), updateHeaders: null); placementDto.Id = id; placementDto.FullyQualifiedTitle = PlacementAggregate.GetFullyQualifiedTitle(placementDto.Title, placementDto.Start, placementDto.End); return(placementDto); }
// POST placements/{placementId}/update // Update the placement for the user. public async Task <ActionResult> UpdatePlacement([FromBody] PlacementDto placementDto) { var currentUser = await _userService.GetUserAsync(User); if (!(IsValidPlacement("UpdatePlacement", currentUser, placementDto))) { return(new BadRequestResult()); } // Update the placement. _placementService.UpdatePlacement(currentUser, placementDto); return(Json(placementDto)); }
public PlacementCommissionDto() { Placement = new PlacementDto(); User = new UserDto(); }