public async Task <TravelPlanDto> CreateAsync(TravelPlanDto travelPlanDto, Guid userId)
        {
            try
            {
                //map here

                var newTravelPlan = new Domain.Models.TravelPlan
                {
                    Name               = travelPlanDto.Name,
                    Description        = travelPlanDto.Description,
                    StartDate          = travelPlanDto.StartDate,
                    EndDate            = travelPlanDto.EndDate,
                    CreatedById        = userId,
                    TravelPlanStatusId = (int)TravelPlanStatusEnum.Created,
                    //add jxn, auto adds to UTP table
                    UserTravelPlans = new List <UserTravelPlan>
                    {
                        new UserTravelPlan
                        {
                            UserId = userId
                        }
                    }
                };

                var tp = await _travelPlanRepository.CreateAsync(newTravelPlan);

                return(new TravelPlanDto(tp));
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #2
0
        public async Task <IActionResult> Create([FromBody] TravelPlanDto travelPlanDto)
        {
            try
            {
                var userId        = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value;
                var newTravelPlan = await _travelPlanRepository.CreateAsync(travelPlanDto, new Guid(userId));

                return(Ok(newTravelPlan));
            }
            catch (Exception exc)
            {
                return(BadRequest());
            }
        }