Ejemplo n.º 1
0
        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)));
        }