예제 #1
0
        public async Task <IActionResult> Create([FromBody] CreateClubDto clubRequest)
        {
            if (clubRequest == null)
            {
                return(BadRequest());
            }

            var username = User.GetUsername();
            var user     = await _unitOfWork.UserRepository.GetUserByUsername(username);


            var club = new Club
            {
                Name      = clubRequest.Name,
                City      = clubRequest.City,
                State     = clubRequest.State,
                Intro     = clubRequest.Intro,
                AppUser   = user,
                AppUserID = user.Id,
                Events    =
                    new List <Event>
                {
                    new Event {
                        Title    = clubRequest.Events.Title,
                        Location = clubRequest.Events.Location,
                        Date     = clubRequest.Events.Date,
                    }
                }
            };


            await _clubRepository.CreateClubAsync(club);

            var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var locationUri = baseUrl + "/api/club/" + club.Name;

            var response = new Club {
                Name = club.Name
            };

            return(Created(locationUri, response));
        }