public TravelPlanActivityDto(TravelPlanActivity travelPlanActivity)
 {
     this.Id           = travelPlanActivity.TravelPlanActivityId;
     this.TravelPlanId = travelPlanActivity.TravelPlanId;
     this.HostId       = travelPlanActivity.HostId;
     this.Name         = travelPlanActivity.Name;
     this.StartTime    = DateTime.SpecifyKind(travelPlanActivity.StartTime, DateTimeKind.Utc);
     this.EndTime      = DateTime.SpecifyKind(travelPlanActivity.EndTime, DateTimeKind.Utc);
     this.Category     = travelPlanActivity.Category;
     this.Location     = new LocationDto(travelPlanActivity.Location);
 }
Example #2
0
        public async Task <bool> DeleteAsync(TravelPlanActivity activityToDelete)
        {
            try
            {
                _dbContext.TravelPlanActivities.Remove(activityToDelete);

                var isSuccessful = await _dbContext.SaveChangesAsync() > 0;

                return(isSuccessful);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public async Task <TravelPlanActivityDto> CreateAsync(TravelPlanActivityDto activityDto, Guid userId)
        {
            try
            {
                //check if TravelPlan exists
                var travelPlan = await _dbContext.TravelPlans.FindAsync(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
                };

                _dbContext.TravelPlanActivities.Add(newActivity);

                var isSuccessful = await _dbContext.SaveChangesAsync() > 0;

                if (isSuccessful)
                {
                    return(new TravelPlanActivityDto(newActivity));
                }
                throw new Exception("Error saving changes");
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #4
0
        public async Task <TravelPlanActivity> CreateAsync(TravelPlanActivity newActivity)
        {
            try
            {
                _dbContext.TravelPlanActivities.Add(newActivity);

                var isSuccessful = await _dbContext.SaveChangesAsync() > 0;

                if (isSuccessful)
                {
                    return(newActivity);
                }
                throw new Exception("Error saving changes");
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #5
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;
            }
        }