public async Task <IActionResult> Create([FromBody] TravelPlanActivityDto activityDto)
        {
            try
            {
                var userId      = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier).Value;
                var newActivity = await _activityRepository.CreateAsync(activityDto, new Guid(userId));

                return(Ok(newActivity));
            }
            catch (Exception exc)
            {
                return(BadRequest());
            }
        }
Example #2
0
        public async Task <TravelPlanActivityDto> CreateAsync(TravelPlanActivityDto activityDto, Guid userId)
        {
            try
            {
                var travelPlan = await _travelPlanService.GetAsync(activityDto.TravelPlanId);

                if (travelPlan == null)
                {
                    throw new Exception("Travel Plan Not Found");
                }

                //map here
                var newActivity = new TravelPlanActivity
                {
                    Name      = activityDto.Name,
                    StartTime = activityDto.StartTime,
                    EndTime   = activityDto.EndTime,
                    Category  = activityDto.Category,
                    Location  = new Location
                    {
                        Address   = activityDto.Location.Address,
                        Latitude  = activityDto.Location.Latitude,
                        Longitude = activityDto.Location.Longitude,
                    },
                    HostId       = userId,
                    TravelPlanId = activityDto.TravelPlanId
                };

                var addedActivity = await _travelPlanActivityRepository.CreateAsync(newActivity);

                return(new TravelPlanActivityDto(addedActivity));
            }
            catch (Exception)
            {
                throw;
            }
        }