public async Task <IActionResult> Create([FromBody] CreateRosterRequest rosterRequest) { var loggedUserId = HttpContext.GetUserId(); var roster = new Roster { Id = Guid.NewGuid().ToString(), CreatorId = loggedUserId, CreatorName = rosterRequest.CreatorName, Name = rosterRequest.Name, Description = rosterRequest.Description }; var userRosterAccess = new UserRosterAccess { Id = Guid.NewGuid(), CreatorId = loggedUserId, IsOwner = true, IsModerator = false, RosterId = roster.Id, UserId = loggedUserId, CreatedOn = DateTime.UtcNow }; await _rosterService.CreateRosterAsync(roster); await _rosterAccessService.CreateRosterAccessAsync(userRosterAccess); var locationUri = _uriService.GetRosterUri(roster.Id.ToString()); return(Created(locationUri, _mapper.Map <RosterResponse>(roster))); }
public async Task <IActionResult> Create([FromBody] CreateRosterAccessRequest request) { var loggedUserId = HttpContext.GetUserId(); var access = await _rosterAccessService.GetRosterAccessAsync(GetBy.RosterId, loggedUserId, request.RosterId); if (access is null) { return(CreateErrorResponse(Status.Forbidden)); } if (access.UserId == request.UserId) { return(CreateErrorResponse(Status.BadRequest, "You already have access to this roster.")); } var newAccess = new UserRosterAccess { Id = Guid.NewGuid(), UserId = request.UserId, RosterId = request.RosterId, CreatorId = loggedUserId, IsModerator = request.IsModerator, CreatedOn = DateTime.UtcNow }; await _rosterAccessService.CreateRosterAccessAsync(newAccess); var locationUri = _uriService.GetRosterAccessUri(newAccess.Id.ToString()); return(Created(locationUri, _mapper.Map <RosterAccessResponse>(newAccess))); }
public async Task <bool> CreateRosterAccessAsync(UserRosterAccess userRosterAccess) { var exists = _context.UserRosterAccessesDto.Any(r => r.RosterId == userRosterAccess.RosterId && r.UserId == userRosterAccess.UserId); if (exists) { return(false); } await _context.UserRosterAccessesDto.AddAsync(_mapper.Map <UserRosterAccessDto>(userRosterAccess)); return(await _context.SaveChangesAsync() > 0); }